647
648 // for debugging with UseMallocOnly
649 void* Arena::internal_malloc_4(size_t x) {
650 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
651 check_for_overflow(x, "Arena::internal_malloc_4");
652 if (_hwm + x > _max) {
653 return grow(x);
654 } else {
655 char *old = _hwm;
656 _hwm += x;
657 return old;
658 }
659 }
660 #endif
661
662
663 //--------------------------------------------------------------------------------------
664 // Non-product code
665
666 #ifndef PRODUCT
667 // The global operator new should never be called since it will usually indicate
668 // a memory leak. Use CHeapObj as the base class of such objects to make it explicit
669 // that they're allocated on the C heap.
670 // Commented out in product version to avoid conflicts with third-party C++ native code.
671 //
672 // In C++98/03 the throwing new operators are defined with the following signature:
673 //
674 // void* operator new(std::size_tsize) throw(std::bad_alloc);
675 // void* operator new[](std::size_tsize) throw(std::bad_alloc);
676 //
677 // while all the other (non-throwing) new and delete operators are defined with an empty
678 // throw clause (i.e. "operator delete(void* p) throw()") which means that they do not
679 // throw any exceptions (see section 18.4 of the C++ standard).
680 //
681 // In the new C++11/14 standard, the signature of the throwing new operators was changed
682 // by completely omitting the throw clause (which effectively means they could throw any
683 // exception) while all the other new/delete operators where changed to have a 'nothrow'
684 // clause instead of an empty throw clause.
685 //
686 // Unfortunately, the support for exception specifications among C++ compilers is still
687 // very fragile. While some more strict compilers like AIX xlC or HP aCC reject to
688 // override the default throwing new operator with a user operator with an empty throw()
689 // clause, the MS Visual C++ compiler warns for every non-empty throw clause like
690 // throw(std::bad_alloc) that it will ignore the exception specification. The following
691 // operator definitions have been checked to correctly work with all currently supported
692 // compilers and they should be upwards compatible with C++11/14. Therefore
693 // PLEASE BE CAREFUL if you change the signature of the following operators!
694
695 static void * zero = (void *) 0;
696
697 void* operator new(size_t size) /* throw(std::bad_alloc) */ {
698 fatal("Should not call global operator new");
699 return zero;
700 }
701
702 void* operator new [](size_t size) /* throw(std::bad_alloc) */ {
703 fatal("Should not call global operator new[]");
704 return zero;
705 }
706
707 void* operator new(size_t size, const std::nothrow_t& nothrow_constant) throw() {
708 fatal("Should not call global operator new");
709 return 0;
710 }
711
712 void* operator new [](size_t size, std::nothrow_t& nothrow_constant) throw() {
713 fatal("Should not call global operator new[]");
714 return 0;
715 }
716
717 void operator delete(void* p) throw() {
718 fatal("Should not call global delete");
719 }
720
721 void operator delete [](void* p) throw() {
722 fatal("Should not call global delete []");
723 }
724
725 void AllocatedObj::print() const { print_on(tty); }
726 void AllocatedObj::print_value() const { print_value_on(tty); }
727
728 void AllocatedObj::print_on(outputStream* st) const {
729 st->print_cr("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
730 }
731
732 void AllocatedObj::print_value_on(outputStream* st) const {
733 st->print("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
734 }
735
736 julong Arena::_bytes_allocated = 0;
737
738 void Arena::inc_bytes_allocated(size_t x) { inc_stat_counter(&_bytes_allocated, x); }
739
740 AllocStats::AllocStats() {
741 start_mallocs = os::num_mallocs;
742 start_frees = os::num_frees;
743 start_malloc_bytes = os::alloc_bytes;
744 start_mfree_bytes = os::free_bytes;
|
647
648 // for debugging with UseMallocOnly
649 void* Arena::internal_malloc_4(size_t x) {
650 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
651 check_for_overflow(x, "Arena::internal_malloc_4");
652 if (_hwm + x > _max) {
653 return grow(x);
654 } else {
655 char *old = _hwm;
656 _hwm += x;
657 return old;
658 }
659 }
660 #endif
661
662
663 //--------------------------------------------------------------------------------------
664 // Non-product code
665
666 #ifndef PRODUCT
667 void AllocatedObj::print() const { print_on(tty); }
668 void AllocatedObj::print_value() const { print_value_on(tty); }
669
670 void AllocatedObj::print_on(outputStream* st) const {
671 st->print_cr("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
672 }
673
674 void AllocatedObj::print_value_on(outputStream* st) const {
675 st->print("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
676 }
677
678 julong Arena::_bytes_allocated = 0;
679
680 void Arena::inc_bytes_allocated(size_t x) { inc_stat_counter(&_bytes_allocated, x); }
681
682 AllocStats::AllocStats() {
683 start_mallocs = os::num_mallocs;
684 start_frees = os::num_frees;
685 start_malloc_bytes = os::alloc_bytes;
686 start_mfree_bytes = os::free_bytes;
|