jniHandles.hpp revision 1472
/*
* 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.
*
*/
class JNIHandleBlock;
class JNIHandles : AllStatic {
friend class VMStructs;
private:
public:
// Resolve handle into oop
// Resolve externally provided handle into oop with some guards
// Resolve handle into oop, result guaranteed not to be null
// Local handles
static jobject make_local(Thread* thread, oop obj); // Even faster version when current thread is known
// Global handles
// Weak global handles
// jmethodID handling (as Weak global handles).
// Because the useful life-span of a jmethodID cannot be determined, once created they are
// never reclaimed. The methods to which they refer, however, can be GC'ed away if the class
// is unloaded or if the method is made obsolete or deleted -- in these cases, the jmethodID
// refers to NULL (as is the case for any weak reference).
// Use resolve_jmethod_id() in situations where the caller is expected
// to provide a valid jmethodID; the only sanity checks are in asserts;
// result guaranteed not to be NULL.
// Use checked_resolve_jmethod_id() in situations where the caller
// should provide a valid jmethodID, but might not. NULL is returned
// when the jmethodID does not refer to a valid method.
// Sentinel marking deleted handles in block. Note that we cannot store NULL as
// the sentinel, since clearing weak global JNI refs are done by storing NULL in
// the handle. The handle may not be reused before destroy_weak_global is called.
// Initialization
static void initialize();
// Debugging
static void verify();
static long global_handle_memory_usage();
static long weak_global_handle_memory_usage();
// Garbage collection support(global handles only, local handles are traversed from thread)
// Traversal of regular global handles
static void oops_do(OopClosure* f);
// Traversal of weak global handles. Unreachable oops are cleared.
};
class JNIHandleBlock : public CHeapObj {
friend class VMStructs;
friend class CppInterpreter;
private:
enum SomeConstants {
};
int _top; // Index of next unused handle
// The following instance variables are only used by the first block in a chain.
// Having two types of blocks complicates the code and the space overhead in negligble.
int _allocate_before_rebuild; // Number of blocks to allocate before rebuilding free list
#ifndef PRODUCT
#endif
static int _blocks_allocated; // For debugging/printing
// Fill block with bad_handle values
void zap();
protected:
// No more handles in the both the current and following blocks
private:
// Free list computation
void rebuild_free_list();
public:
// Handle allocation
// Block allocation and block free list management
// JNI PushLocalFrame/PopLocalFrame support
// Stub generator support
// Garbage collection support
// Traversal of regular handles
void oops_do(OopClosure* f);
// Traversal of weak handles. Unreachable oops are cleared.
// Debugging
int length() const; // Length of chain starting with this block
long memory_usage() const;
#ifndef PRODUCT
static void print_statistics();
#endif
};
assert(result != NULL || (handle == NULL || !CheckJNICalls || is_weak_global_handle(handle)), "Invalid value read from jni handle");
return result;
};
return result;
};
// Don't let that private _deleted_handle object escape into the wild.
return result;
};
};
}
return (methodOop) o;
};
}
}