--- old/src/hotspot/share/memory/heap.cpp 2021-04-20 17:54:01.057755303 +0000 +++ new/src/hotspot/share/memory/heap.cpp 2021-04-20 17:54:00.901751414 +0000 @@ -204,6 +204,7 @@ assert(rs.size() >= committed_size, "reserved < committed"); assert(segment_size >= sizeof(FreeBlock), "segment size is too small"); assert(is_power_of_2(segment_size), "segment_size must be a power of 2"); + assert_locked_or_safepoint(CodeCache_lock); _segment_size = segment_size; _log2_segment_size = exact_log2(segment_size); @@ -252,6 +253,8 @@ bool CodeHeap::expand_by(size_t size) { + assert_locked_or_safepoint(CodeCache_lock); + // expand _memory space size_t dm = align_to_page_size(_memory.committed_size() + size) - _memory.committed_size(); if (dm > 0) { @@ -282,6 +285,7 @@ void* CodeHeap::allocate(size_t instance_size) { size_t number_of_segments = size_to_segments(instance_size + header_size()); assert(segments_to_size(number_of_segments) >= sizeof(FreeBlock), "not enough room for FreeList"); + assert_locked_or_safepoint(CodeCache_lock); // First check if we can satisfy request from freelist NOT_PRODUCT(verify()); @@ -346,6 +350,8 @@ void CodeHeap::deallocate_tail(void* p, size_t used_size) { assert(p == find_start(p), "illegal deallocation"); + assert_locked_or_safepoint(CodeCache_lock); + // Find start of HeapBlock HeapBlock* b = (((HeapBlock *)p) - 1); assert(b->allocated_space() == p, "sanity check"); @@ -362,6 +368,8 @@ void CodeHeap::deallocate(void* p) { assert(p == find_start(p), "illegal deallocation"); + assert_locked_or_safepoint(CodeCache_lock); + // Find start of HeapBlock HeapBlock* b = (((HeapBlock *)p) - 1); assert(b->allocated_space() == p, "sanity check"); @@ -789,6 +797,7 @@ void CodeHeap::verify() { if (VerifyCodeCache) { + assert_locked_or_safepoint(CodeCache_lock); size_t len = 0; int count = 0; for(FreeBlock* b = _freelist; b != NULL; b = b->link()) {