From 16865066ca384a2351b153797f2bd291e84386fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Mon, 15 May 2023 16:41:13 +0200 Subject: [PATCH] Ensure NativeImageDebugDataInfo methods are used by logging are only called if needed --- .../objectfile/debugentry/DebugInfoBase.java | 29 +++++++++-------- .../image/NativeImageDebugInfoProvider.java | 32 +++++++------------ 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java index 9924800029a5..df163def7af8 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java @@ -34,21 +34,22 @@ import java.util.List; import java.util.Map; -import com.oracle.objectfile.debugentry.range.PrimaryRange; -import com.oracle.objectfile.debugentry.range.Range; -import com.oracle.objectfile.debugentry.range.SubRange; -import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFileInfo; -import jdk.vm.ci.meta.ResolvedJavaType; import org.graalvm.collections.EconomicMap; import org.graalvm.compiler.debug.DebugContext; +import com.oracle.objectfile.debugentry.range.PrimaryRange; +import com.oracle.objectfile.debugentry.range.Range; +import com.oracle.objectfile.debugentry.range.SubRange; import com.oracle.objectfile.debuginfo.DebugInfoProvider; import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugCodeInfo; -import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugLocationInfo; +import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFileInfo; import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugLocalValueInfo; +import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugLocationInfo; import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo.DebugTypeKind; import com.oracle.objectfile.elf.dwarf.DwarfDebugInfo; +import jdk.vm.ci.meta.ResolvedJavaType; + /** * An abstract class which indexes the information presented by the DebugInfoProvider in an * organization suitable for use by subclasses targeting a specific binary format. @@ -349,13 +350,15 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) { })); debugInfoProvider.dataInfoProvider().forEach(debugDataInfo -> debugDataInfo.debugContext((debugContext) -> { - String provenance = debugDataInfo.getProvenance(); - String typeName = debugDataInfo.getTypeName(); - String partitionName = debugDataInfo.getPartition(); - /* Address is heap-register relative pointer. */ - long address = debugDataInfo.getAddress(); - long size = debugDataInfo.getSize(); - debugContext.log(DebugContext.INFO_LEVEL, "Data: address 0x%x size 0x%x type %s partition %s provenance %s ", address, size, typeName, partitionName, provenance); + if (debugContext.isLogEnabled(DebugContext.INFO_LEVEL)) { + String provenance = debugDataInfo.getProvenance(); + String typeName = debugDataInfo.getTypeName(); + String partitionName = debugDataInfo.getPartition(); + /* Address is heap-register relative pointer. */ + long address = debugDataInfo.getAddress(); + long size = debugDataInfo.getSize(); + debugContext.log(DebugContext.INFO_LEVEL, "Data: address 0x%x size 0x%x type %s partition %s provenance %s ", address, size, typeName, partitionName, provenance); + } })); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java index 30da03fc3275..19a39d7f2048 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java @@ -2528,63 +2528,53 @@ public Type getType() { } private class NativeImageDebugDataInfo implements DebugDataInfo { - HostedClass hostedClass; - ImageHeapPartition partition; - long offset; - long address; - long size; - String typeName; - String provenance; + private final NativeImageHeap.ObjectInfo objectInfo; @SuppressWarnings("try") @Override public void debugContext(Consumer action) { - try (DebugContext.Scope s = debugContext.scope("DebugDataInfo", provenance)) { + try (DebugContext.Scope s = debugContext.scope("DebugDataInfo")) { action.accept(debugContext); } catch (Throwable e) { throw debugContext.handle(e); } } + /* Accessors. */ + NativeImageDebugDataInfo(ObjectInfo objectInfo) { - hostedClass = objectInfo.getClazz(); - partition = objectInfo.getPartition(); - offset = objectInfo.getOffset(); - address = objectInfo.getAddress(); - size = objectInfo.getSize(); - provenance = objectInfo.toString(); - typeName = hostedClass.toJavaName(); + this.objectInfo = objectInfo; } - /* Accessors. */ @Override public String getProvenance() { - return provenance; + return objectInfo.toString(); } @Override public String getTypeName() { - return typeName; + return objectInfo.getClazz().toJavaName(); } @Override public String getPartition() { + ImageHeapPartition partition = objectInfo.getPartition(); return partition.getName() + "{" + partition.getSize() + "}@" + partition.getStartOffset(); } @Override public long getOffset() { - return offset; + return objectInfo.getOffset(); } @Override public long getAddress() { - return address; + return objectInfo.getAddress(); } @Override public long getSize() { - return size; + return objectInfo.getSize(); } }