Skip to content

Commit

Permalink
8317975: [JVMCI] assert(pointee != nullptr) failed: invariant
Browse files Browse the repository at this point in the history
Reviewed-by: never, thartmann
  • Loading branch information
Doug Simon committed Oct 16, 2023
1 parent 36993ae commit 7028fb9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,16 @@ C2V_VMENTRY_0(jint, arrayIndexScale, (JNIEnv* env, jobject, jchar type_char))
return type2aelembytes(type);
C2V_END

C2V_VMENTRY(void, clearOopHandle, (JNIEnv* env, jobject, jlong oop_handle))
if (oop_handle == 0L) {
JVMCI_THROW(NullPointerException);
}
// Assert before nulling out, for better debugging.
assert(JVMCIRuntime::is_oop_handle(oop_handle), "precondition");
oop* oop_ptr = (oop*) oop_handle;
NativeAccess<>::oop_store(oop_ptr, (oop) nullptr);
C2V_END

C2V_VMENTRY(void, releaseClearedOopHandles, (JNIEnv* env, jobject))
JVMCIENV->runtime()->release_cleared_oop_handles();
C2V_END
Expand Down Expand Up @@ -3260,6 +3270,7 @@ JNINativeMethod CompilerToVM::methods[] = {
{CC "readArrayElement", CC "(" OBJECTCONSTANT "I)Ljava/lang/Object;", FN_PTR(readArrayElement)},
{CC "arrayBaseOffset", CC "(C)I", FN_PTR(arrayBaseOffset)},
{CC "arrayIndexScale", CC "(C)I", FN_PTR(arrayIndexScale)},
{CC "clearOopHandle", CC "(J)V", FN_PTR(clearOopHandle)},
{CC "releaseClearedOopHandles", CC "()V", FN_PTR(releaseClearedOopHandles)},
{CC "registerNativeMethods", CC "(" CLASS ")[J", FN_PTR(registerNativeMethods)},
{CC "isCurrentThreadAttached", CC "()Z", FN_PTR(isCurrentThreadAttached)},
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/jvmci/jvmciRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,13 @@ jlong JVMCIRuntime::make_oop_handle(const Handle& obj) {
return reinterpret_cast<jlong>(ptr);
}

#ifdef ASSERT
bool JVMCIRuntime::is_oop_handle(jlong handle) {
const oop* ptr = (oop*) handle;
return object_handles()->allocation_status(ptr) == OopStorage::ALLOCATED_ENTRY;
}
#endif

int JVMCIRuntime::release_and_clear_oop_handles() {
guarantee(_num_attached_threads == cannot_be_attached, "only call during JVMCI runtime shutdown");
int released = release_cleared_oop_handles();
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/jvmci/jvmciRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ class JVMCIRuntime: public CHeapObj<mtJVMCI> {
// used when creating an IndirectHotSpotObjectConstantImpl in the
// shared library JavaVM.
jlong make_oop_handle(const Handle& obj);
#ifdef ASSERT
static bool is_oop_handle(jlong handle);
#endif

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

// Allocation and management of metadata handles.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,11 @@ boolean isTrustedForIntrinsics(HotSpotResolvedObjectTypeImpl klass) {

native boolean isTrustedForIntrinsics(HotSpotResolvedObjectTypeImpl klass, long klassPointer);

/**
* Clears the oop handle in {@code handle}.
*/
native void clearOopHandle(long handle);

/**
* Releases all oop handles whose referent is null.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ void clear(Object scopeDescription) {

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

@Override
Expand Down

1 comment on commit 7028fb9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.