26
26
27
27
import static com .oracle .svm .core .annotate .RecomputeFieldValue .Kind .AtomicFieldUpdaterOffset ;
28
28
import static com .oracle .svm .core .annotate .RecomputeFieldValue .Kind .FieldOffset ;
29
+ import static com .oracle .svm .core .annotate .RecomputeFieldValue .Kind .StaticFieldBase ;
29
30
import static com .oracle .svm .core .annotate .RecomputeFieldValue .Kind .TranslateFieldOffset ;
30
31
import static com .oracle .svm .core .util .VMError .guarantee ;
31
32
import static com .oracle .svm .core .util .VMError .shouldNotReachHere ;
48
49
import com .oracle .graal .pointsto .meta .AnalysisMetaAccess ;
49
50
import com .oracle .graal .pointsto .util .GraalAccess ;
50
51
import com .oracle .svm .core .BuildPhaseProvider ;
52
+ import com .oracle .svm .core .StaticFieldsSupport ;
51
53
import com .oracle .svm .core .annotate .RecomputeFieldValue ;
52
54
import com .oracle .svm .core .config .ConfigurationValues ;
53
55
import com .oracle .svm .core .fieldvaluetransformer .FieldValueTransformerWithAvailability ;
@@ -133,11 +135,11 @@ public ComputedValueField(ResolvedJavaField original, ResolvedJavaField annotate
133
135
constantValue = JavaConstant .defaultForKind (getJavaKind ());
134
136
break ;
135
137
case FieldOffset :
136
- try {
137
- f = targetClass . getDeclaredField ( targetName ) ;
138
- } catch ( NoSuchFieldException e ) {
139
- throw shouldNotReachHere ( "could not find target field " + targetClass . getName () + "." + targetName + " for alias " + annotated . format ( "%H.%n" ) );
140
- }
138
+ f = getField ( annotated , targetClass , targetName );
139
+ break ;
140
+ case StaticFieldBase :
141
+ f = getField ( annotated , targetClass , targetName );
142
+ UserError . guarantee ( Modifier . isStatic ( f . getModifiers ()), "Target field must be static for %s computation of %s" , StaticFieldBase , fieldFormat ());
141
143
break ;
142
144
case Custom :
143
145
if (initialTransformer != null ) {
@@ -154,15 +156,24 @@ public ComputedValueField(ResolvedJavaField original, ResolvedJavaField annotate
154
156
}
155
157
}
156
158
boolean isOffsetField = isOffsetRecomputation (kind );
159
+ boolean isStaticFieldBase = kind == StaticFieldBase ;
157
160
guarantee (!isFinal || !isOffsetField );
158
- this .isValueAvailableBeforeAnalysis = customValueAvailableBeforeAnalysis && !isOffsetField ;
159
- this .isValueAvailableOnlyAfterAnalysis = customValueAvailableOnlyAfterAnalysis || isOffsetField ;
161
+ this .isValueAvailableBeforeAnalysis = customValueAvailableBeforeAnalysis && !isOffsetField && ! isStaticFieldBase ;
162
+ this .isValueAvailableOnlyAfterAnalysis = customValueAvailableOnlyAfterAnalysis || isOffsetField || isStaticFieldBase ;
160
163
this .isValueAvailableOnlyAfterCompilation = customValueAvailableOnlyAfterCompilation ;
161
164
this .targetField = f ;
162
165
this .fieldValueTransformer = transformer ;
163
166
this .valueCache = EconomicMap .create ();
164
167
}
165
168
169
+ private static Field getField (ResolvedJavaField annotated , Class <?> targetClass , String targetName ) {
170
+ try {
171
+ return targetClass .getDeclaredField (targetName );
172
+ } catch (NoSuchFieldException e ) {
173
+ throw UserError .abort ("Could not find target field %s.%s for alias %s." , targetClass .getName (), targetName , annotated .format ("%H.%n" ));
174
+ }
175
+ }
176
+
166
177
public static boolean isOffsetRecomputation (RecomputeFieldValue .Kind kind ) {
167
178
return offsetComputationKinds .contains (kind );
168
179
}
@@ -282,6 +293,10 @@ public JavaConstant readValue(MetaAccessProvider metaAccess, JavaConstant receiv
282
293
case ArrayIndexShift :
283
294
constantValue = asConstant (ConfigurationValues .getObjectLayout ().getArrayIndexShift (JavaKind .fromJavaClass (targetClass .getComponentType ())));
284
295
return constantValue ;
296
+ case StaticFieldBase :
297
+ Object staticFieldsArray = targetField .getType ().isPrimitive () ? StaticFieldsSupport .getStaticPrimitiveFields () : StaticFieldsSupport .getStaticObjectFields ();
298
+ constantValue = GraalAccess .getOriginalSnippetReflection ().forObject (staticFieldsArray );
299
+ return constantValue ;
285
300
}
286
301
287
302
ReadLock readLock = valueCacheLock .readLock ();
@@ -342,9 +357,9 @@ private JavaConstant computeValue(MetaAccessProvider metaAccess, JavaConstant re
342
357
originalValue = fetchOriginalValue (metaAccess , receiver , originalSnippetReflection );
343
358
Object newValue = fieldValueTransformer .transform (receiverValue , originalValue );
344
359
checkValue (newValue );
345
- result = originalSnippetReflection .forBoxed (annotated .getJavaKind (), newValue );
360
+ result = originalSnippetReflection .forBoxed (original .getJavaKind (), newValue );
346
361
347
- assert result .getJavaKind () == annotated .getJavaKind ();
362
+ assert result .getJavaKind () == original .getJavaKind ();
348
363
break ;
349
364
default :
350
365
throw shouldNotReachHere ("Field recomputation of kind " + kind + " for " + fieldFormat () + " not yet supported" );
0 commit comments