Skip to content

Commit 1c7e8eb

Browse files
committed
WIP7.
1 parent 6cbec74 commit 1c7e8eb

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ public enum UsageKind {
244244
/* The registration task initializes the type. */
245245
this.initializationTask = new AnalysisFuture<>(() -> universe.initializeType(this), null);
246246
this.typeData = new AnalysisFuture<>(() -> {
247-
/* Init the type before reading its static fields. */
248-
initializationTask.ensureDone();
249247
AnalysisError.guarantee(universe.getHeapScanner() != null, "Heap scanner is not available.");
250248
return universe.getHeapScanner().computeTypeData(this);
251249
});

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ameta/AnalysisConstantReflectionProvider.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.graalvm.nativeimage.Platforms;
3434
import org.graalvm.word.WordBase;
3535

36+
import com.oracle.graal.pointsto.heap.value.ValueSupplier;
3637
import com.oracle.graal.pointsto.meta.AnalysisField;
3738
import com.oracle.graal.pointsto.meta.AnalysisType;
3839
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
@@ -46,6 +47,7 @@
4647
import com.oracle.svm.core.util.VMError;
4748
import com.oracle.svm.hosted.SVMHost;
4849
import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport;
50+
import com.oracle.svm.hosted.meta.HostedMetaAccess;
4951

5052
import jdk.vm.ci.meta.Constant;
5153
import jdk.vm.ci.meta.ConstantReflectionProvider;
@@ -102,6 +104,42 @@ public JavaConstant readValue(MetaAccessProvider suppliedMetaAccess, AnalysisFie
102104
return interceptValue(field, value);
103105
}
104106

107+
/** Read the field value and wrap it in a value supplier. */
108+
public ValueSupplier<JavaConstant> readHostedFieldValue(AnalysisField field, HostedMetaAccess hMetaAccess, JavaConstant receiver) {
109+
if (classInitializationSupport.shouldInitializeAtRuntime(field.getDeclaringClass())) {
110+
if (field.isStatic()) {
111+
return ValueSupplier.eagerValue(readUninitializedStaticValue(field));
112+
} else {
113+
/*
114+
* Classes that are initialized at run time must not have instances in the image
115+
* heap. Invoking instance methods would miss the class initialization checks. Image
116+
* generation should have been aborted earlier with a user-friendly message, this is
117+
* just a safeguard.
118+
*/
119+
throw VMError.shouldNotReachHere("Cannot read instance field of a class that is initialized at run time: " + field.format("%H.%n"));
120+
}
121+
}
122+
123+
if (field.wrapped instanceof ReadableJavaField) {
124+
ReadableJavaField readableField = (ReadableJavaField) field.wrapped;
125+
if (readableField.isValueAvailableBeforeAnalysis()) {
126+
/* Materialize and return the value. */
127+
return ValueSupplier.eagerValue(universe.lookup(readableField.readValue(metaAccess, receiver)));
128+
} else {
129+
/*
130+
* Return a lazy value. This applies to RecomputeFieldValue.Kind.FieldOffset and
131+
* RecomputeFieldValue.Kind.Custom. The value becomes available during hosted
132+
* universe building and is installed by calling
133+
* ComputedValueField.processSubstrate() or by ComputedValueField.readValue().
134+
* Attempts to materialize the value earlier will result in an error.
135+
*/
136+
return ValueSupplier.lazyValue(() -> universe.lookup(readableField.readValue(hMetaAccess, receiver)),
137+
readableField::isValueAvailable);
138+
}
139+
}
140+
return ValueSupplier.eagerValue(universe.lookup(originalConstantReflection.readFieldValue(field.wrapped, receiver)));
141+
}
142+
105143
/*
106144
* Static fields of classes that are initialized at run time have the default (uninitialized)
107145
* value in the image heap. But there is one important exception:
@@ -126,7 +164,8 @@ public JavaConstant readValue(MetaAccessProvider suppliedMetaAccess, AnalysisFie
126164
* pretty likely (although not guaranteed) that we are not returning an unintended value for a
127165
* class that is re-initialized at run time.
128166
*/
129-
public static JavaConstant readUninitializedStaticValue(AnalysisField field) {
167+
public JavaConstant readUninitializedStaticValue(AnalysisField field) {
168+
assert classInitializationSupport.shouldInitializeAtRuntime(field.getDeclaringClass());
130169
JavaKind kind = field.getJavaKind();
131170

132171
boolean canHaveConstantValueAttribute = kind.isPrimitive() || field.getType().getName().equals("Ljava/lang/String;");

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@
3939
import com.oracle.graal.pointsto.heap.value.ValueSupplier;
4040
import com.oracle.graal.pointsto.meta.AnalysisField;
4141
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
42-
import com.oracle.graal.pointsto.meta.AnalysisType;
4342
import com.oracle.graal.pointsto.util.AnalysisFuture;
4443
import com.oracle.svm.core.BuildPhaseProvider;
4544
import com.oracle.svm.core.meta.ReadableJavaField;
4645
import com.oracle.svm.core.meta.SubstrateObjectConstant;
4746
import com.oracle.svm.core.util.VMError;
4847
import com.oracle.svm.hosted.ImageClassLoader;
49-
import com.oracle.svm.hosted.SVMHost;
5048
import com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider;
5149
import com.oracle.svm.hosted.meta.HostedMetaAccess;
5250
import com.oracle.svm.util.ReflectionUtil;
@@ -85,10 +83,6 @@ protected Class<?> getClass(String className) {
8583
return loader.findClassOrFail(className);
8684
}
8785

88-
protected boolean shouldInitializeAtRunTime(AnalysisType type) {
89-
return ((SVMHost) hostVM).getClassInitializationSupport().shouldInitializeAtRuntime(type);
90-
}
91-
9286
@Override
9387
protected AnalysisFuture<ImageHeapObject> getOrCreateConstantReachableTask(JavaConstant javaConstant, ScanReason reason, Consumer<ScanReason> onAnalysisModified) {
9488
VMError.guarantee(javaConstant instanceof SubstrateObjectConstant, "Not a substrate constant " + javaConstant);
@@ -118,34 +112,8 @@ public boolean isValueAvailable(AnalysisField field) {
118112

119113
@Override
120114
protected ValueSupplier<JavaConstant> readHostedFieldValue(AnalysisField field, JavaConstant receiver) {
121-
if (field.isStatic() && shouldInitializeAtRunTime(field.getDeclaringClass())) {
122-
/*
123-
* Read the uninitialized field value. When all constant reads will be routed through
124-
* the heap snapshot this can be moved to AnalysisConstantReflectionProvider, however
125-
* currently we want to read raw values directly from HotSpot.
126-
*/
127-
return ValueSupplier.eagerValue(AnalysisConstantReflectionProvider.readUninitializedStaticValue(field));
128-
}
129-
130-
if (field.wrapped instanceof ReadableJavaField) {
131-
ReadableJavaField readableField = (ReadableJavaField) field.wrapped;
132-
if (readableField.isValueAvailableBeforeAnalysis()) {
133-
/* Materialize and return the value. */
134-
JavaConstant value = universe.lookup(readableField.readValue(metaAccess, receiver));
135-
return ValueSupplier.eagerValue(value);
136-
} else {
137-
/*
138-
* Return a lazy value. This applies to RecomputeFieldValue.Kind.FieldOffset and
139-
* RecomputeFieldValue.Kind.Custom. The value becomes available during hosted
140-
* universe building and is installed by calling
141-
* ComputedValueField.processSubstrate() or by ComputedValueField.readValue().
142-
* Attempts to materialize the value earlier will result in an error.
143-
*/
144-
return ValueSupplier.lazyValue(() -> universe.lookup(readableField.readValue(hostedMetaAccess, receiver)),
145-
readableField::isValueAvailable);
146-
}
147-
}
148-
return super.readHostedFieldValue(field, receiver);
115+
AnalysisConstantReflectionProvider aConstantReflection = (AnalysisConstantReflectionProvider) this.constantReflection;
116+
return aConstantReflection.readHostedFieldValue(field, hostedMetaAccess, receiver);
149117
}
150118

151119
@Override

0 commit comments

Comments
 (0)