diff --git a/src/hotspot/share/gc/parallel/mutableSpace.cpp b/src/hotspot/share/gc/parallel/mutableSpace.cpp index a8f47a387e3..6d30c5a8d1f 100644 --- a/src/hotspot/share/gc/parallel/mutableSpace.cpp +++ b/src/hotspot/share/gc/parallel/mutableSpace.cpp @@ -182,12 +182,11 @@ bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) { // Only used by oldgen allocation. bool MutableSpace::needs_expand(size_t word_size) const { -#ifdef ASSERT - // If called by VM thread, locking is not needed. - if (!Thread::current()->is_VM_thread()) { - assert_lock_strong(PSOldGenExpand_lock); - } -#endif + // This method can be invoked either outside of safepoint by java threads or + // in safepoint by gc workers. Such accesses are synchronized by holding one + // of the following locks. + assert(Heap_lock->is_locked() || PSOldGenExpand_lock->is_locked(), "precondition"); + // Holding the lock means end is stable. So while top may be advancing // via concurrent allocations, there is no need to order the reads of top // and end here, unlike in cas_allocate. diff --git a/src/hotspot/share/gc/parallel/psOldGen.cpp b/src/hotspot/share/gc/parallel/psOldGen.cpp index 2d4b0698ad0..4e614c53447 100644 --- a/src/hotspot/share/gc/parallel/psOldGen.cpp +++ b/src/hotspot/share/gc/parallel/psOldGen.cpp @@ -118,8 +118,8 @@ void PSOldGen::initialize_performance_counters() { } HeapWord* PSOldGen::expand_and_allocate(size_t word_size) { - assert(SafepointSynchronize::is_at_safepoint(), "precondition"); - assert(Thread::current()->is_VM_thread(), "precondition"); + assert(Heap_lock->is_locked(), "precondition"); + if (object_space()->needs_expand(word_size)) { expand(word_size*HeapWordSize); }