|
26 | 26 |
|
27 | 27 | import java.net.URI; |
28 | 28 | import java.util.Map; |
| 29 | +import java.util.function.Function; |
29 | 30 | import java.util.function.Supplier; |
30 | 31 |
|
31 | 32 | import jdk.graal.compiler.annotation.EnumElement; |
@@ -181,48 +182,85 @@ private static int actualStableDimensions(ResolvedJavaField field, int dimension |
181 | 182 | * Gets an object describing how a read of {@code field} can be constant folded based on Truffle |
182 | 183 | * annotations. |
183 | 184 | * |
| 185 | + * @param field the field for which to compute {@link ConstantFieldInfo} |
| 186 | + * @param declaredAnnotationValues a map of method annotations keyed by their declaring |
| 187 | + * {@link ResolvedJavaType} |
| 188 | + * @param types cached types known to the Truffle compiler |
| 189 | + * @param unwrapType a function that unwraps a {@link ResolvedJavaType} obtained from |
| 190 | + * {@code types} to its underlying host {@link ResolvedJavaType}. In native-image, |
| 191 | + * known Truffle types are represented as {@code AnalysisType}, while the keys in |
| 192 | + * {@code declaredAnnotationValues} correspond to host JVMCI types. Therefore, each |
| 193 | + * {@code AnalysisType} must be unwrapped via |
| 194 | + * {@code OriginalClassProvider.getOriginalType(JavaType)} to correctly access the |
| 195 | + * corresponding annotation entries in {@code declaredAnnotationValues}. |
| 196 | + * |
184 | 197 | * @return {@code null} if there are no constant folding related Truffle annotations on |
185 | 198 | * {@code field} |
186 | 199 | */ |
187 | 200 | public static ConstantFieldInfo computeConstantFieldInfo(ResolvedJavaField field, |
188 | 201 | Map<ResolvedJavaType, AnnotationValue> declaredAnnotationValues, |
189 | | - KnownTruffleTypes types) { |
190 | | - if (declaredAnnotationValues.containsKey(types.Node_Child)) { |
| 202 | + KnownTruffleTypes types, Function<ResolvedJavaType, ResolvedJavaType> unwrapType) { |
| 203 | + if (declaredAnnotationValues.containsKey(unwrapType.apply(types.Node_Child))) { |
191 | 204 | return ConstantFieldInfo.CHILD; |
192 | 205 | } |
193 | | - if (declaredAnnotationValues.containsKey(types.Node_Children)) { |
| 206 | + if (declaredAnnotationValues.containsKey(unwrapType.apply(types.Node_Children))) { |
194 | 207 | return ConstantFieldInfo.CHILDREN; |
195 | 208 | } |
196 | | - AnnotationValue cf = declaredAnnotationValues.get(types.CompilerDirectives_CompilationFinal); |
| 209 | + AnnotationValue cf = declaredAnnotationValues.get(unwrapType.apply(types.CompilerDirectives_CompilationFinal)); |
197 | 210 | if (cf != null) { |
198 | 211 | int dimensions = actualStableDimensions(field, cf.get("dimensions", Integer.class)); |
199 | 212 | return ConstantFieldInfo.forDimensions(dimensions); |
200 | 213 | } |
201 | 214 | return null; |
202 | 215 | } |
203 | 216 |
|
| 217 | + /** |
| 218 | + * Computes {@link PartialEvaluationMethodInfo} for the given {@code method} based on its |
| 219 | + * declared annotations. |
| 220 | + * |
| 221 | + * <p> |
| 222 | + * This method analyzes the annotations present on {@code method}, provided in |
| 223 | + * {@code declaredAnnotationValues}, and determines partial evaluation behavior such as loop |
| 224 | + * explosion, inlining, and specialization characteristics. |
| 225 | + * </p> |
| 226 | + * |
| 227 | + * @param runtime the Truffle runtime used to determine whether |
| 228 | + * {@linkplain TruffleCompilerRuntime#isJavaInstrumentationActive() flight recorder |
| 229 | + * instrumentation is active} |
| 230 | + * @param method the method for which to compute {@link PartialEvaluationMethodInfo} |
| 231 | + * @param declaredAnnotationValues a map of method annotations keyed by their declaring |
| 232 | + * {@link ResolvedJavaType} |
| 233 | + * @param types cached types known to the Truffle compiler |
| 234 | + * @param unwrapType a function that unwraps a {@link ResolvedJavaType} obtained from |
| 235 | + * {@code types} to its underlying host {@link ResolvedJavaType}. In native-image, |
| 236 | + * known Truffle types are represented as {@code AnalysisType}, while the keys in |
| 237 | + * {@code declaredAnnotationValues} correspond to host JVMCI types. Therefore, each |
| 238 | + * {@code AnalysisType} must be unwrapped via |
| 239 | + * {@code OriginalClassProvider.getOriginalType(JavaType)} to correctly access the |
| 240 | + * corresponding annotation entries in {@code declaredAnnotationValues}. |
| 241 | + */ |
204 | 242 | public static PartialEvaluationMethodInfo computePartialEvaluationMethodInfo(TruffleCompilerRuntime runtime, |
205 | 243 | ResolvedJavaMethod method, |
206 | 244 | Map<ResolvedJavaType, AnnotationValue> declaredAnnotationValues, |
207 | | - KnownTruffleTypes types) { |
208 | | - AnnotationValue truffleBoundary = declaredAnnotationValues.get(types.CompilerDirectives_TruffleBoundary); |
209 | | - AnnotationValue truffleCallBoundary = declaredAnnotationValues.get(types.TruffleCallBoundary); |
210 | | - boolean specialization = declaredAnnotationValues.get(types.Specialization) != null; |
211 | | - AnnotationValue explodeLoop = declaredAnnotationValues.get(types.ExplodeLoop); |
| 245 | + KnownTruffleTypes types, Function<ResolvedJavaType, ResolvedJavaType> unwrapType) { |
| 246 | + AnnotationValue truffleBoundary = declaredAnnotationValues.get(unwrapType.apply(types.CompilerDirectives_TruffleBoundary)); |
| 247 | + AnnotationValue truffleCallBoundary = declaredAnnotationValues.get(unwrapType.apply(types.TruffleCallBoundary)); |
| 248 | + boolean specialization = declaredAnnotationValues.get(unwrapType.apply(types.Specialization)) != null; |
| 249 | + AnnotationValue explodeLoop = declaredAnnotationValues.get(unwrapType.apply(types.ExplodeLoop)); |
212 | 250 |
|
213 | | - return new PartialEvaluationMethodInfo(getLoopExplosionKind(explodeLoop, types), |
| 251 | + return new PartialEvaluationMethodInfo(getLoopExplosionKind(explodeLoop, unwrapType.apply(types.ExplodeLoop_LoopExplosionKind)), |
214 | 252 | getInlineKind(runtime, truffleBoundary, truffleCallBoundary, method, true, types), |
215 | 253 | getInlineKind(runtime, truffleBoundary, truffleCallBoundary, method, false, types), |
216 | 254 | method.canBeInlined(), |
217 | 255 | specialization); |
218 | 256 | } |
219 | 257 |
|
220 | | - private static LoopExplosionKind getLoopExplosionKind(AnnotationValue value, KnownTruffleTypes types) { |
| 258 | + private static LoopExplosionKind getLoopExplosionKind(AnnotationValue value, ResolvedJavaType expectedType) { |
221 | 259 | if (value == null) { |
222 | 260 | return LoopExplosionKind.NONE; |
223 | 261 | } |
224 | 262 | EnumElement enumElement = value.get("kind", EnumElement.class); |
225 | | - if (!types.ExplodeLoop_LoopExplosionKind.equals(enumElement.enumType)) { |
| 263 | + if (!expectedType.equals(enumElement.enumType)) { |
226 | 264 | throw new IllegalStateException("Incompatible ExplodeLoop change. ExplodeLoop.kind must be LoopExplosionKind."); |
227 | 265 | } |
228 | 266 | return Enum.valueOf(LoopExplosionKind.class, enumElement.name); |
|
0 commit comments