Skip to content

Commit d81251f

Browse files
committed
fixup! Don't create JNINativeCallWrapperMethods for JNICallTrampolineMethods
1 parent a053fe5 commit d81251f

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/JNIJavaCallTrampolines.java

-8
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,10 @@
2828
import com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod;
2929
import com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant;
3030

31-
import jdk.vm.ci.meta.ConstantPool;
32-
import jdk.vm.ci.meta.MetaAccessProvider;
33-
3431
/**
3532
* Holder class for generated {@link JNIJavaCallWrapperMethod} code.
3633
*/
3734
public final class JNIJavaCallTrampolines {
38-
public static ConstantPool getConstantPool(MetaAccessProvider metaAccess) {
39-
// Each generated call wrapper needs an actual constant pool, so we provide our
40-
// private constructor's
41-
return metaAccess.lookupJavaType(JNIJavaCallWrappers.class).getDeclaredConstructors()[0].getConstantPool();
42-
}
4335

4436
private JNIJavaCallTrampolines() {
4537
}

substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/access/JNIAccessFeature.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ public void beforeAnalysis(BeforeAnalysisAccess arg) {
169169
BeforeAnalysisAccessImpl access = (BeforeAnalysisAccessImpl) arg;
170170
this.nativeLibraries = access.getNativeLibraries();
171171

172-
createJavaCallTrampoline(access, CallVariant.VARARGS, false);
173-
createJavaCallTrampoline(access, CallVariant.ARRAY, false);
174-
createJavaCallTrampoline(access, CallVariant.VA_LIST, false);
175-
createJavaCallTrampoline(access, CallVariant.VARARGS, true);
176-
createJavaCallTrampoline(access, CallVariant.ARRAY, true);
177-
createJavaCallTrampoline(access, CallVariant.VA_LIST, true);
172+
registerJavaCallTrampoline(access, CallVariant.VARARGS, false);
173+
registerJavaCallTrampoline(access, CallVariant.ARRAY, false);
174+
registerJavaCallTrampoline(access, CallVariant.VA_LIST, false);
175+
registerJavaCallTrampoline(access, CallVariant.VARARGS, true);
176+
registerJavaCallTrampoline(access, CallVariant.ARRAY, true);
177+
registerJavaCallTrampoline(access, CallVariant.VA_LIST, true);
178178

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

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

201200
public JNICallTrampolineMethod getCallTrampolineMethod(CallVariant variant, boolean nonVirtual) {

substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNINativeCallWrapperSubstitutionProcessor.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,8 +32,8 @@
3232
import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl;
3333
import com.oracle.svm.jni.JNIJavaCallTrampolines;
3434
import com.oracle.svm.jni.access.JNIAccessFeature;
35-
import jdk.vm.ci.meta.MetaUtil;
3635
import jdk.vm.ci.meta.ResolvedJavaMethod;
36+
import jdk.vm.ci.meta.ResolvedJavaType;
3737

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

4647
JNINativeCallWrapperSubstitutionProcessor(DuringSetupAccessImpl access) {
47-
super();
4848
this.access = access;
49+
this.jniJavaCallTrampolinesType = access.getMetaAccess().lookupJavaType(JNIJavaCallTrampolines.class).getWrapped();
4950
}
5051

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

0 commit comments

Comments
 (0)