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]
  • Loading branch information
zapster committed Aug 22, 2023
1 parent e7b40b1 commit 0f2c3c1
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 org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.hosted.RuntimeReflection;

import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
Expand Down Expand Up @@ -100,7 +102,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 @@ -121,9 +123,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 (JavaVersionUtil.JAVA_SPEC >= 22) {
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);
}

var accessImpl = (DuringSetupAccessImpl) access;
substitutionProcessor = new MethodHandleInvokerRenamingSubstitutionProcessor(accessImpl.getBigBang());
Expand Down Expand Up @@ -315,7 +330,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 0f2c3c1

Please sign in to comment.