Skip to content

Commit 7028fb9

Browse files
author
Doug Simon
committed
8317975: [JVMCI] assert(pointee != nullptr) failed: invariant
Reviewed-by: never, thartmann
1 parent 36993ae commit 7028fb9

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,16 @@ C2V_VMENTRY_0(jint, arrayIndexScale, (JNIEnv* env, jobject, jchar type_char))
24362436
return type2aelembytes(type);
24372437
C2V_END
24382438

2439+
C2V_VMENTRY(void, clearOopHandle, (JNIEnv* env, jobject, jlong oop_handle))
2440+
if (oop_handle == 0L) {
2441+
JVMCI_THROW(NullPointerException);
2442+
}
2443+
// Assert before nulling out, for better debugging.
2444+
assert(JVMCIRuntime::is_oop_handle(oop_handle), "precondition");
2445+
oop* oop_ptr = (oop*) oop_handle;
2446+
NativeAccess<>::oop_store(oop_ptr, (oop) nullptr);
2447+
C2V_END
2448+
24392449
C2V_VMENTRY(void, releaseClearedOopHandles, (JNIEnv* env, jobject))
24402450
JVMCIENV->runtime()->release_cleared_oop_handles();
24412451
C2V_END
@@ -3260,6 +3270,7 @@ JNINativeMethod CompilerToVM::methods[] = {
32603270
{CC "readArrayElement", CC "(" OBJECTCONSTANT "I)Ljava/lang/Object;", FN_PTR(readArrayElement)},
32613271
{CC "arrayBaseOffset", CC "(C)I", FN_PTR(arrayBaseOffset)},
32623272
{CC "arrayIndexScale", CC "(C)I", FN_PTR(arrayIndexScale)},
3273+
{CC "clearOopHandle", CC "(J)V", FN_PTR(clearOopHandle)},
32633274
{CC "releaseClearedOopHandles", CC "()V", FN_PTR(releaseClearedOopHandles)},
32643275
{CC "registerNativeMethods", CC "(" CLASS ")[J", FN_PTR(registerNativeMethods)},
32653276
{CC "isCurrentThreadAttached", CC "()Z", FN_PTR(isCurrentThreadAttached)},

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,13 @@ jlong JVMCIRuntime::make_oop_handle(const Handle& obj) {
887887
return reinterpret_cast<jlong>(ptr);
888888
}
889889

890+
#ifdef ASSERT
891+
bool JVMCIRuntime::is_oop_handle(jlong handle) {
892+
const oop* ptr = (oop*) handle;
893+
return object_handles()->allocation_status(ptr) == OopStorage::ALLOCATED_ENTRY;
894+
}
895+
#endif
896+
890897
int JVMCIRuntime::release_and_clear_oop_handles() {
891898
guarantee(_num_attached_threads == cannot_be_attached, "only call during JVMCI runtime shutdown");
892899
int released = release_cleared_oop_handles();

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,12 @@ class JVMCIRuntime: public CHeapObj<mtJVMCI> {
317317
// used when creating an IndirectHotSpotObjectConstantImpl in the
318318
// shared library JavaVM.
319319
jlong make_oop_handle(const Handle& obj);
320+
#ifdef ASSERT
321+
static bool is_oop_handle(jlong handle);
322+
#endif
320323

321324
// Releases all the non-null entries in _oop_handles whose referent is null.
322325
// Returns the number of handles released by this call.
323-
// The method also resets _last_found_oop_handle_index to -1
324-
// and _null_oop_handles to 0.
325326
int release_cleared_oop_handles();
326327

327328
// Allocation and management of metadata handles.

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,11 @@ boolean isTrustedForIntrinsics(HotSpotResolvedObjectTypeImpl klass) {
13001300

13011301
native boolean isTrustedForIntrinsics(HotSpotResolvedObjectTypeImpl klass, long klassPointer);
13021302

1303+
/**
1304+
* Clears the oop handle in {@code handle}.
1305+
*/
1306+
native void clearOopHandle(long handle);
1307+
13031308
/**
13041309
* Releases all oop handles whose referent is null.
13051310
*/

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ void clear(Object scopeDescription) {
155155

156156
/**
157157
* Sets the referent of {@code handle} to 0 so that it will be reclaimed when calling
158-
* {@link CompilerToVM#releaseClearedOopHandles}.
158+
* {@link CompilerToVM#releaseClearedOopHandles}. This must be done with a VM call so
159+
* that the JNI handle is cleared at a safepoint.
159160
*/
160161
static void clearHandle(long handle) {
161-
UNSAFE.putLong(handle, 0);
162+
runtime().compilerToVm.clearOopHandle(handle);
162163
}
163164

164165
@Override

0 commit comments

Comments
 (0)