From a94428246977a53b3c3ae01d90f8d864e6cad38d Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 25 Oct 2018 15:57:58 +0700 Subject: [PATCH] =?UTF-8?q?JVM=20Halt=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2=D1=83?= =?UTF-8?q?=D1=8E=D1=89=D0=B8=D0=B9=20=D0=BD=D0=B0=D1=82=D0=B8=D0=B2=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ru/gravit/launcher/AvanguardStarter.java | 15 ++++++++++++--- .../ru/gravit/launcher/hasher/DirWatcher.java | 11 ++++++++++- .../main/java/ru/gravit/utils/NativeJVMHalt.java | 14 ++++++++++++++ .../java/ru/gravit/utils/helper/JVMHelper.java | 1 + 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 libLauncher/src/main/java/ru/gravit/utils/NativeJVMHalt.java diff --git a/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java b/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java index 06081e55..d481b9ad 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java +++ b/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java @@ -9,6 +9,7 @@ import net.minecraftforge.fml.SafeExitJVM; import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.utils.NativeJVMHalt; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.JVMHelper; @@ -51,11 +52,19 @@ public void run() { static void safeHalt(int exitcode) { try { - SafeExitJVM.exit(exitcode); - } catch (Throwable e) - { SafeExitJVMLegacy.exit(exitcode); + } catch (Throwable ignored) + { + } + try { + SafeExitJVM.exit(exitcode); + } catch (Throwable ignored) + { + + } + NativeJVMHalt halt = new NativeJVMHalt(exitcode); + halt.halt(); } public static final String NAME = Launcher.getConfig().projectname; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java index 998e4460..10a386cd 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java @@ -19,6 +19,7 @@ import net.minecraftforge.fml.SafeExitJVM; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.hasher.HashedEntry.Type; +import ru.gravit.utils.NativeJVMHalt; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.JVMHelper.OS; @@ -72,8 +73,16 @@ private static void handleError(Throwable e) { SafeExitJVMLegacy.exit(-123); } catch (Throwable ignored) { - SafeExitJVM.exit(-123); + } + try { + SafeExitJVM.exit(-123); + } catch (Throwable ignored) + { + + } + NativeJVMHalt halt = new NativeJVMHalt(-123); + halt.halt(); } private static Deque toPath(Iterable path) { diff --git a/libLauncher/src/main/java/ru/gravit/utils/NativeJVMHalt.java b/libLauncher/src/main/java/ru/gravit/utils/NativeJVMHalt.java new file mode 100644 index 00000000..786861d4 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/utils/NativeJVMHalt.java @@ -0,0 +1,14 @@ +package ru.gravit.utils; + +import ru.gravit.utils.helper.LogHelper; + +public class NativeJVMHalt { + public NativeJVMHalt(int haltCode) { + this.haltCode = haltCode; + LogHelper.error("JVM exit code %d",haltCode); + halt(); + } + + public int haltCode; + public native void halt(); +} diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index 2165d916..cc5e6f37 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -118,6 +118,7 @@ public static URL[] getClassPathURL() { } public static void checkStackTrace(Class mainClass) { + LogHelper.debug("Testing stacktrace"); Exception e = new Exception("Testing stacktrace"); StackTraceElement[] list = e.getStackTrace(); if(!list[list.length - 1].getClassName().equals(mainClass.getName()))