/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_MEMORY_RESOURCEAREA_HPP
#define SHARE_VM_MEMORY_RESOURCEAREA_HPP
#include "memory/allocation.hpp"
#ifdef TARGET_OS_FAMILY_linux
# include "thread_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "thread_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "thread_windows.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "thread_bsd.inline.hpp"
#endif
// The resource area holds temporary data structures in the VM.
// The actual allocation areas are thread local. Typical usage:
//
// ...
// {
// ResourceMark rm;
// int foo[] = NEW_RESOURCE_ARRAY(int, 64);
// ...
// }
// ...
//------------------------------ResourceArea-----------------------------------
// A ResourceArea is an Arena that supports safe usage of ResourceMark.
friend class ResourceMark;
friend class DeoptResourceMark;
friend class VMStructs;
public:
ResourceArea() {
debug_only(_nesting = 0;)
}
debug_only(_nesting = 0;);
}
#ifdef ASSERT
fatal("memory leak: allocating without ResourceMark");
if (UseMallocOnly) {
// use malloc, but save pointer in res. area for later freeing
}
#endif
}
};
//------------------------------ResourceMark-----------------------------------
// A resource mark releases all resources allocated after it was constructed
// when the destructor is called. Typically used as a local variable.
protected:
}
public:
#ifndef ASSERT
}
#else
#endif // ASSERT
_size_in_bytes = r->_size_in_bytes;
}
void reset_to_mark() {
if (UseMallocOnly) free_malloced_objects();
// reset arena size before delete chunks. Otherwise, the total
// arena size could exceed total chunk size
} else {
}
// clear out this chunk (to detect allocation bugs)
}
~ResourceMark() {
}
private:
};
//------------------------------DeoptResourceMark-----------------------------------
// A deopt resource mark releases all resources allocated after it was constructed
// when the destructor is called. Typically used as a local variable. It differs
// from a typical resource more in that it is C-Heap allocated so that deoptimization
// can use data structures that are arena based but are not amenable to vanilla
// ResourceMarks because deoptimization can not use a stack allocated mark. During
// deoptimization we go thru the following steps:
//
// 0: start in assembly stub and call either uncommon_trap/fetch_unroll_info
// 1: create the vframeArray (contains pointers to Resource allocated structures)
// This allocates the DeoptResourceMark.
// 2: return to assembly stub and remove stub frame and deoptee frame and create
// the new skeletal frames.
// 3: push new stub frame and call unpack_frames
// 4: retrieve information from the vframeArray to populate the skeletal frames
// 5: release the DeoptResourceMark
// 6: return to stub and eventually to interpreter
//
// With old style eager deoptimization the vframeArray was created by the vmThread there
// was no way for the vframeArray to contain resource allocated objects and so
// a complex set of data structures to simulate an array of vframes in CHeap memory
// was used. With new style lazy deoptimization the vframeArray is created in the
// the thread that will use it and we can use a much simpler scheme for the vframeArray
// leveraging existing data structures if we simply create a way to manage this one
// special need for a ResourceMark. If ResourceMark simply inherited from CHeapObj
// then existing ResourceMarks would work fine since no one use new to allocate them
// and they would be stack allocated. This leaves open the possibilty of accidental
// misuse so we simple duplicate the ResourceMark functionality here.
protected:
}
public:
#ifndef ASSERT
}
#else
#endif // ASSERT
}
void reset_to_mark() {
if (UseMallocOnly) free_malloced_objects();
// reset arena size before delete chunks. Otherwise, the total
// arena size could exceed total chunk size
} else {
}
// clear out this chunk (to detect allocation bugs)
}
~DeoptResourceMark() {
}
private:
};
#endif // SHARE_VM_MEMORY_RESOURCEAREA_HPP