Skip to content

Commit d8c463e

Browse files
Zeaveecstancu
authored andcommitted
[GR-59256] Write missing constants in the application layer
PullRequest: graal/20063
2 parents 46b3f87 + b1d054d commit d8c463e

File tree

8 files changed

+35
-15
lines changed

8 files changed

+35
-15
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapConstant.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ abstract static class ConstantData {
9797
* constant created in the current layer.
9898
*/
9999
private boolean isInBaseLayer;
100+
/**
101+
* A boolean telling if the constant was written in the image heap of the base layer.
102+
*/
103+
private boolean writtenInPreviousLayer;
100104
/**
101105
* An object representing a way to retrieve the value of the constant in the hosted
102106
* universe.
@@ -212,6 +216,15 @@ public boolean isInBaseLayer() {
212216
return constantData.isInBaseLayer;
213217
}
214218

219+
public void markWrittenInPreviousLayer() {
220+
AnalysisError.guarantee(isInBaseLayer(), "Constant must be in base layer to be marked as written in the base layer.");
221+
constantData.writtenInPreviousLayer = true;
222+
}
223+
224+
public boolean isWrittenInPreviousLayer() {
225+
return constantData.writtenInPreviousLayer;
226+
}
227+
215228
public JavaConstant getHostedObject() {
216229
AnalysisError.guarantee(!CompressibleConstant.isCompressed(constantData.hostedObject), "References to hosted objects should never be compressed.");
217230
return constantData.hostedObject;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HeapBreakdownProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected void calculate(BeforeImageWriteAccessImpl access) {
109109
Set<byte[]> seenStringByteArrays = Collections.newSetFromMap(new IdentityHashMap<>());
110110
final boolean reportStringBytesConstant = reportStringBytes;
111111
for (ObjectInfo o : access.getImage().getHeap().getObjects()) {
112-
if (o.getConstant().isInBaseLayer()) {
112+
if (o.getConstant().isWrittenInPreviousLayer()) {
113113
continue;
114114
}
115115
long objectSize = o.getSize();

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ private static void printHistogram(ImageHeapPartition partition, Iterable<Object
898898
long canonicalizedCount = 0L;
899899
long canonicalizedSize = 0L;
900900
for (ObjectInfo info : objects) {
901-
if (info.getConstant().isInBaseLayer()) {
901+
if (info.getConstant().isWrittenInPreviousLayer()) {
902902
continue;
903903
}
904904
if (partition == info.getPartition()) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public int getObjectCount() {
179179
}
180180

181181
public int getLayerObjectCount() {
182-
return (int) objects.values().stream().filter(o -> !o.constant.isInBaseLayer()).count();
182+
return (int) objects.values().stream().filter(o -> !o.constant.isWrittenInPreviousLayer()).count();
183183
}
184184

185185
public ObjectInfo getObjectInfo(Object obj) {
@@ -418,7 +418,7 @@ private int computeIdentityHashCode(JavaConstant constant) {
418418
public int countDynamicHubs() {
419419
int count = 0;
420420
for (ObjectInfo o : getObjects()) {
421-
if (!o.constant.isInBaseLayer() && hMetaAccess.isInstanceOf(o.getConstant(), DynamicHub.class)) {
421+
if (!o.constant.isWrittenInPreviousLayer() && hMetaAccess.isInstanceOf(o.getConstant(), DynamicHub.class)) {
422422
count++;
423423
}
424424
}
@@ -648,7 +648,7 @@ private void addObjectToImageHeap(final JavaConstant constant, boolean immutable
648648
* are reachable from regular constants in this layer.
649649
*/
650650
private static boolean processBaseLayerConstant(JavaConstant constant, ObjectInfo info) {
651-
if (((ImageHeapConstant) constant).isInBaseLayer()) {
651+
if (((ImageHeapConstant) constant).isWrittenInPreviousLayer()) {
652652
info.setOffsetInPartition(HostedImageLayerBuildingSupport.singleton().getLoader().getObjectOffset(constant));
653653
info.setHeapPartition(BASE_LAYER_PARTITION);
654654
return true;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeapWriter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ public long writeHeap(DebugContext debug, RelocatableBuffer buffer) {
103103
try (Indent perHeapIndent = debug.logAndIndent("NativeImageHeap.writeHeap:")) {
104104
for (ObjectInfo info : heap.getObjects()) {
105105
assert !heap.isBlacklisted(info.getObject());
106-
if (info.getConstant().isInBaseLayer()) {
106+
if (info.getConstant().isWrittenInPreviousLayer()) {
107107
/*
108-
* Base layer constants are only added to the heap model to store the absolute
109-
* offset in the base layer heap. We don't need to actually write them; their
110-
* absolute offset is used by the objects that reference them.
108+
* Base layer constants already written in the base layer heap are only added to
109+
* the heap model to store the absolute offset in the base layer heap. We don't
110+
* need to actually write them; their absolute offset is used by the objects
111+
* that reference them.
111112
*/
112113
continue;
113114
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/ObjectGroupHistogram.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void doPrint() {
126126

127127
HeapHistogram totalHistogram = new HeapHistogram();
128128
for (ObjectInfo info : heap.getObjects()) {
129-
if (info.getConstant().isInBaseLayer()) {
129+
if (info.getConstant().isWrittenInPreviousLayer()) {
130130
continue;
131131
}
132132
totalHistogram.add(info, info.getSize());
@@ -162,7 +162,7 @@ private static Object readTruffleRuntimeCompilationSupportField(String name) {
162162

163163
public void processType(Class<?> clazz, String group, boolean addObject, ObjectFilter objectFilter, FieldFilter fieldFilter) {
164164
for (ObjectInfo info : heap.getObjects()) {
165-
if (!info.getConstant().isInBaseLayer() && clazz.isInstance(info.getObject())) {
165+
if (!info.getConstant().isWrittenInPreviousLayer() && clazz.isInstance(info.getObject())) {
166166
processObject(info, group, addObject, 1, objectFilter, fieldFilter);
167167
}
168168
}
@@ -185,8 +185,8 @@ public void processObject(Object object, String group, boolean addObject, Object
185185
private void processObject(ObjectInfo info, String group, boolean addObject, int recursionLevel, ObjectFilter objectFilter, FieldFilter fieldFilter) {
186186
assert info != null;
187187
ImageHeapConstant ihc = info.getConstant();
188-
if (ihc.isInBaseLayer()) {
189-
/* Base layer objects don't count towards current layer's statistics. */
188+
if (ihc.isWrittenInPreviousLayer()) {
189+
/* Written base layer objects don't count towards current layer's statistics. */
190190
return;
191191
}
192192
if (objectFilter != null && !objectFilter.test(info, recursionLevel)) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,7 @@ private void addBaseLayerObject(int id, long objectOffset, Supplier<ImageHeapCon
14971497
}
14981498
if (objectOffset != -1) {
14991499
objectOffsets.put(ImageHeapConstant.getConstantID(heapObj), objectOffset);
1500+
heapObj.markWrittenInPreviousLayer();
15001501
}
15011502
return heapObj;
15021503
});

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerWriter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ private static void persistMethodWrappedMember(PersistedAnalysisMethod.WrappedMe
631631
Parameter[] params = member.getParameters();
632632
TextList.Builder atb = b.initArgumentTypeNames(params.length);
633633
for (int i = 0; i < params.length; i++) {
634-
atb.set(i, new Text.Reader(params[i].getName()));
634+
atb.set(i, new Text.Reader(params[i].getType().getName()));
635635
}
636636
}
637637

@@ -810,9 +810,11 @@ private void persistConstantRelinkingInfo(PersistedConstant.Builder builder, Ima
810810
Relinking.Builder relinkingBuilder = builder.getObject().getRelinking();
811811
int id = ImageHeapConstant.getConstantID(imageHeapConstant);
812812
ResolvedJavaType type = bb.getConstantReflectionProvider().asJavaType(hostedObject);
813+
boolean tryStaticFinalFieldRelink = true;
813814
if (type instanceof AnalysisType analysisType) {
814815
relinkingBuilder.initClassConstant().setTypeId(analysisType.getId());
815816
constantsToRelink.add(id);
817+
tryStaticFinalFieldRelink = false;
816818
} else if (clazz.equals(String.class)) {
817819
StringConstant.Builder stringConstantBuilder = relinkingBuilder.initStringConstant();
818820
String value = bb.getSnippetReflectionProvider().asObject(String.class, hostedObject);
@@ -822,14 +824,17 @@ private void persistConstantRelinkingInfo(PersistedConstant.Builder builder, Ima
822824
*/
823825
stringConstantBuilder.setValue(value);
824826
constantsToRelink.add(id);
827+
tryStaticFinalFieldRelink = false;
825828
}
826829
} else if (Enum.class.isAssignableFrom(clazz)) {
827830
EnumConstant.Builder enumBuilder = relinkingBuilder.initEnumConstant();
828831
Enum<?> value = bb.getSnippetReflectionProvider().asObject(Enum.class, hostedObject);
829832
enumBuilder.setEnumClass(value.getDeclaringClass().getName());
830833
enumBuilder.setEnumName(value.name());
831834
constantsToRelink.add(id);
832-
} else if (shouldRelinkConstant(imageHeapConstant) && imageHeapConstant.getOrigin() != null) {
835+
tryStaticFinalFieldRelink = false;
836+
}
837+
if (tryStaticFinalFieldRelink && shouldRelinkConstant(imageHeapConstant) && imageHeapConstant.getOrigin() != null) {
833838
AnalysisField field = imageHeapConstant.getOrigin();
834839
if (shouldRelinkField(field)) {
835840
Relinking.FieldConstant.Builder fieldConstantBuilder = relinkingBuilder.initFieldConstant();

0 commit comments

Comments
 (0)