|
26 | 26 |
|
27 | 27 | import static com.oracle.svm.core.deopt.Deoptimizer.Options.LazyDeoptimization;
|
28 | 28 | import static com.oracle.svm.core.option.RuntimeOptionKey.RuntimeOptionKeyFlag.RelevantForCompilationIsolates;
|
| 29 | +import static com.oracle.svm.core.os.RawFileOperationSupport.FileAccessMode.WRITE; |
| 30 | +import static com.oracle.svm.core.os.RawFileOperationSupport.FileCreationMode.CREATE_OR_REPLACE; |
29 | 31 | import static com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer;
|
30 | 32 |
|
| 33 | +import com.oracle.svm.core.SubstrateOptions; |
| 34 | +import com.oracle.svm.core.log.Log; |
| 35 | +import com.oracle.svm.core.os.RawFileOperationSupport; |
31 | 36 | import org.graalvm.collections.EconomicMap;
|
32 | 37 | import org.graalvm.nativeimage.CurrentIsolate;
|
33 | 38 | import org.graalvm.nativeimage.IsolateThread;
|
34 | 39 | import org.graalvm.nativeimage.Platform;
|
35 | 40 | import org.graalvm.nativeimage.Platforms;
|
36 | 41 | import org.graalvm.nativeimage.c.function.CodePointer;
|
| 42 | +import org.graalvm.nativeimage.c.type.CCharPointer; |
37 | 43 | import org.graalvm.word.Pointer;
|
38 | 44 | import org.graalvm.word.UnsignedWord;
|
39 | 45 |
|
|
59 | 65 | import jdk.graal.compiler.options.OptionType;
|
60 | 66 | import jdk.graal.compiler.word.Word;
|
61 | 67 |
|
| 68 | +import java.text.SimpleDateFormat; |
| 69 | + |
62 | 70 | public class RuntimeCodeCache {
|
63 | 71 |
|
64 | 72 | public static class Options {
|
@@ -161,11 +169,45 @@ private static int binarySearch(NonmovableArray<UntetheredCodeInfo> a, int fromI
|
161 | 169 | return -(low + 1); // key not found.
|
162 | 170 | }
|
163 | 171 |
|
| 172 | + private static RawFileOperationSupport getFileSupport() { |
| 173 | + return RawFileOperationSupport.bigEndian(); |
| 174 | + } |
| 175 | + |
| 176 | + private static void dumpMethod(CodeInfo info) { |
| 177 | + String methodName = CodeInfoAccess.getName(info); |
| 178 | + int tier = CodeInfoAccess.getTier(info); |
| 179 | + String date = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date()); |
| 180 | + String tmpDirPath = getFileSupport().getTempDirectory(); |
| 181 | + String filePath = tmpDirPath + "/" + date + "_" + methodName + "_" + tier + ".bin"; |
| 182 | + |
| 183 | + RawFileOperationSupport.RawFileDescriptor fd = getFileSupport().create(filePath, CREATE_OR_REPLACE, WRITE); |
| 184 | + if (!getFileSupport().isValid(fd)) { |
| 185 | + Log.log().string("Failed to dump runtime compiled code: '").string(filePath).string("' could not be created.").newline(); |
| 186 | + return; |
| 187 | + } |
| 188 | + |
| 189 | + try { |
| 190 | + CCharPointer codeStart = (CCharPointer) CodeInfoAccess.getCodeStart(info); |
| 191 | + |
| 192 | + UnsignedWord codeSize = CodeInfoAccess.getCodeSize(info); |
| 193 | + if (!RawFileOperationSupport.bigEndian().write(fd, (Pointer) codeStart, codeSize)) { |
| 194 | + Log.log().string("Dumping method to ").string(filePath).string(" failed").newline(); |
| 195 | + } |
| 196 | + } finally { |
| 197 | + getFileSupport().close(fd); |
| 198 | + } |
| 199 | + } |
| 200 | + |
164 | 201 | public void addMethod(CodeInfo info) {
|
165 | 202 | assert VMOperation.isInProgressAtSafepoint() : "invalid state";
|
166 | 203 | InstalledCodeObserverSupport.activateObservers(RuntimeCodeInfoAccess.getCodeObserverHandles(info));
|
| 204 | + |
167 | 205 | addMethod0(info);
|
168 | 206 | RuntimeCodeInfoHistory.singleton().logAdd(info);
|
| 207 | + |
| 208 | + if (SubstrateOptions.hasDumpRuntimeCompiledMethodsSupport()) { |
| 209 | + dumpMethod(info); |
| 210 | + } |
169 | 211 | }
|
170 | 212 |
|
171 | 213 | @Uninterruptible(reason = "Modifying code tables that are used by the GC")
|
|
0 commit comments