Skip to content

Commit

Permalink
svm: adapt "Move ReferencedKeyMap to jdk.internal so it may be shared…
Browse files Browse the repository at this point in the history
…" [JDK-8310913]

(cherry picked from commit 0f2c3c1)
  • Loading branch information
zapster authored and simonis committed May 29, 2024
1 parent ab3336b commit ef89857
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import java.util.Iterator;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import com.oracle.svm.core.jdk.JDK21u4OrLater;
import org.graalvm.nativeimage.hosted.RuntimeReflection;

import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
Expand Down Expand Up @@ -101,7 +103,7 @@ public class MethodHandleFeature implements InternalFeature {
* equivalent image heap object is not part of the table and subsequently fails a comparison.
*/
private Object runtimeMethodTypeInternTable;
private Method concurrentWeakInternSetAdd;
private Method referencedKeySetAdd;

private MethodHandleInvokerRenamingSubstitutionProcessor substitutionProcessor;

Expand All @@ -122,9 +124,22 @@ public void duringSetup(DuringSetupAccess access) {
Class<?> arrayAccessorClass = access.findClassByName("java.lang.invoke.MethodHandleImpl$ArrayAccessor");
typedAccessors = ReflectionUtil.lookupField(arrayAccessorClass, "TYPED_ACCESSORS");

Class<?> concurrentWeakInternSetClass = access.findClassByName("java.lang.invoke.MethodType$ConcurrentWeakInternSet");
runtimeMethodTypeInternTable = ReflectionUtil.newInstance(concurrentWeakInternSetClass);
concurrentWeakInternSetAdd = ReflectionUtil.lookupMethod(concurrentWeakInternSetClass, "add", Object.class);
if (JDK21u4OrLater.jdk21u4OrLater) {
try {
Class<?> referencedKeySetClass = access.findClassByName("jdk.internal.util.ReferencedKeySet");
Method create = ReflectionUtil.lookupMethod(referencedKeySetClass, "create", boolean.class, boolean.class, Supplier.class);
// The following call must match the static initializer of MethodType#internTable.
runtimeMethodTypeInternTable = create.invoke(null,
/* isSoft */ false, /* useNativeQueue */ true, (Supplier<Object>) () -> new ConcurrentHashMap<>(512));
referencedKeySetAdd = ReflectionUtil.lookupMethod(referencedKeySetClass, "add", Object.class);
} catch (ReflectiveOperationException e) {
throw VMError.shouldNotReachHere(e);
}
} else {
Class<?> concurrentWeakInternSetClass = access.findClassByName("java.lang.invoke.MethodType$ConcurrentWeakInternSet");
runtimeMethodTypeInternTable = ReflectionUtil.newInstance(concurrentWeakInternSetClass);
referencedKeySetAdd = ReflectionUtil.lookupMethod(concurrentWeakInternSetClass, "add", Object.class);
}

if (!SubstrateOptions.UseOldMethodHandleIntrinsics.getValue()) {
/*
Expand Down Expand Up @@ -322,7 +337,7 @@ private static void registerVarHandleMethodsForReflection(FeatureAccess access,

public void registerHeapMethodType(MethodType methodType) {
try {
concurrentWeakInternSetAdd.invoke(runtimeMethodTypeInternTable, methodType);
referencedKeySetAdd.invoke(runtimeMethodTypeInternTable, methodType);
} catch (ReflectiveOperationException e) {
throw VMError.shouldNotReachHere(e);
}
Expand Down

0 comments on commit ef89857

Please sign in to comment.