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