Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhaeubl committed Feb 14, 2024
1 parent bdd3c69 commit d78fb47
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public Pair<String, String> getOsNameAndVersion() {
break;
}

VoidPointer versionInfo = NullableNativeMemory.malloc(WordFactory.unsigned(versionSize), NmtCategory.Other);
VoidPointer versionInfo = NullableNativeMemory.malloc(WordFactory.unsigned(versionSize), NmtCategory.Internal);
if (versionInfo.isNull()) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,8 +80,7 @@ public final class VMInspectionOptions {
@Option(help = "Dumps all runtime compiled methods on SIGUSR2.", type = OptionType.User) //
public static final HostedOptionKey<Boolean> 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<Boolean> PrintNMTStatistics = new RuntimeOptionKey<>(false);

@Platforms(Platform.HOSTED_ONLY.class)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends PointerBase> T malloc(UnsignedWord size, NmtCategory flag) {
public static <T extends PointerBase> T malloc(UnsignedWord size, NmtCategory category) {
T outerPointer = UntrackedNullableNativeMemory.malloc(getAllocationSize(size));
return track(outerPointer, size, flag);
return track(outerPointer, size, category);
}

/**
Expand All @@ -64,9 +64,9 @@ public static <T extends PointerBase> 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 extends PointerBase> T malloc(int size, NmtCategory flag) {
public static <T extends PointerBase> T malloc(int size, NmtCategory category) {
assert size >= 0;
return malloc(WordFactory.unsigned(size), flag);
return malloc(WordFactory.unsigned(size), category);
}

/**
Expand All @@ -75,9 +75,9 @@ public static <T extends PointerBase> 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 extends PointerBase> T calloc(UnsignedWord size, NmtCategory flag) {
public static <T extends PointerBase> T calloc(UnsignedWord size, NmtCategory category) {
T outerPointer = UntrackedNullableNativeMemory.calloc(getAllocationSize(size));
return track(outerPointer, size, flag);
return track(outerPointer, size, category);
}

/**
Expand All @@ -86,9 +86,9 @@ public static <T extends PointerBase> 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 extends PointerBase> T calloc(int size, NmtCategory flag) {
public static <T extends PointerBase> T calloc(int size, NmtCategory category) {
assert size >= 0;
return calloc(WordFactory.unsigned(size), flag);
return calloc(WordFactory.unsigned(size), category);
}

/**
Expand All @@ -100,9 +100,9 @@ public static <T extends PointerBase> T calloc(int size, NmtCategory flag) {
*/
@SuppressWarnings("unchecked")
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public static <T extends PointerBase> T realloc(T ptr, UnsignedWord size, NmtCategory flag) {
public static <T extends PointerBase> 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));
}
Expand All @@ -123,7 +123,7 @@ public static <T extends PointerBase> 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);
}

/**
Expand All @@ -134,9 +134,9 @@ public static <T extends PointerBase> T realloc(T ptr, UnsignedWord size, NmtCat
* deallocated and remains unchanged.
*/
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public static <T extends PointerBase> T realloc(T ptr, int size, NmtCategory flag) {
public static <T extends PointerBase> 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);
}

/**
Expand Down Expand Up @@ -167,9 +167,9 @@ private static UnsignedWord getAllocationSize(UnsignedWord size) {

@SuppressWarnings("unchecked")
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
private static <T extends PointerBase> T track(T outerPtr, UnsignedWord size, NmtCategory flag) {
private static <T extends PointerBase> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d78fb47

Please sign in to comment.