From 1148a659a89edc6a4f320d578bc0025eae3553fb Mon Sep 17 00:00:00 2001 From: Tomas Zezula Date: Mon, 13 Mar 2023 08:40:12 +0000 Subject: [PATCH] 8303678: [JVMCI] Add possibility to convert object JavaConstant to jobject. Reviewed-by: never --- .../vm/ci/hotspot/HotSpotJVMCIRuntime.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java index 1ec015a1415..8a2de8b7e57 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @@ -858,6 +858,26 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime { } } + /** + * Gets the {@code jobject} value wrapped by {@code peerObject}. The returned "naked" value is + * only valid as long as {@code peerObject} is valid. Note that the latter may be shorter than + * the lifetime of {@code peerObject}. As such, this method should only be used to pass an + * object parameter across a JNI call from the JVMCI shared library to HotSpot. This method must + * only be called from within the JVMCI shared library. + * + * @param peerObject a reference to an object in the peer runtime + * @return the {@code jobject} value wrapped by {@code peerObject} + * @throws IllegalArgumentException if the current runtime is not the JVMCI shared library or + * {@code peerObject} is not a peer object reference + */ + public long getJObjectValue(HotSpotObjectConstant peerObject) { + if (peerObject instanceof IndirectHotSpotObjectConstantImpl) { + IndirectHotSpotObjectConstantImpl remote = (IndirectHotSpotObjectConstantImpl) peerObject; + return remote.getHandle(); + } + throw new IllegalArgumentException("Cannot get jobject value for " + peerObject + " (" + peerObject.getClass().getName() + ")"); + } + @Override public JVMCIBackend getHostJVMCIBackend() { return hostBackend;