Skip to content

Commit

Permalink
fixup! Don't create JNINativeCallWrapperMethods for JNICallTrampoline…
Browse files Browse the repository at this point in the history
…Methods
  • Loading branch information
zakkak committed Dec 23, 2021
1 parent 5b56df0 commit 9005517
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,10 @@
import com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod;
import com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant;

import jdk.vm.ci.meta.ConstantPool;
import jdk.vm.ci.meta.MetaAccessProvider;

/**
* Holder class for generated {@link JNIJavaCallWrapperMethod} code.
*/
public final class JNIJavaCallTrampolines {
public static ConstantPool getConstantPool(MetaAccessProvider metaAccess) {
// Each generated call wrapper needs an actual constant pool, so we provide our
// private constructor's
return metaAccess.lookupJavaType(JNIJavaCallWrappers.class).getDeclaredConstructors()[0].getConstantPool();
}

private JNIJavaCallTrampolines() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ public void beforeAnalysis(BeforeAnalysisAccess arg) {
BeforeAnalysisAccessImpl access = (BeforeAnalysisAccessImpl) arg;
this.nativeLibraries = access.getNativeLibraries();

createJavaCallTrampoline(access, CallVariant.VARARGS, false);
createJavaCallTrampoline(access, CallVariant.ARRAY, false);
createJavaCallTrampoline(access, CallVariant.VA_LIST, false);
createJavaCallTrampoline(access, CallVariant.VARARGS, true);
createJavaCallTrampoline(access, CallVariant.ARRAY, true);
createJavaCallTrampoline(access, CallVariant.VA_LIST, true);
registerJavaCallTrampoline(access, CallVariant.VARARGS, false);
registerJavaCallTrampoline(access, CallVariant.ARRAY, false);
registerJavaCallTrampoline(access, CallVariant.VA_LIST, false);
registerJavaCallTrampoline(access, CallVariant.VARARGS, true);
registerJavaCallTrampoline(access, CallVariant.ARRAY, true);
registerJavaCallTrampoline(access, CallVariant.VA_LIST, true);

/* duplicated to reduce the number of analysis iterations */
getConditionalConfigurationRegistry().flushConditionalConfiguration(access);
Expand All @@ -184,7 +184,7 @@ private static ConditionalConfigurationRegistry getConditionalConfigurationRegis
return (ConditionalConfigurationRegistry) ImageSingletons.lookup(JNIRuntimeAccess.JNIRuntimeAccessibilitySupport.class);
}

private void createJavaCallTrampoline(BeforeAnalysisAccessImpl access, CallVariant variant, boolean nonVirtual) {
private static void registerJavaCallTrampoline(BeforeAnalysisAccessImpl access, CallVariant variant, boolean nonVirtual) {
AnalysisMetaAccess metaAccess = access.getMetaAccess();
ResolvedJavaField field = JNIAccessibleMethod.getCallWrapperField(metaAccess.getWrapped(), variant, nonVirtual);
access.getUniverse().lookup(field.getDeclaringClass()).registerAsReachable();
Expand All @@ -193,9 +193,8 @@ private void createJavaCallTrampoline(BeforeAnalysisAccessImpl access, CallVaria
Method reflectionMethod = ReflectionUtil.lookupMethod(JNIJavaCallTrampolines.class, trampolineName);
// Look up the java method to ensure a JNICallTrampolineMethod gets created for it through
// com.oracle.svm.jni.hosted.JNINativeCallWrapperSubstitutionProcessor.lookup
metaAccess.lookupJavaMethod(reflectionMethod);
JNICallTrampolineMethod trampoline = getCallTrampolineMethod(trampolineName);
access.registerAsCompiled(access.getUniverse().lookup(trampoline));
AnalysisMethod trampoline = metaAccess.lookupJavaMethod(reflectionMethod);
access.registerAsCompiled(trampoline);
}

public JNICallTrampolineMethod getCallTrampolineMethod(CallVariant variant, boolean nonVirtual) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,8 +32,8 @@
import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl;
import com.oracle.svm.jni.JNIJavaCallTrampolines;
import com.oracle.svm.jni.access.JNIAccessFeature;
import jdk.vm.ci.meta.MetaUtil;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;

/**
* Substitutes methods declared as {@code native} with {@link JNINativeCallWrapperMethod} instances
Expand All @@ -42,17 +42,17 @@
class JNINativeCallWrapperSubstitutionProcessor extends SubstitutionProcessor {
private final Map<ResolvedJavaMethod, JNINativeCallWrapperMethod> callWrappers = new ConcurrentHashMap<>();
private final DuringSetupAccessImpl access;
private final ResolvedJavaType jniJavaCallTrampolinesType;

JNINativeCallWrapperSubstitutionProcessor(DuringSetupAccessImpl access) {
super();
this.access = access;
this.jniJavaCallTrampolinesType = access.getMetaAccess().lookupJavaType(JNIJavaCallTrampolines.class).getWrapped();
}

@Override
public ResolvedJavaMethod lookup(ResolvedJavaMethod method) {
assert method.isNative() : "Must have been registered as a native substitution processor";
String jniJavaCallWrappersInternalName = MetaUtil.toInternalName(JNIJavaCallTrampolines.class.getTypeName());
if (method.getDeclaringClass().getName().equals(jniJavaCallWrappersInternalName)) {
if (method.getDeclaringClass() == jniJavaCallTrampolinesType) {
// Avoid generating JNINativeCallWrapperMethods for trampolines
return JNIAccessFeature.singleton().getOrCreateCallTrampolineMethod(access, method.getName());
}
Expand Down

0 comments on commit 9005517

Please sign in to comment.