From a3bee18d420222aa2a73d6f44e1d81b22c3765de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Mon, 11 Jan 2021 17:02:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-46819=20win7=E4=B8=8B=E5=8A=A0?= =?UTF-8?q?=E8=BD=BDj2v8dll=E4=B9=8B=E5=90=8E=E7=A8=8B=E5=BA=8F=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/eclipsesource/v8/LibraryLoader.java | 53 +++++++++++++++++++ .../main/java/com/eclipsesource/v8/V8.java | 1 + 2 files changed, 54 insertions(+) diff --git a/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java b/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java index c3ef4351f..369d6562f 100644 --- a/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java +++ b/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java @@ -15,6 +15,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.management.ManagementFactory; class LibraryLoader { @@ -23,6 +24,8 @@ class LibraryLoader { static final String SWT_LIB_DIR = ".j2v8"; + static final String MINIMUM_VERSION = "6.2"; + static { DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$ SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$ @@ -193,4 +196,54 @@ class LibraryLoader { } catch (Throwable e) { } } + + //内核版本windows NT6.2以下存在加载dll之后无法正常退出的问题,注册钩子函数退出时杀掉进程 + static void checkExceptionVersion() { + String version = System.getProperty("os.version"); + if (PlatformDetector.OS.isWindows() && belowMinimumVersion(version)) { + registerExit(); + } + } + + //低于指定版本,6.2以下 + private static boolean belowMinimumVersion(String version) { + int i = compareVersion(version, MINIMUM_VERSION); + if (i < 0) { + return true; + } else { + return false; + } + } + + private static int compareVersion(String version1, String version2) { + String[] versionArray1 = version1.split("\\.");//注意此处为正则匹配,不能用"."; + String[] versionArray2 = version2.split("\\."); + int idx = 0; + int minLength = Math.min(versionArray1.length, versionArray2.length);//取最小长度值 + int diff = 0; + while (idx < minLength + && (diff = versionArray1[idx].length() - versionArray2[idx].length()) == 0//先比较长度 + && (diff = versionArray1[idx].compareTo(versionArray2[idx])) == 0) {//再比较字符 + ++idx; + } + //如果已经分出大小,则直接返回,如果未分出大小,则再比较位数,有子版本的为大; + diff = (diff != 0) ? diff : versionArray1.length - versionArray2.length; + return diff; + } + + //低于指定版本,6.2以下 + private static void registerExit() { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + String name = ManagementFactory.getRuntimeMXBean().getName(); + String pid = name.split("@")[0]; + try { + Runtime.getRuntime().exec("taskkill /F /PID " + pid); + } catch (Exception ex) { + System.exit(0); + } + } + }); + } } diff --git a/fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java b/fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java index 511f522bf..bac35971a 100644 --- a/fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java +++ b/fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java @@ -76,6 +76,7 @@ public class V8 extends V8Object { try { LibraryLoader.loadLibrary(tmpDirectory); nativeLibraryLoaded = true; + LibraryLoader.checkExceptionVersion(); } catch (Error e) { nativeLoadError = e; } catch (Exception e) { From e9ac0239ef361db3f93c0f55c2f6dd27bb94353d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Mon, 11 Jan 2021 17:07:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/eclipsesource/v8/LibraryLoader.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java b/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java index 369d6562f..4903e3c8d 100644 --- a/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java +++ b/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java @@ -208,11 +208,7 @@ class LibraryLoader { //低于指定版本,6.2以下 private static boolean belowMinimumVersion(String version) { int i = compareVersion(version, MINIMUM_VERSION); - if (i < 0) { - return true; - } else { - return false; - } + return i < 0; } private static int compareVersion(String version1, String version2) { From 95273a6c6751b8cb97d59a3304928a6328bc2c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Mon, 11 Jan 2021 17:19:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/eclipsesource/v8/LibraryLoader.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java b/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java index 4903e3c8d..7c9adf68e 100644 --- a/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java +++ b/fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java @@ -207,8 +207,7 @@ class LibraryLoader { //低于指定版本,6.2以下 private static boolean belowMinimumVersion(String version) { - int i = compareVersion(version, MINIMUM_VERSION); - return i < 0; + return compareVersion(version, MINIMUM_VERSION) < 0; } private static int compareVersion(String version1, String version2) {