summaryrefslogtreecommitdiff
path: root/stoc
diff options
context:
space:
mode:
authorPatrick Luby <plubius@neooffice.org>2023-10-14 21:13:26 -0400
committerAndras Timar <andras.timar@collabora.com>2023-10-19 11:27:02 +0200
commitf8e36903fe78a41f5cee952e9fd573a75eccf25f (patch)
tree13b77753c18fccb0cc5b6e64eedc2b4e12731b34 /stoc
parent8122d0d9a18187241f9c1a46b2197faed4d51d21 (diff)
tdf#101376 don't detach thread if it is the main thread on macOS
On macOS, many AWT classes do their work on the main thread deep in native methods in the java.awt.* classes. The problem is that Oracle's and OpenJDK's JVMs don't bracket their "perform on main thread" native calls with "attach/detach current thread" calls to the JVM. Change-Id: I0859dc9e20f34bd0b43bb321898507764fd530fb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157985 Tested-by: Jenkins Reviewed-by: Patrick Luby <plubius@neooffice.org> (cherry picked from commit a0eee8e56b91324470bb0e15c6b8009cfc411335) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157962
Diffstat (limited to 'stoc')
-rw-r--r--stoc/Library_javavm.mk6
-rw-r--r--stoc/source/javavm/javavm.cxx15
2 files changed, 21 insertions, 0 deletions
diff --git a/stoc/Library_javavm.mk b/stoc/Library_javavm.mk
index e096565769f9..adcb49691ce1 100644
--- a/stoc/Library_javavm.mk
+++ b/stoc/Library_javavm.mk
@@ -31,4 +31,10 @@ $(eval $(call gb_Library_add_exception_objects,javavm,\
stoc/source/javavm/jvmargs \
))
+ifeq ($(OS),MACOSX)
+$(eval $(call gb_Library_use_system_darwin_frameworks,javavm,\
+ CoreFoundation \
+))
+endif
+
# vim:set noet sw=4 ts=4:
diff --git a/stoc/source/javavm/javavm.cxx b/stoc/source/javavm/javavm.cxx
index 12bcc2c904b7..dc22107fbf84 100644
--- a/stoc/source/javavm/javavm.cxx
+++ b/stoc/source/javavm/javavm.cxx
@@ -79,6 +79,12 @@
#define TIMEZONE "MET"
#endif
+#ifdef MACOSX
+#include <premac.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <postmac.h>
+#endif
+
/* Within this implementation of the com.sun.star.java.JavaVirtualMachine
* service and com.sun.star.java.theJavaVirtualMachine singleton, the method
* com.sun.star.java.XJavaVM.getJavaVM relies on the following:
@@ -456,6 +462,15 @@ public:
explicit DetachCurrentThread(JavaVM * jvm): m_jvm(jvm) {}
~DetachCurrentThread() {
+#ifdef MACOSX
+ // tdf#101376 don't detach thread if it is the main thread on macOS
+ // On macOS, many AWT classes do their work on the main thread
+ // deep in native methods in the java.awt.* classes. The problem
+ // is that Oracle's and OpenJDK's JVMs don't bracket their
+ // "perform on main thread" native calls with "attach/detach
+ // current thread" calls to the JVM.
+ if (CFRunLoopGetCurrent() != CFRunLoopGetMain())
+#endif
if (m_jvm->DetachCurrentThread() != 0) {
OSL_ASSERT(false);
}