8200429: Adjust object pinning interface on CollectedHeap
Reviewed-by: dholmes, rkennke
This commit is contained in:
parent
29bb7c8a05
commit
15263a27f8
@ -621,12 +621,15 @@ void CollectedHeap::reset_promotion_should_fail() {
|
||||
|
||||
#endif // #ifndef PRODUCT
|
||||
|
||||
oop CollectedHeap::pin_object(JavaThread* thread, oop o) {
|
||||
Handle handle(thread, o);
|
||||
GCLocker::lock_critical(thread);
|
||||
return handle();
|
||||
bool CollectedHeap::supports_object_pinning() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void CollectedHeap::unpin_object(JavaThread* thread, oop o) {
|
||||
GCLocker::unlock_critical(thread);
|
||||
oop CollectedHeap::pin_object(JavaThread* thread, oop obj) {
|
||||
ShouldNotReachHere();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CollectedHeap::unpin_object(JavaThread* thread, oop obj) {
|
||||
ShouldNotReachHere();
|
||||
}
|
||||
|
@ -589,14 +589,12 @@ class CollectedHeap : public CHeapObj<mtInternal> {
|
||||
// perform cleanup tasks serially in the VMThread.
|
||||
virtual WorkGang* get_safepoint_workers() { return NULL; }
|
||||
|
||||
// Support for object pinning. This is used by JNI's Get*Critical() and
|
||||
// Release*Critical() family of functions. A GC may either use the GCLocker
|
||||
// protocol to ensure no critical arrays are in-use when entering
|
||||
// a GC pause, or it can implement pinning, which must guarantee that
|
||||
// the object does not move while pinned.
|
||||
virtual oop pin_object(JavaThread* thread, oop o);
|
||||
|
||||
virtual void unpin_object(JavaThread* thread, oop o);
|
||||
// Support for object pinning. This is used by JNI Get*Critical()
|
||||
// and Release*Critical() family of functions. If supported, the GC
|
||||
// must guarantee that pinned objects never move.
|
||||
virtual bool supports_object_pinning() const;
|
||||
virtual oop pin_object(JavaThread* thread, oop obj);
|
||||
virtual void unpin_object(JavaThread* thread, oop obj);
|
||||
|
||||
// Non product verification and debugging.
|
||||
#ifndef PRODUCT
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "classfile/symbolTable.hpp"
|
||||
#include "classfile/systemDictionary.hpp"
|
||||
#include "classfile/vmSymbols.hpp"
|
||||
#include "gc/shared/gcLocker.inline.hpp"
|
||||
#include "interpreter/linkResolver.hpp"
|
||||
#include "memory/allocation.hpp"
|
||||
#include "memory/allocation.inline.hpp"
|
||||
@ -3145,6 +3146,24 @@ JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start,
|
||||
}
|
||||
JNI_END
|
||||
|
||||
static oop lock_gc_or_pin_object(JavaThread* thread, jobject obj) {
|
||||
if (Universe::heap()->supports_object_pinning()) {
|
||||
const oop o = JNIHandles::resolve_non_null(obj);
|
||||
return Universe::heap()->pin_object(thread, o);
|
||||
} else {
|
||||
GCLocker::lock_critical(thread);
|
||||
return JNIHandles::resolve_non_null(obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void unlock_gc_or_unpin_object(JavaThread* thread, jobject obj) {
|
||||
if (Universe::heap()->supports_object_pinning()) {
|
||||
const oop o = JNIHandles::resolve_non_null(obj);
|
||||
return Universe::heap()->unpin_object(thread, o);
|
||||
} else {
|
||||
GCLocker::unlock_critical(thread);
|
||||
}
|
||||
}
|
||||
|
||||
JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy))
|
||||
JNIWrapper("GetPrimitiveArrayCritical");
|
||||
@ -3152,8 +3171,7 @@ JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboole
|
||||
if (isCopy != NULL) {
|
||||
*isCopy = JNI_FALSE;
|
||||
}
|
||||
oop a = JNIHandles::resolve_non_null(array);
|
||||
a = Universe::heap()->pin_object(thread, a);
|
||||
oop a = lock_gc_or_pin_object(thread, array);
|
||||
assert(a->is_array(), "just checking");
|
||||
BasicType type;
|
||||
if (a->is_objArray()) {
|
||||
@ -3170,8 +3188,7 @@ JNI_END
|
||||
JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode))
|
||||
JNIWrapper("ReleasePrimitiveArrayCritical");
|
||||
HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(env, array, carray, mode);
|
||||
oop a = JNIHandles::resolve_non_null(array);
|
||||
Universe::heap()->unpin_object(thread, a);
|
||||
unlock_gc_or_unpin_object(thread, array);
|
||||
HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN();
|
||||
JNI_END
|
||||
|
||||
@ -3179,8 +3196,7 @@ JNI_END
|
||||
JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy))
|
||||
JNIWrapper("GetStringCritical");
|
||||
HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(env, string, (uintptr_t *) isCopy);
|
||||
oop s = JNIHandles::resolve_non_null(string);
|
||||
s = Universe::heap()->pin_object(thread, s);
|
||||
oop s = lock_gc_or_pin_object(thread, string);
|
||||
typeArrayOop s_value = java_lang_String::value(s);
|
||||
bool is_latin1 = java_lang_String::is_latin1(s);
|
||||
if (isCopy != NULL) {
|
||||
@ -3217,7 +3233,7 @@ JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar
|
||||
// This assumes that ReleaseStringCritical bookends GetStringCritical.
|
||||
FREE_C_HEAP_ARRAY(jchar, chars);
|
||||
}
|
||||
Universe::heap()->unpin_object(thread, s);
|
||||
unlock_gc_or_unpin_object(thread, str);
|
||||
HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN();
|
||||
JNI_END
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user