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
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;
|
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 #ifndef SHARK
668 // The global operator new should never be called since it will usually indicate
669 // a memory leak. Use CHeapObj as the base class of such objects to make it explicit
670 // that they're allocated on the C heap.
671 // Commented out in product version to avoid conflicts with third-party C++ native code.
672 //
673 // In C++98/03 the throwing new operators are defined with the following signature:
674 //
675 // void* operator new(std::size_tsize) throw(std::bad_alloc);
676 // void* operator new[](std::size_tsize) throw(std::bad_alloc);
677 //
678 // while all the other (non-throwing) new and delete operators are defined with an empty
679 // throw clause (i.e. "operator delete(void* p) throw()") which means that they do not
680 // throw any exceptions (see section 18.4 of the C++ standard).
681 //
682 // In the new C++11/14 standard, the signature of the throwing new operators was changed
683 // by completely omitting the throw clause (which effectively means they could throw any
684 // exception) while all the other new/delete operators where changed to have a 'nothrow'
685 // clause instead of an empty throw clause.
686 //
687 // Unfortunately, the support for exception specifications among C++ compilers is still
705 return zero;
706 }
707
708 void* operator new(size_t size, const std::nothrow_t& nothrow_constant) throw() {
709 fatal("Should not call global operator new");
710 return 0;
711 }
712
713 void* operator new [](size_t size, std::nothrow_t& nothrow_constant) throw() {
714 fatal("Should not call global operator new[]");
715 return 0;
716 }
717
718 void operator delete(void* p) throw() {
719 fatal("Should not call global delete");
720 }
721
722 void operator delete [](void* p) throw() {
723 fatal("Should not call global delete []");
724 }
725
726 #endif // SHARK
727
728 void AllocatedObj::print() const { print_on(tty); }
729 void AllocatedObj::print_value() const { print_value_on(tty); }
730
731 void AllocatedObj::print_on(outputStream* st) const {
732 st->print_cr("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
733 }
734
735 void AllocatedObj::print_value_on(outputStream* st) const {
736 st->print("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
737 }
738
739 julong Arena::_bytes_allocated = 0;
740
741 void Arena::inc_bytes_allocated(size_t x) { inc_stat_counter(&_bytes_allocated, x); }
742
743 AllocStats::AllocStats() {
744 start_mallocs = os::num_mallocs;
745 start_frees = os::num_frees;
746 start_malloc_bytes = os::alloc_bytes;
|