64
64
#include " services/attachListener.hpp"
65
65
#include " services/mallocTracker.hpp"
66
66
#include " services/mallocHeader.inline.hpp"
67
- #include " services/memTracker.hpp"
67
+ #include " services/memTracker.inline. hpp"
68
68
#include " services/nmtPreInit.hpp"
69
69
#include " services/nmtCommon.hpp"
70
70
#include " services/threadService.hpp"
@@ -87,8 +87,6 @@ int os::_processor_count = 0;
87
87
int os::_initial_active_processor_count = 0 ;
88
88
os::PageSizes os::_page_sizes;
89
89
90
- static size_t cur_malloc_words = 0 ; // current size for MallocMaxTestWords
91
-
92
90
DEBUG_ONLY (bool os::_mutex_init_done = false ;)
93
91
94
92
int os::snprintf(char * buf, size_t len, const char * fmt, ...) {
@@ -607,23 +605,6 @@ char* os::strdup_check_oom(const char* str, MEMFLAGS flags) {
607
605
return p;
608
606
}
609
607
610
- //
611
- // This function supports testing of the malloc out of memory
612
- // condition without really running the system out of memory.
613
- //
614
-
615
- static bool has_reached_max_malloc_test_peak (size_t alloc_size) {
616
- if (MallocMaxTestWords > 0 ) {
617
- size_t words = (alloc_size / BytesPerWord);
618
-
619
- if ((cur_malloc_words + words) > MallocMaxTestWords) {
620
- return true ;
621
- }
622
- Atomic::add (&cur_malloc_words, words);
623
- }
624
- return false ;
625
- }
626
-
627
608
#ifdef ASSERT
628
609
static void check_crash_protection () {
629
610
assert (!ThreadCrashProtection::is_crash_protected (Thread::current_or_null ()),
@@ -658,8 +639,8 @@ void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
658
639
// we chose the latter.
659
640
size = MAX2 ((size_t )1 , size);
660
641
661
- // For the test flag -XX:MallocMaxTestWords
662
- if (has_reached_max_malloc_test_peak (size)) {
642
+ // Observe MallocLimit
643
+ if (MemTracker::check_exceeds_limit (size, memflags )) {
663
644
return nullptr ;
664
645
}
665
646
@@ -710,11 +691,6 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
710
691
// we chose the latter.
711
692
size = MAX2 ((size_t )1 , size);
712
693
713
- // For the test flag -XX:MallocMaxTestWords
714
- if (has_reached_max_malloc_test_peak (size)) {
715
- return nullptr ;
716
- }
717
-
718
694
if (MemTracker::enabled ()) {
719
695
// NMT realloc handling
720
696
@@ -725,12 +701,20 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
725
701
return nullptr ;
726
702
}
727
703
704
+ const size_t old_size = MallocTracker::malloc_header (memblock)->size ();
705
+
706
+ // Observe MallocLimit
707
+ if ((size > old_size) && MemTracker::check_exceeds_limit (size - old_size, memflags)) {
708
+ return nullptr ;
709
+ }
710
+
728
711
// Perform integrity checks on and mark the old block as dead *before* calling the real realloc(3) since it
729
712
// may invalidate the old block, including its header.
730
713
MallocHeader* header = MallocHeader::resolve_checked (memblock);
731
714
assert (memflags == header->flags (), " weird NMT flags mismatch (new:\" %s\" != old:\" %s\" )\n " ,
732
715
NMTUtil::flag_to_name (memflags), NMTUtil::flag_to_name (header->flags ()));
733
716
const MallocHeader::FreeInfo free_info = header->free_info ();
717
+
734
718
header->mark_block_as_dead ();
735
719
736
720
// the real realloc
@@ -750,7 +734,7 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
750
734
void * const new_inner_ptr = MemTracker::record_malloc (new_outer_ptr, size, memflags, stack);
751
735
752
736
#ifdef ASSERT
753
- size_t old_size = free_info.size ;
737
+ assert ( old_size == free_info.size , " Sanity " ) ;
754
738
if (old_size < size) {
755
739
// We also zap the newly extended region.
756
740
::memset ((char *)new_inner_ptr + old_size, uninitBlockPad, size - old_size);
0 commit comments