Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimeon Andreev2020-12-21 11:52:01 +0000
committerAndrey Loskutov2020-12-21 20:16:39 +0000
commit2684843e3d22bb177a6c6b21c3ee75f3bb3d250e (patch)
tree3c2afa3b274341a484e36e9ebe3ddc9bacfbce9c
parent0b7e18c5e7569dce72e5e570ed9f678e5b66e26c (diff)
downloadeclipse.platform.swt-2684843e3d22bb177a6c6b21c3ee75f3bb3d250e.tar.gz
eclipse.platform.swt-2684843e3d22bb177a6c6b21c3ee75f3bb3d250e.tar.xz
eclipse.platform.swt-2684843e3d22bb177a6c6b21c3ee75f3bb3d250e.zip
Bug 569853 - jstack crashes Eclipse when running on Java 11
1) Always call DetachCurrentThread if AttachCurrentThreadAsDaemon was called before, see https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#detaching_from_the_vm. 2) Specify JNI 1.4 version in JNI_OnLoad, see https://docs.oracle.com/en/java/javase/11/docs/specs/jni/invocation.html#jni_onload 3) Added printf around attach/detach for easier debugging. 4) Fixed build.sh to allow c99 standard for the for loop defined in DEBUG_CALL_PRINTS and resolve compilation error below if DEBUG_CALL_PRINTS is enabled: callback.c:1252:3: error: 'for' loop initial declarations are only allowed in C99 mode Main change is 1), it is a workaround for jstack / JVM bug described in https://bugzilla.redhat.com/show_bug.cgi?id=1897150 Change-Id: I3ba32d9bef217e5ffc76b8802e7e59de503a2161
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c28
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h1
4 files changed, 13 insertions, 24 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
index 0490465334..61f01449a3 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
@@ -116,7 +116,7 @@ esac
case $SWT_OS.$SWT_ARCH in
"linux.x86_64")
if [ "${CC}" = "" ]; then
- export CC=gcc
+ export CC="gcc -std=c99"
fi
if [ "${JAVA_HOME}" = "" ]; then
# Cross-platform method of finding JAVA_HOME.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c b/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
index 1e37e28810..0bd7b87a77 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
@@ -1298,24 +1298,15 @@ jlong callback(int index, ...)
}
#endif
-#ifdef JNI_VERSION_1_2
- if (IS_JNI_1_2) {
- (*JVM)->GetEnv(JVM, (void **)&env, JNI_VERSION_1_2);
- }
-#endif
-
-#ifdef JNI_VERSION_1_4
- if (env == NULL) {
- if (JNI_VERSION >= JNI_VERSION_1_4) {
- (*JVM)->AttachCurrentThreadAsDaemon(JVM, (void **)&env, NULL);
- }
- }
+(*JVM)->GetEnv(JVM, (void **)&env, JNI_VERSION_1_4);
+
+if (env == NULL) {
+ (*JVM)->AttachCurrentThreadAsDaemon(JVM, (void **)&env, NULL);
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "SWT-JNI: AttachCurrentThreadAsDaemon\n");
#endif
-
- if (env == NULL) {
- (*JVM)->AttachCurrentThread(JVM, (void **)&env, NULL);
- if (IS_JNI_1_2) detach = 1;
- }
+ detach = 1;
+}
/* If the current thread is not attached to the VM, it is not possible to call into the VM */
if (env == NULL) {
@@ -1391,6 +1382,9 @@ done:
if (detach) {
(*JVM)->DetachCurrentThread(JVM);
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "SWT-JNI: DetachCurrentThread\n");
+#endif
env = NULL;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c
index e78a2e4811..483aae2d47 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c
@@ -14,16 +14,12 @@
#include "swt.h"
-int IS_JNI_1_2 = 0;
JavaVM *JVM = NULL;
-#ifdef JNI_VERSION_1_2
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
- IS_JNI_1_2 = 1;
JVM = vm;
- return JNI_VERSION_1_2;
+ return JNI_VERSION_1_4;
}
-#endif
void throwOutOfMemory(JNIEnv *env) {
jclass clazz = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
index fa228e9971..32f39f01bd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
@@ -29,7 +29,6 @@
extern "C" {
#endif
-extern int IS_JNI_1_2;
extern JavaVM *JVM;
/* #define DEBUG */

Back to the top