Skip to content

Commit 083d75d

Browse files
committed
TruffleHostEnvironment does not call TruffleCompilerRuntime#getHostMethodInfo.
1 parent 1006af4 commit 083d75d

File tree

5 files changed

+53
-13
lines changed

5 files changed

+53
-13
lines changed

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/truffle/LibGraalTruffleHostEnvironment.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.lang.invoke.MethodHandles;
2929
import java.lang.invoke.MethodType;
3030
import java.util.Map;
31+
import java.util.function.Function;
3132

3233
import com.oracle.truffle.compiler.HostMethodInfo;
3334
import com.oracle.truffle.compiler.TruffleCompilable;
@@ -41,7 +42,6 @@
4142
import jdk.graal.compiler.truffle.TruffleCompilerImpl;
4243
import jdk.graal.compiler.truffle.TruffleElementCache;
4344
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
44-
import jdk.graal.compiler.truffle.host.TruffleKnownHostTypes;
4545
import jdk.graal.compiler.truffle.hotspot.HotSpotTruffleCompilerImpl;
4646
import jdk.vm.ci.meta.MetaAccessProvider;
4747
import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -101,14 +101,8 @@ protected Object createKey(ResolvedJavaMethod method) {
101101

102102
@Override
103103
protected HostMethodInfo computeValue(ResolvedJavaMethod method) {
104-
TruffleKnownHostTypes hostTypes = types();
105104
Map<ResolvedJavaType, AnnotationValue> annotations = AnnotationValueSupport.getDeclaredAnnotationValues(method);
106-
boolean isTruffleBoundary = annotations.containsKey(hostTypes.TruffleBoundary);
107-
boolean isBytecodeInterpreterSwitch = annotations.containsKey(hostTypes.BytecodeInterpreterSwitch);
108-
boolean isBytecodeInterpreterSwitchBoundary = annotations.containsKey(hostTypes.BytecodeInterpreterSwitchBoundary);
109-
boolean isInliningCutoff = annotations.containsKey(hostTypes.InliningCutoff);
110-
boolean isInliningRoot = annotations.containsKey(hostTypes.InliningRoot);
111-
return new HostMethodInfo(isTruffleBoundary, isBytecodeInterpreterSwitch, isBytecodeInterpreterSwitchBoundary, isInliningCutoff, isInliningRoot);
105+
return computeHostMethodInfo(annotations, Function.identity());
112106
}
113107

114108
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/host/TruffleHostEnvironment.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package jdk.graal.compiler.truffle.host;
2626

27+
import jdk.graal.compiler.annotation.AnnotationValue;
2728
import jdk.graal.compiler.debug.GraalError;
2829
import jdk.graal.compiler.serviceprovider.GraalServices;
2930
import jdk.graal.compiler.serviceprovider.LibGraalService;
@@ -39,6 +40,9 @@
3940
import jdk.vm.ci.meta.ResolvedJavaMethod;
4041
import jdk.vm.ci.meta.ResolvedJavaType;
4142

43+
import java.util.Map;
44+
import java.util.function.Function;
45+
4246
/**
4347
* This class manages Truffle resources used during host Java compilation. A host environment is
4448
* only available if the Truffle runtime was fully initialized. In practice this means that several
@@ -162,6 +166,31 @@ public TruffleRuntimeScope openTruffleRuntimeScope() {
162166
return null;
163167
}
164168

169+
/**
170+
* Computes a {@link HostMethodInfo} instance based on the annotations present on a given
171+
* method.
172+
*
173+
* @param declaredAnnotationValues a map of method annotations keyed by their declaring
174+
* {@link ResolvedJavaType}
175+
* @param unwrapType a function that unwraps a {@link ResolvedJavaType} obtained from
176+
* {@code hostTypes} to its underlying host {@link ResolvedJavaType}. In
177+
* native-image, known Truffle types are represented as {@code AnalysisType}, while
178+
* the keys in {@code declaredAnnotationValues} correspond to host JVMCI types.
179+
* Therefore, each {@code AnalysisType} must be unwrapped via
180+
* {@code OriginalClassProvider.getOriginalType(JavaType)} to correctly access the
181+
* corresponding annotation entries in {@code declaredAnnotationValues}.
182+
*/
183+
protected final HostMethodInfo computeHostMethodInfo(Map<ResolvedJavaType, AnnotationValue> declaredAnnotationValues,
184+
Function<ResolvedJavaType, ResolvedJavaType> unwrapType) {
185+
TruffleKnownHostTypes hostTypes = types();
186+
boolean isTruffleBoundary = declaredAnnotationValues.containsKey(unwrapType.apply(hostTypes.TruffleBoundary));
187+
boolean isBytecodeInterpreterSwitch = declaredAnnotationValues.containsKey(unwrapType.apply(hostTypes.BytecodeInterpreterSwitch));
188+
boolean isBytecodeInterpreterSwitchBoundary = declaredAnnotationValues.containsKey(unwrapType.apply(hostTypes.BytecodeInterpreterSwitchBoundary));
189+
boolean isInliningCutoff = declaredAnnotationValues.containsKey(unwrapType.apply(hostTypes.InliningCutoff));
190+
boolean isInliningRoot = declaredAnnotationValues.containsKey(unwrapType.apply(hostTypes.InliningRoot));
191+
return new HostMethodInfo(isTruffleBoundary, isBytecodeInterpreterSwitch, isBytecodeInterpreterSwitchBoundary, isInliningCutoff, isInliningRoot);
192+
}
193+
165194
@LibGraalService
166195
public interface Lookup {
167196

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/HotSpotTruffleHostEnvironment.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package jdk.graal.compiler.truffle.hotspot;
2626

27+
import jdk.graal.compiler.annotation.AnnotationValue;
28+
import jdk.graal.compiler.annotation.AnnotationValueSupport;
2729
import jdk.graal.compiler.debug.GraalError;
2830
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
2931
import jdk.graal.compiler.truffle.TruffleCompilerImpl;
@@ -35,6 +37,10 @@
3537

3638
import jdk.vm.ci.meta.MetaAccessProvider;
3739
import jdk.vm.ci.meta.ResolvedJavaMethod;
40+
import jdk.vm.ci.meta.ResolvedJavaType;
41+
42+
import java.util.Map;
43+
import java.util.function.Function;
3844

3945
final class HotSpotTruffleHostEnvironment extends TruffleHostEnvironment {
4046

@@ -80,7 +86,8 @@ protected Object createKey(ResolvedJavaMethod method) {
8086

8187
@Override
8288
protected HostMethodInfo computeValue(ResolvedJavaMethod method) {
83-
return runtime().getHostMethodInfo(method);
89+
Map<ResolvedJavaType, AnnotationValue> annotations = AnnotationValueSupport.getDeclaredAnnotationValues(method);
90+
return computeHostMethodInfo(annotations, Function.identity());
8491
}
8592

8693
}

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleHostEnvironment.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
*/
2525
package com.oracle.svm.truffle;
2626

27+
import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor;
28+
import com.oracle.svm.util.OriginalClassProvider;
29+
import jdk.graal.compiler.annotation.AnnotationValue;
30+
import jdk.vm.ci.meta.ResolvedJavaType;
31+
import org.graalvm.nativeimage.ImageSingletons;
2732
import org.graalvm.nativeimage.Platform;
2833
import org.graalvm.nativeimage.Platforms;
2934

@@ -37,6 +42,9 @@
3742
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
3843
import jdk.vm.ci.meta.MetaAccessProvider;
3944
import jdk.vm.ci.meta.ResolvedJavaMethod;
45+
import org.graalvm.nativeimage.impl.AnnotationExtractor;
46+
47+
import java.util.Map;
4048

4149
@Platforms(Platform.HOSTED_ONLY.class)
4250
final class SubstrateTruffleHostEnvironment extends TruffleHostEnvironment {
@@ -74,7 +82,9 @@ protected Object createKey(ResolvedJavaMethod method) {
7482

7583
@Override
7684
protected HostMethodInfo computeValue(ResolvedJavaMethod method) {
77-
return runtime().getHostMethodInfo(method);
85+
SubstrateAnnotationExtractor extractor = (SubstrateAnnotationExtractor) ImageSingletons.lookup(AnnotationExtractor.class);
86+
Map<ResolvedJavaType, AnnotationValue> annotations = extractor.getDeclaredAnnotationValues(method);
87+
return computeHostMethodInfo(annotations, OriginalClassProvider::getOriginalType);
7888
}
7989

8090
}

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleRuntime.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,19 @@ protected EngineCacheSupport loadEngineCacheSupport(List<OptionDescriptors> opti
184184
@Override
185185
@Platforms(Platform.HOSTED_ONLY.class)
186186
public PartialEvaluationMethodInfo getPartialEvaluationMethodInfo(ResolvedJavaMethod method) {
187-
return super.getPartialEvaluationMethodInfo(method);
187+
throw new UnsupportedOperationException();
188188
}
189189

190190
@Override
191191
@Platforms(Platform.HOSTED_ONLY.class)
192192
public HostMethodInfo getHostMethodInfo(ResolvedJavaMethod method) {
193-
return super.getHostMethodInfo(method);
193+
throw new UnsupportedOperationException();
194194
}
195195

196196
@Override
197197
@Platforms(Platform.HOSTED_ONLY.class)
198198
public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
199-
return super.getConstantFieldInfo(field);
199+
throw new UnsupportedOperationException();
200200
}
201201

202202
private void teardownCompilerIsolate() {

0 commit comments

Comments
 (0)