|
1 | 1 | /* |
2 | | - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
24 | 24 | */ |
25 | 25 | package com.oracle.svm.core; |
26 | 26 |
|
| 27 | +import java.io.File; |
27 | 28 | import java.lang.invoke.MethodHandle; |
28 | 29 | import java.lang.invoke.MethodHandles; |
29 | 30 | import java.lang.reflect.Method; |
|
45 | 46 | import org.graalvm.nativeimage.c.type.CCharPointerPointer; |
46 | 47 | import org.graalvm.nativeimage.c.type.CTypeConversion; |
47 | 48 | import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; |
| 49 | +import org.graalvm.nativeimage.impl.HeapDumpSupport; |
48 | 50 | import org.graalvm.word.Pointer; |
49 | 51 | import org.graalvm.word.UnsignedWord; |
50 | 52 | import org.graalvm.word.WordFactory; |
@@ -134,6 +136,18 @@ private static int runCore() { |
134 | 136 | */ |
135 | 137 | private static int runCore0() { |
136 | 138 | try { |
| 139 | + if (SubstrateOptions.DumpHeapAndExit.getValue()) { |
| 140 | + if (VMInspectionOptions.AllowVMInspection.getValue() && ImageSingletons.contains(HeapDumpSupport.class)) { |
| 141 | + String absoluteHeapDumpPath = new File(SubstrateOptions.Name.getValue() + ".hprof").getAbsolutePath(); |
| 142 | + VMRuntime.dumpHeap(absoluteHeapDumpPath, true); |
| 143 | + System.out.println("Heap dump created at '" + absoluteHeapDumpPath + "'."); |
| 144 | + return 0; |
| 145 | + } else { |
| 146 | + System.err.println("Unable to dump heap. Heap dumping is only supported for native images built with `-H:+AllowVMInspection` and GraalVM Enterprise Edition."); |
| 147 | + return 1; |
| 148 | + } |
| 149 | + } |
| 150 | + |
137 | 151 | if (SubstrateOptions.ParseRuntimeOptions.getValue()) { |
138 | 152 | /* |
139 | 153 | * When options are not parsed yet, it is also too early to run the startup hooks |
|
0 commit comments