Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.

Commit 35915eb

Browse files
committed
[GR-44518] Add possibility to convert object JavaConstant to jobject.
1 parent ecffcb5 commit 35915eb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,26 @@ JavaType lookupTypeInternal(String name, HotSpotResolvedObjectType accessingType
858858
}
859859
}
860860

861+
/**
862+
* Gets the {@code jobject} value wrapped by {@code peerObject}. The returned "naked" value is
863+
* only valid as long as {@code peerObject} is valid. Note that the latter may be shorter than
864+
* the lifetime of {@code peerObject}. As such, this method should only be used to pass an
865+
* object parameter across a JNI call from the JVMCI shared library to HotSpot. This method must
866+
* only be called from within the JVMCI shared library.
867+
*
868+
* @param peerObject a reference to an object in the peer runtime
869+
* @return the {@code jobject} value wrapped by {@code peerObject}
870+
* @throws IllegalArgumentException if the current runtime is not the JVMCI shared library or
871+
* {@code peerObject} is not a peer object reference
872+
*/
873+
public long getJObjectValue(HotSpotObjectConstant peerObject) {
874+
if (peerObject instanceof IndirectHotSpotObjectConstantImpl) {
875+
IndirectHotSpotObjectConstantImpl remote = (IndirectHotSpotObjectConstantImpl) peerObject;
876+
return remote.getHandle();
877+
}
878+
throw new IllegalArgumentException("Cannot get jobject value for " + peerObject + " (" + peerObject.getClass().getName() + ")");
879+
}
880+
861881
@Override
862882
public JVMCIBackend getHostJVMCIBackend() {
863883
return hostBackend;

0 commit comments

Comments
 (0)