Skip to content

Commit eaaccdf

Browse files
committed
Resolved review comments.
1 parent 46592f2 commit eaaccdf

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/KnownTruffleTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class KnownTruffleTypes extends AbstractKnownTruffleTypes {
106106
public final ResolvedJavaType UnexpectedResultException = lookupType("com.oracle.truffle.api.nodes.UnexpectedResultException");
107107
public final ResolvedJavaType SlowPathException = lookupType("com.oracle.truffle.api.nodes.SlowPathException");
108108
public final ResolvedJavaType ExplodeLoop = lookupType("com.oracle.truffle.api.nodes.ExplodeLoop");
109+
public final ResolvedJavaType ExplodeLoop_LoopExplosionKind = lookupType("com.oracle.truffle.api.nodes.ExplodeLoop$LoopExplosionKind");
109110

110111
// truffle.api.frame
111112
public final ResolvedJavaType VirtualFrame = lookupType("com.oracle.truffle.api.frame.VirtualFrame");

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/PartialEvaluator.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,22 @@ public static PartialEvaluationMethodInfo computePartialEvaluationMethodInfo(Tru
210210
boolean specialization = declaredAnnotationValues.get(types.Specialization) != null;
211211
AnnotationValue explodeLoop = declaredAnnotationValues.get(types.ExplodeLoop);
212212

213-
return new PartialEvaluationMethodInfo(getLoopExplosionKind(explodeLoop),
213+
return new PartialEvaluationMethodInfo(getLoopExplosionKind(explodeLoop, types),
214214
getInlineKind(runtime, truffleBoundary, truffleCallBoundary, method, true, types),
215215
getInlineKind(runtime, truffleBoundary, truffleCallBoundary, method, false, types),
216216
method.canBeInlined(),
217217
specialization);
218218
}
219219

220-
private static LoopExplosionKind getLoopExplosionKind(AnnotationValue value) {
220+
private static LoopExplosionKind getLoopExplosionKind(AnnotationValue value, KnownTruffleTypes types) {
221221
if (value == null) {
222222
return LoopExplosionKind.NONE;
223223
}
224-
String kind = value.get("kind", EnumElement.class).name;
225-
return switch (kind) {
226-
case "FULL_UNROLL" -> LoopExplosionKind.FULL_UNROLL;
227-
case "FULL_UNROLL_UNTIL_RETURN" -> LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN;
228-
case "FULL_EXPLODE" -> LoopExplosionKind.FULL_EXPLODE;
229-
case "FULL_EXPLODE_UNTIL_RETURN" -> LoopExplosionKind.FULL_EXPLODE_UNTIL_RETURN;
230-
case "MERGE_EXPLODE" -> LoopExplosionKind.MERGE_EXPLODE;
231-
default -> throw new InternalError(String.format("Unknown Truffle LoopExplosionKind %s", kind));
232-
};
224+
EnumElement enumElement = value.get("kind", EnumElement.class);
225+
if (!types.ExplodeLoop_LoopExplosionKind.equals(enumElement.enumType)) {
226+
throw new IllegalStateException("Incompatible ExplodeLoop change. ExplodeLoop.kind must be LoopExplosionKind.");
227+
}
228+
return Enum.valueOf(LoopExplosionKind.class, enumElement.name);
233229
}
234230

235231
private static InlineKind getInlineKind(TruffleCompilerRuntime runtime, AnnotationValue truffleBoundary, AnnotationValue truffleCallBoundary,

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleElementCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class TruffleElementCache<K, V> {
4141
/**
4242
* Value representing a null value in the cache.
4343
*/
44-
private final Object NULL_VALUE = new Object();
44+
private static final Object NULL_VALUE = new Object();
4545

4646
@SuppressWarnings("serial")
4747
protected TruffleElementCache(int maxSize) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public EconomicMap<ResolvedJavaMethod, EncodedGraph> getOrCreateEncodedGraphCach
123123
cache = graphCacheRef.get();
124124
} while (cache == null &&
125125
!graphCacheRef.compareAndSet(null, cache = EconomicMap.wrapMap(new ConcurrentHashMap<>())));
126+
assert cache != null;
126127
return cache;
127128
}
128129

truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntime.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ private static boolean findInliningRootSupported() {
189189
}
190190

191191
private static MethodHandle findGetAnnotation() {
192+
/*
193+
* In JDK versions prior to 25.1, ResolvedJavaType implemented AnnotatedElement, and the
194+
* Graal compiler queried the Truffle runtime to retrieve annotation values.
195+
*
196+
* Starting with JDK 25.1, ResolvedJavaType no longer implements AnnotatedElement.
197+
* Instead, the Graal compiler directly reads annotation values using the
198+
* jdk.graal.compiler.annotation API.
199+
*
200+
* As a result, on JDK 25.1 and later, the Truffle runtime is never queried by the Graal
201+
* compiler to obtain annotation values. For compatibility, getAnnotation is still
202+
* supported when Truffle runs on GraalVM versions older than 25.1.
203+
*/
192204
if (AnnotatedElement.class.isAssignableFrom(ResolvedJavaType.class)) {
193205
try {
194206
Method method = AnnotatedElement.class.getDeclaredMethod("getAnnotation", Class.class);
@@ -488,6 +500,7 @@ private static UnmodifiableEconomicMap<String, Class<?>> initLookupTypes(Iterabl
488500
InlineSupport.DoubleField.class,
489501
InlineSupport.ReferenceField.class,
490502
ExplodeLoop.class,
503+
ExplodeLoop.LoopExplosionKind.class,
491504
Specialization.class,
492505
TruffleCallBoundary.class,
493506
}) {

0 commit comments

Comments
 (0)