diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapConstant.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapConstant.java index 978d73b2b354..b03df7313451 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapConstant.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapConstant.java @@ -97,6 +97,10 @@ abstract static class ConstantData { * constant created in the current layer. */ private boolean isInBaseLayer; + /** + * A boolean telling if the constant was written in the image heap of the base layer. + */ + private boolean writtenInPreviousLayer; /** * An object representing a way to retrieve the value of the constant in the hosted * universe. @@ -212,6 +216,15 @@ public boolean isInBaseLayer() { return constantData.isInBaseLayer; } + public void markWrittenInPreviousLayer() { + AnalysisError.guarantee(isInBaseLayer(), "Constant must be in base layer to be marked as written in the base layer."); + constantData.writtenInPreviousLayer = true; + } + + public boolean isWrittenInPreviousLayer() { + return constantData.writtenInPreviousLayer; + } + public JavaConstant getHostedObject() { AnalysisError.guarantee(!CompressibleConstant.isCompressed(constantData.hostedObject), "References to hosted objects should never be compressed."); return constantData.hostedObject; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HeapBreakdownProvider.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HeapBreakdownProvider.java index 7e9ed3f0eb84..f2f19693767e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HeapBreakdownProvider.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HeapBreakdownProvider.java @@ -109,7 +109,7 @@ protected void calculate(BeforeImageWriteAccessImpl access) { Set seenStringByteArrays = Collections.newSetFromMap(new IdentityHashMap<>()); final boolean reportStringBytesConstant = reportStringBytes; for (ObjectInfo o : access.getImage().getHeap().getObjects()) { - if (o.getConstant().isInBaseLayer()) { + if (o.getConstant().isWrittenInPreviousLayer()) { continue; } long objectSize = o.getSize(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java index 9a863c53c074..e3dde81928b1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java @@ -898,7 +898,7 @@ private static void printHistogram(ImageHeapPartition partition, Iterable !o.constant.isInBaseLayer()).count(); + return (int) objects.values().stream().filter(o -> !o.constant.isWrittenInPreviousLayer()).count(); } public ObjectInfo getObjectInfo(Object obj) { @@ -418,7 +418,7 @@ private int computeIdentityHashCode(JavaConstant constant) { public int countDynamicHubs() { int count = 0; for (ObjectInfo o : getObjects()) { - if (!o.constant.isInBaseLayer() && hMetaAccess.isInstanceOf(o.getConstant(), DynamicHub.class)) { + if (!o.constant.isWrittenInPreviousLayer() && hMetaAccess.isInstanceOf(o.getConstant(), DynamicHub.class)) { count++; } } @@ -648,7 +648,7 @@ private void addObjectToImageHeap(final JavaConstant constant, boolean immutable * are reachable from regular constants in this layer. */ private static boolean processBaseLayerConstant(JavaConstant constant, ObjectInfo info) { - if (((ImageHeapConstant) constant).isInBaseLayer()) { + if (((ImageHeapConstant) constant).isWrittenInPreviousLayer()) { info.setOffsetInPartition(HostedImageLayerBuildingSupport.singleton().getLoader().getObjectOffset(constant)); info.setHeapPartition(BASE_LAYER_PARTITION); return true; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeapWriter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeapWriter.java index 35fe27ec4f03..2a03cb17929b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeapWriter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeapWriter.java @@ -103,11 +103,12 @@ public long writeHeap(DebugContext debug, RelocatableBuffer buffer) { try (Indent perHeapIndent = debug.logAndIndent("NativeImageHeap.writeHeap:")) { for (ObjectInfo info : heap.getObjects()) { assert !heap.isBlacklisted(info.getObject()); - if (info.getConstant().isInBaseLayer()) { + if (info.getConstant().isWrittenInPreviousLayer()) { /* - * Base layer constants are only added to the heap model to store the absolute - * offset in the base layer heap. We don't need to actually write them; their - * absolute offset is used by the objects that reference them. + * Base layer constants already written in the base layer heap are only added to + * the heap model to store the absolute offset in the base layer heap. We don't + * need to actually write them; their absolute offset is used by the objects + * that reference them. */ continue; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/ObjectGroupHistogram.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/ObjectGroupHistogram.java index 5e14858adb30..978951547d93 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/ObjectGroupHistogram.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/ObjectGroupHistogram.java @@ -126,7 +126,7 @@ private void doPrint() { HeapHistogram totalHistogram = new HeapHistogram(); for (ObjectInfo info : heap.getObjects()) { - if (info.getConstant().isInBaseLayer()) { + if (info.getConstant().isWrittenInPreviousLayer()) { continue; } totalHistogram.add(info, info.getSize()); @@ -162,7 +162,7 @@ private static Object readTruffleRuntimeCompilationSupportField(String name) { public void processType(Class clazz, String group, boolean addObject, ObjectFilter objectFilter, FieldFilter fieldFilter) { for (ObjectInfo info : heap.getObjects()) { - if (!info.getConstant().isInBaseLayer() && clazz.isInstance(info.getObject())) { + if (!info.getConstant().isWrittenInPreviousLayer() && clazz.isInstance(info.getObject())) { processObject(info, group, addObject, 1, objectFilter, fieldFilter); } } @@ -185,8 +185,8 @@ public void processObject(Object object, String group, boolean addObject, Object private void processObject(ObjectInfo info, String group, boolean addObject, int recursionLevel, ObjectFilter objectFilter, FieldFilter fieldFilter) { assert info != null; ImageHeapConstant ihc = info.getConstant(); - if (ihc.isInBaseLayer()) { - /* Base layer objects don't count towards current layer's statistics. */ + if (ihc.isWrittenInPreviousLayer()) { + /* Written base layer objects don't count towards current layer's statistics. */ return; } if (objectFilter != null && !objectFilter.test(info, recursionLevel)) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java index 60e8c59e8a05..0ec40afc629a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java @@ -1497,6 +1497,7 @@ private void addBaseLayerObject(int id, long objectOffset, Supplier