|
20 | 20 | import java.util.Set; |
21 | 21 | import java.util.TreeSet; |
22 | 22 | import java.util.function.BiPredicate; |
| 23 | +import java.util.function.ToIntFunction; |
23 | 24 | import java.util.jar.JarEntry; |
24 | 25 | import java.util.jar.JarFile; |
25 | 26 | import java.util.jar.JarInputStream; |
@@ -827,10 +828,23 @@ private File execute(String name, List<TaskOrArg> jvmArgs, List<TaskOrArg> runAr |
827 | 828 | throw new IllegalStateException("Failed to find JDK for version " + java_version, e); |
828 | 829 | } |
829 | 830 |
|
830 | | - if (isDecompile) |
831 | | - jvm = Mavenizer.fillDecompileJvmArgs(jvm); |
| 831 | + ToIntFunction<String> logHandler = null; |
| 832 | + if (isDecompile) { |
| 833 | + jvm = Mavenizer.fillDecompileJvmArgs(jvm, true); |
| 834 | + logHandler = MCPTaskFactory::parseDecompileLog; |
| 835 | + } |
832 | 836 |
|
833 | | - var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, jvm, run, isDecompile ? MCPTaskFactory::parseDecompileLog : null); |
| 837 | + var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, jvm, run, logHandler); |
| 838 | + if (ret.exitCode == OUT_OF_MEMORY && isDecompile) { |
| 839 | + var newJvm = Mavenizer.fillDecompileJvmArgs(resolveArgs(cache, tasks, jvmArgs), false); |
| 840 | + if (!newJvm.equals(jvm)) { |
| 841 | + LOGGER.error("First decompile failed with OutOfMemory using JVM Args: " + jvm); |
| 842 | + LOGGER.error("Attempting again with: " + newJvm); |
| 843 | + ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, newJvm, run, logHandler); |
| 844 | + if (ret.exitCode == OUT_OF_MEMORY) |
| 845 | + LOGGER.error("Ran out of memory again, you can specify more manually using the --decompile-memory Mavenizer argument"); |
| 846 | + } |
| 847 | + } |
834 | 848 | if (ret.exitCode != 0) |
835 | 849 | throw new IllegalStateException("Failed to run MCP Step (exit code " + ret.exitCode + "), See log: " + log.getAbsolutePath()); |
836 | 850 |
|
@@ -892,6 +906,8 @@ private List<String> resolveArgs(HashStore cache, Map<Task, String> tasks, List< |
892 | 906 | private static int parseDecompileLog(String line) { |
893 | 907 | if (line.startsWith("java.lang.OutOfMemoryError:")) |
894 | 908 | return OUT_OF_MEMORY; |
| 909 | + if (line.startsWith("Exception in thread") && line.contains("java.lang.OutOfMemoryError")) |
| 910 | + return OUT_OF_MEMORY; |
895 | 911 | if (line.contains("ERROR:")) { |
896 | 912 | // String message = "Method " + mt.getName() + " " + mt.getDescriptor() + " in class " + cl.qualifiedName + " couldn't be written."; |
897 | 913 | // String message = "Method " + mt.getName() + " " + mt.getDescriptor() + " in class " + classWrapper.getClassStruct().qualifiedName + " couldn't be written."; |
|
0 commit comments