Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.Map;
import java.util.function.Supplier;

import jdk.graal.compiler.options.OptionValues;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.MapCursor;
Expand All @@ -49,13 +48,14 @@
import org.graalvm.nativeimage.RuntimeOptions;
import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.VMRuntime;
import org.graalvm.nativeimage.libgraal.hosted.LibGraalLoader;
import org.graalvm.nativeimage.libgraal.LibGraalRuntime;
import org.graalvm.nativeimage.libgraal.hosted.GlobalData;
import org.graalvm.nativeimage.libgraal.hosted.LibGraalLoader;

import jdk.graal.compiler.core.common.LibGraalSupport;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.libgraal.truffle.HSTruffleCompilerRuntime;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.graal.compiler.word.Word;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
Expand Down Expand Up @@ -162,7 +162,7 @@ public void processReferences() {
}

@Override
public void dumpHeap(String outputFile, boolean live) throws IOException {
public void dumpHeap(String outputFile, boolean live) throws IOException, UnsupportedOperationException {
VMRuntime.dumpHeap(outputFile, live);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static <T extends CompilationResult> void checkForHeapDump(Request<T> re
try {
final String path = debug.getDumpPath(".compilation.hprof", false);
GraalServices.dumpHeap(path, false);
} catch (IOException e) {
} catch (IOException | UnsupportedOperationException e) {
e.printStackTrace(System.out);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@
import java.util.Optional;
import java.util.regex.Pattern;

import jdk.graal.compiler.core.GraalCompilerOptions;
import jdk.graal.compiler.debug.GraphFilter;
import jdk.graal.compiler.serviceprovider.GraalServices;
import org.graalvm.collections.EconomicMap;

import jdk.graal.compiler.core.GraalCompilerOptions;
import jdk.graal.compiler.core.common.util.CompilationAlarm;
import jdk.graal.compiler.debug.CounterKey;
import jdk.graal.compiler.debug.DebugCloseable;
import jdk.graal.compiler.debug.DebugContext;
import jdk.graal.compiler.debug.DebugContext.CompilerPhaseScope;
import jdk.graal.compiler.debug.DebugOptions;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.debug.GraphFilter;
import jdk.graal.compiler.debug.MemUseTrackerKey;
import jdk.graal.compiler.debug.TTY;
import jdk.graal.compiler.debug.TimerKey;
Expand All @@ -65,6 +64,7 @@
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.phases.contract.NodeCostUtil;
import jdk.graal.compiler.phases.contract.PhaseSizeContract;
import jdk.graal.compiler.serviceprovider.GraalServices;
import jdk.vm.ci.meta.SpeculationLog;

/**
Expand Down Expand Up @@ -506,7 +506,7 @@ public final void apply(final StructuredGraph graph, final C context, final bool
try {
final String path = debug.getDumpPath("_" + getName() + ".hprof", false);
GraalServices.dumpHeap(path, false);
} catch (IOException e) {
} catch (IOException | UnsupportedOperationException e) {
e.printStackTrace(System.out);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@
import jdk.graal.compiler.core.ArchitectureSpecific;
import jdk.graal.compiler.core.common.LibGraalSupport;
import jdk.graal.compiler.core.common.NativeImageSupport;
import jdk.vm.ci.code.Architecture;

import jdk.graal.compiler.debug.GraalError;
import jdk.internal.misc.VM;
import jdk.vm.ci.code.Architecture;
import jdk.vm.ci.meta.EncodedSpeculationReason;
import jdk.vm.ci.meta.SpeculationLog.SpeculationReason;
import jdk.vm.ci.runtime.JVMCI;
Expand Down Expand Up @@ -498,7 +497,7 @@ public static List<String> getInputArguments() {
* @throws IOException if an IO error occurred dyring dumping
* @throws UnsupportedOperationException if this operation is not supported.
*/
public static void dumpHeap(String outputFile, boolean live) throws IOException {
public static void dumpHeap(String outputFile, boolean live) throws IOException, UnsupportedOperationException {
LibGraalSupport libgraal = LibGraalSupport.INSTANCE;
if (libgraal != null) {
libgraal.dumpHeap(outputFile, live);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -86,9 +86,6 @@ public static void shutdown() {
* @since 20.1
*/
public static void dumpHeap(String outputFile, boolean live) throws IOException {
if (!ImageSingletons.contains(HeapDumpSupport.class)) {
throw new UnsupportedOperationException();
}
ImageSingletons.lookup(HeapDumpSupport.class).dumpHeap(outputFile, live);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public final class VMInspectionOptions {
", '" + MONITORING_JCMD_NAME + "' (experimental)" +
", or '" + MONITORING_ALL_NAME + "' (deprecated behavior: defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)";

static {
assert MONITORING_ALL_VALUES.stream().allMatch(v -> MONITORING_DEFAULT_NAME.equals(v) || MONITORING_ALLOWED_VALUES_TEXT.contains(v)) : "A value is missing in the user-facing help text";
}

@APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_DEFAULT_NAME) //
@Option(help = "Enable monitoring features that allow the VM to be inspected at run time. Comma-separated list can contain " + MONITORING_ALLOWED_VALUES_TEXT + ". " +
"For example: '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_HEAPDUMP_NAME + "," + MONITORING_JFR_NAME + "'.", type = OptionType.User) //
Expand All @@ -92,6 +88,10 @@ 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, VMInspectionOptions::notSupportedOnWindows);

static {
assert MONITORING_ALL_VALUES.stream().allMatch(v -> MONITORING_DEFAULT_NAME.equals(v) || MONITORING_ALLOWED_VALUES_TEXT.contains(v)) : "A value is missing in the user-facing help text";
}

@Platforms(Platform.HOSTED_ONLY.class)
private static void notSupportedOnWindows(HostedOptionKey<Boolean> optionKey) {
if (Platform.includedIn(WINDOWS.class) && optionKey.getValue()) {
Expand Down Expand Up @@ -136,8 +136,9 @@ private static String getDefaultMonitoringCommandArgument() {
}

@Fold
public static String getHeapDumpCommandArgument() {
return SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, MONITORING_HEAPDUMP_NAME);
public static String getHeapDumpNotSupportedMessage() {
return "Unable to dump heap. Heap dumping is only supported on Linux and MacOS for native binaries built with '" +
SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, MONITORING_HEAPDUMP_NAME) + "'.";
}

private static Set<String> getEnabledMonitoringFeatures() {
Expand Down Expand Up @@ -167,8 +168,7 @@ public static boolean dumpImageHeap() {
System.out.println("Heap dump created at '" + absoluteHeapDumpPath + "'.");
return true;
} else {
System.out.println("Unable to dump heap. Heap dumping is only supported on Linux and MacOS for native executables built with '" +
VMInspectionOptions.getHeapDumpCommandArgument() + "'.");
System.out.println(VMInspectionOptions.getHeapDumpNotSupportedMessage());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.io.IOException;

import jdk.graal.compiler.word.Word;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.StackValue;
Expand All @@ -39,6 +38,7 @@
import org.graalvm.word.Pointer;

import com.oracle.svm.core.UnmanagedMemoryUtil;
import com.oracle.svm.core.VMInspectionOptions;
import com.oracle.svm.core.heap.GCCause;
import com.oracle.svm.core.heap.Heap;
import com.oracle.svm.core.heap.RestrictHeapAccess;
Expand All @@ -55,6 +55,7 @@
import com.oracle.svm.core.util.TimeUtils;

import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.word.Word;

public class HeapDumpSupportImpl extends HeapDumping {
private final HeapDumpWriter writer;
Expand Down Expand Up @@ -133,6 +134,10 @@ private void dumpHeapOnOutOfMemoryError0() {

@Override
public void dumpHeap(String filename, boolean gcBefore, boolean overwrite) throws IOException {
if (!RawFileOperationSupport.isPresent()) {
throw new UnsupportedOperationException(VMInspectionOptions.getHeapDumpNotSupportedMessage());
}

FileCreationMode creationMode = overwrite ? FileCreationMode.CREATE_OR_REPLACE : FileCreationMode.CREATE;
RawFileDescriptor fd = getFileSupport().create(filename, creationMode, RawFileOperationSupport.FileAccessMode.READ_WRITE);
if (!getFileSupport().isValid(fd)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.oracle.svm.core.Isolates;
import jdk.graal.compiler.graph.Edges;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.Equivalence;
Expand All @@ -44,7 +42,9 @@
import org.graalvm.nativeimage.VMRuntime;
import org.graalvm.nativeimage.hosted.FieldValueTransformer;

import com.oracle.svm.core.Isolates;
import com.oracle.svm.core.SubstrateTargetDescription;
import com.oracle.svm.core.VMInspectionOptions;
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Inject;
import com.oracle.svm.core.annotate.InjectAccessors;
Expand Down Expand Up @@ -74,6 +74,7 @@
import jdk.graal.compiler.debug.MetricKey;
import jdk.graal.compiler.debug.TTY;
import jdk.graal.compiler.debug.TimeSource;
import jdk.graal.compiler.graph.Edges;
import jdk.graal.compiler.graph.Node;
import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool;
import jdk.graal.compiler.lir.phases.LIRPhase;
Expand Down Expand Up @@ -232,7 +233,10 @@ final class Target_jdk_graal_compiler_serviceprovider_GraalServices {
* {@code jdk.graal.compiler.management.JMXServiceProvider}.
*/
@Substitute
public static void dumpHeap(String outputFile, boolean live) throws IOException {
public static void dumpHeap(String outputFile, boolean live) throws IOException, UnsupportedOperationException {
if (!VMInspectionOptions.hasHeapDumpSupport()) {
throw new UnsupportedOperationException(VMInspectionOptions.getHeapDumpNotSupportedMessage());
}
VMRuntime.dumpHeap(outputFile, live);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.MapCursor;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.impl.HeapDumpSupport;

Expand Down Expand Up @@ -69,18 +68,18 @@ public class HeapDumpFeature implements InternalFeature {
@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
/*
* Include the feature unconditionally (all platforms except Windows - even unknown
* platforms). The code and all its data are only present in the final image if the heap
* dumping infrastructure is actually called by any code (e.g., VMRuntime.dumpHeap(...) or
* --enable-monitoring=heapdump).
* Include the feature unconditionally (all platforms, even unknown platforms). The static
* analysis ensures that the code and all its data are only present in the final image if
* the heap dumping infrastructure is actually called by any code (e.g.,
* VMRuntime.dumpHeap(...) or --enable-monitoring=heapdump).
*/
return !Platform.includedIn(Platform.WINDOWS.class);
return true;
}

@Override
public void duringSetup(DuringSetupAccess access) {
HeapDumpMetadata metadata = new HeapDumpMetadata();
HeapDumping heapDumpSupport = new HeapDumpSupportImpl(metadata);
HeapDumpSupportImpl heapDumpSupport = new HeapDumpSupportImpl(metadata);

ImageSingletons.add(HeapDumpSupport.class, heapDumpSupport);
ImageSingletons.add(HeapDumping.class, heapDumpSupport);
Expand Down
Loading