--- old/src/hotspot/share/memory/resourceArea.cpp 2020-08-21 11:45:57.592517976 -0400 +++ new/src/hotspot/share/memory/resourceArea.cpp 2020-08-21 11:45:57.108501389 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ #include "precompiled.hpp" #include "memory/allocation.inline.hpp" #include "memory/resourceArea.inline.hpp" -#include "runtime/mutexLocker.hpp" +#include "runtime/atomic.hpp" #include "runtime/thread.inline.hpp" #include "services/memTracker.hpp" @@ -40,9 +40,25 @@ } } -//------------------------------ResourceMark----------------------------------- -debug_only(int ResourceArea::_warned;) // to suppress multiple warnings +#ifdef ASSERT + +void ResourceArea::verify_has_resource_mark() { + if (_nesting <= 0) { + // Only report the first occurrence of an allocating thread that + // is missing a ResourceMark, to avoid possible recursive errors + // in error handling. + static volatile bool reported = false; + if (!Atomic::load(&reported)) { + if (!Atomic::cmpxchg(&reported, false, true)) { + fatal("memory leak: allocating without ResourceMark"); + } + } + } +} +#endif // ASSERT + +//------------------------------ResourceMark----------------------------------- // The following routines are declared in allocation.hpp and used everywhere: // Allocation in thread-local resource area @@ -60,30 +76,3 @@ extern void resource_free_bytes( char *old, size_t size ) { Thread::current()->resource_area()->Afree(old, size); } - -#ifdef ASSERT -ResourceMark::ResourceMark(Thread *thread) { - assert(thread == Thread::current(), "not the current thread"); - initialize(thread); -} - -DeoptResourceMark::DeoptResourceMark(Thread *thread) { - assert(thread == Thread::current(), "not the current thread"); - initialize(thread); -} -#endif - - -//------------------------------------------------------------------------------- -// Non-product code -#ifndef PRODUCT - -void ResourceMark::free_malloced_objects() { - Arena::free_malloced_objects(_chunk, _hwm, _max, _area->_hwm); -} - -void DeoptResourceMark::free_malloced_objects() { - Arena::free_malloced_objects(_chunk, _hwm, _max, _area->_hwm); -} - -#endif