From d78fb470bc4a2cd7caccb0a274bd4b491db62a59 Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Tue, 13 Feb 2024 08:21:56 +0100 Subject: [PATCH] Cleanups. --- .../WindowsSystemPropertiesSupport.java | 2 +- .../oracle/svm/core/VMInspectionOptions.java | 8 ++--- .../core/c/function/IsolateSupportImpl.java | 2 +- .../svm/core/memory/NullableNativeMemory.java | 30 +++++++++---------- .../com/oracle/svm/core/nmt/NmtCategory.java | 4 +-- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java index 5795754098c..10a35b294b3 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java @@ -246,7 +246,7 @@ public Pair getOsNameAndVersion() { break; } - VoidPointer versionInfo = NullableNativeMemory.malloc(WordFactory.unsigned(versionSize), NmtCategory.Other); + VoidPointer versionInfo = NullableNativeMemory.malloc(WordFactory.unsigned(versionSize), NmtCategory.Internal); if (versionInfo.isNull()) { break; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java index e5b7ad611a7..55c96fa1234 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java @@ -33,7 +33,6 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platform.WINDOWS; import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.heap.dump.HeapDumping; import com.oracle.svm.core.jdk.management.ManagementAgentModule; @@ -81,8 +80,7 @@ public final class VMInspectionOptions { @Option(help = "Dumps all runtime compiled methods on SIGUSR2.", type = OptionType.User) // public static final HostedOptionKey DumpRuntimeCompilationOnSignal = new HostedOptionKey<>(false); - // TEMP (chaeubl): change default to true. - @Option(help = "Print native memory tracking statistics on shutdown.", type = OptionType.User) // + @Option(help = "Print native memory tracking statistics on shutdown if native memory tracking is enabled.", type = OptionType.User) // public static final RuntimeOptionKey PrintNMTStatistics = new RuntimeOptionKey<>(false); @Platforms(Platform.HOSTED_ONLY.class) @@ -176,9 +174,7 @@ public static boolean hasThreadDumpSupport() { @Fold public static boolean hasNativeMemoryTrackingSupport() { - // TEMP (chaeubl): for testing in the CI. - return Platform.includedIn(InternalPlatform.NATIVE_ONLY.class); - // return hasAllOrKeywordMonitoringSupport(MONITORING_NMT_NAME); + return hasAllOrKeywordMonitoringSupport(MONITORING_NMT_NAME); } static class DeprecatedOptions { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/IsolateSupportImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/IsolateSupportImpl.java index 4571f63a383..a64bc2ac410 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/IsolateSupportImpl.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/IsolateSupportImpl.java @@ -90,7 +90,7 @@ public static IsolateThread createIsolate(CreateIsolateParameters parameters, bo // Internally, we use C-style arguments, i.e., the first argument is reserved for // the name of the binary. We use null when isolates are created manually. argc = isolateArgCount + 1; - argv = NativeMemory.malloc(SizeOf.unsigned(CCharPointerPointer.class).multiply(argc), NmtCategory.Other); + argv = NativeMemory.malloc(SizeOf.unsigned(CCharPointerPointer.class).multiply(argc), NmtCategory.Internal); argv.write(0, WordFactory.nullPointer()); pointerHolders = new CTypeConversion.CCharPointerHolder[isolateArgCount]; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/memory/NullableNativeMemory.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/memory/NullableNativeMemory.java index 864a2d933e7..73660292850 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/memory/NullableNativeMemory.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/memory/NullableNativeMemory.java @@ -53,9 +53,9 @@ public class NullableNativeMemory { * This method returns a null pointer when allocation fails. */ @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public static T malloc(UnsignedWord size, NmtCategory flag) { + public static T malloc(UnsignedWord size, NmtCategory category) { T outerPointer = UntrackedNullableNativeMemory.malloc(getAllocationSize(size)); - return track(outerPointer, size, flag); + return track(outerPointer, size, category); } /** @@ -64,9 +64,9 @@ public static T malloc(UnsignedWord size, NmtCategory fl * This method returns a null pointer when allocation fails. */ @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public static T malloc(int size, NmtCategory flag) { + public static T malloc(int size, NmtCategory category) { assert size >= 0; - return malloc(WordFactory.unsigned(size), flag); + return malloc(WordFactory.unsigned(size), category); } /** @@ -75,9 +75,9 @@ public static T malloc(int size, NmtCategory flag) { * This method returns a null pointer when allocation fails. */ @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public static T calloc(UnsignedWord size, NmtCategory flag) { + public static T calloc(UnsignedWord size, NmtCategory category) { T outerPointer = UntrackedNullableNativeMemory.calloc(getAllocationSize(size)); - return track(outerPointer, size, flag); + return track(outerPointer, size, category); } /** @@ -86,9 +86,9 @@ public static T calloc(UnsignedWord size, NmtCategory fl * This method returns a null pointer when allocation fails. */ @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public static T calloc(int size, NmtCategory flag) { + public static T calloc(int size, NmtCategory category) { assert size >= 0; - return calloc(WordFactory.unsigned(size), flag); + return calloc(WordFactory.unsigned(size), category); } /** @@ -100,9 +100,9 @@ public static T calloc(int size, NmtCategory flag) { */ @SuppressWarnings("unchecked") @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public static T realloc(T ptr, UnsignedWord size, NmtCategory flag) { + public static T realloc(T ptr, UnsignedWord size, NmtCategory category) { if (ptr.isNull()) { - return malloc(size, flag); + return malloc(size, category); } else if (!VMInspectionOptions.hasNativeMemoryTrackingSupport()) { return UntrackedNullableNativeMemory.realloc(ptr, getAllocationSize(size)); } @@ -123,7 +123,7 @@ public static T realloc(T ptr, UnsignedWord size, NmtCat /* Only untrack the old block if the allocation was successful. */ NativeMemoryTracking.singleton().untrack(oldSize, oldCategory); - return track(newOuterPointer, size, flag); + return track(newOuterPointer, size, category); } /** @@ -134,9 +134,9 @@ public static T realloc(T ptr, UnsignedWord size, NmtCat * deallocated and remains unchanged. */ @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public static T realloc(T ptr, int size, NmtCategory flag) { + public static T realloc(T ptr, int size, NmtCategory category) { assert size >= 0; - return realloc(ptr, WordFactory.unsigned(size), flag); + return realloc(ptr, WordFactory.unsigned(size), category); } /** @@ -167,9 +167,9 @@ private static UnsignedWord getAllocationSize(UnsignedWord size) { @SuppressWarnings("unchecked") @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - private static T track(T outerPtr, UnsignedWord size, NmtCategory flag) { + private static T track(T outerPtr, UnsignedWord size, NmtCategory category) { if (VMInspectionOptions.hasNativeMemoryTrackingSupport() && outerPtr.isNonNull()) { - return (T) NativeMemoryTracking.singleton().track(outerPtr, size, flag); + return (T) NativeMemoryTracking.singleton().track(outerPtr, size, category); } return outerPtr; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/nmt/NmtCategory.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/nmt/NmtCategory.java index 5cabf99520d..ff71cdfabae 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/nmt/NmtCategory.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/nmt/NmtCategory.java @@ -52,8 +52,8 @@ public enum NmtCategory { /** Memory allocated via Unsafe. */ Unsafe("Unsafe"), - /** Some other VM internal reason - avoid if possible, better to add a new category. */ - Other("Other"); + /** Some other, VM internal reason - avoid if possible, better to add a new category. */ + Internal("Internal"); private final String name;