2273N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// In order to preserve oops during garbage collection, they should be 0N/A// allocated and passed around via Handles within the VM. A handle is 0N/A// simply an extra indirection allocated in a thread local handle area. 0N/A// A handle is a ValueObj, so it can be passed around as a value, can 0N/A// be used as a parameter w/o using &-passing, and can be returned as a 0N/A// oop parameters and return types should be Handles whenever feasible. 0N/A// Handles are declared in a straight-forward manner, e.g. 0N/A// Handle h1(obj); // allocate new handle 0N/A// Handle h2(thread, obj); // faster allocation when current thread is known 0N/A// Handle h3; // declare handle only, no allocation occurs 0N/A// h3 = h1; // make h3 refer to same indirection as h1 0N/A// oop obj2 = h2(); // get handle value 0N/A// h1->print(); // invoking operation on oop 0N/A// Handles are specialized for different oop types to provide extra type 0N/A// information and avoid unnecessary casting. For each oop type xxxOop 0N/A// there is a corresponding handle called xxxHandle, e.g. 0N/A// methodOop methodHandle 0N/A// instanceOop instanceHandle 0N/A// For klassOops, it is often useful to model the Klass hierarchy in order 0N/A// to get access to the klass_part without casting. For each xxxKlass there 0N/A// is a corresponding handle called xxxKlassHandle, e.g. 0N/A// klassOop Klass KlassHandle 0N/A// klassOop methodKlass methodKlassHandle 0N/A// klassOop instanceKlass instanceKlassHandle 0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// Base class for all handles. Provides overloading of frequently 0N/A// used operators for ease of use. 0N/A // Don't inline body with assert for current thread 0N/A bool operator == (
oop o)
const {
return obj() == o; }
0N/A // Direct interface, use very sparingly. 0N/A // Used by JavaCalls to quickly convert handles and to create handles static data structures. 0N/A // Constructor takes a dummy argument to prevent unintentional type conversion in C++. 0N/A // Raw handle access. Allows easy duplication of Handles. This can be very unsafe 0N/A // since duplicates is only valid as long as original handle is alive. 0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// Base class for Handles containing klassOops. Provides overloading of frequently 0N/A// used operators for ease of use and typed access to the Klass part. 0N/A // Faster versions passing Thread 665N/A // Direct interface, use very sparingly. 665N/A // Used by SystemDictionaryHandles to create handles on existing WKKs. 665N/A // The obj of such a klass handle may be null, because the handle is formed 665N/A // during system bootstrapping. 0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// Specific Handles for different oop types 0N/A /* Constructors */ \
0N/A /* Special constructor, use sparingly */ \
0N/A /* Operators for ease of use */ \
0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// Specific KlassHandles for different Klass types 0N/A /* Constructors */ \
0N/A /* Access to klass part */ \
0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// Thread local handle area 0N/A // Handle allocation 0N/A // Garbage collection support 0N/A // Number of handles in use 0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// Handles are allocated in a (growable) thread local handle area. Deallocation 0N/A// is managed using a HandleMark. It should normally not be necessary to use 0N/A// HandleMarks manually. 0N/A// A HandleMark constructor will record the current handle area top, and the 0N/A// desctructor will reset the top, destroying all handles allocated in between. 0N/A// The following code will therefore NOT work: 0N/A// h()->print(); // WRONG, h destroyed by HandleMark destructor. 0N/A// If h has to be preserved, it can be converted to an oop or a local JNI handle 0N/A// across the HandleMark boundary. 0N/A// The base class of HandleMark should have been StackObj but we also heap allocate 0N/A// a HandleMark when a thread is created. 0N/A // Link to previous active HandleMark in thread 0N/A // Functions used by HandleMarkCleaner 0N/A // called in the constructor of HandleMarkCleaner 0N/A // called in the destructor of HandleMarkCleaner 0N/A//------------------------------------------------------------------------------------------------------------------------ 0N/A// A NoHandleMark stack object will verify that no handles are allocated 0N/A// in its scope. Enabled in debug mode only. 1879N/A#
endif // SHARE_VM_RUNTIME_HANDLES_HPP