From 74c164ec6259ab688017c59cf524a54d2a8a45e8 Mon Sep 17 00:00:00 2001 From: Timothy Wall Date: Wed, 19 Aug 2015 08:20:00 -0400 Subject: [PATCH] add testing workarounds for JVM thread handling bug on OSX --- test/com/sun/jna/CallbacksTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/com/sun/jna/CallbacksTest.java b/test/com/sun/jna/CallbacksTest.java index 62987d604a..bb918331f7 100644 --- a/test/com/sun/jna/CallbacksTest.java +++ b/test/com/sun/jna/CallbacksTest.java @@ -39,6 +39,12 @@ //@SuppressWarnings("unused") public class CallbacksTest extends TestCase implements Paths { + // On OSX, on Oracle JVM 1.8+, pthread cleanup thinks the native thread is + // not attached, and the JVM never unmaps the defunct native thread. In + // order to avoid this situation causing tests to time out, we need to + // explicitly detach the native thread after our Java code is done with it. + private static final boolean THREAD_DETACH_BUG = Platform.isMac(); + private static final String UNICODE = "[\u0444]"; private static final double DOUBLE_MAGIC = -118.625d; @@ -1111,6 +1117,9 @@ public void callback() { } ++called[0]; + if (THREAD_DETACH_BUG && called[0] == 2) { + Native.detach(true); + } } }; callThreadedCallback(cb, init, 2, 2000, called, 1); @@ -1151,6 +1160,9 @@ public String getName(Callback cb) { public void callback() { threads.add(Thread.currentThread()); ++called[0]; + if (THREAD_DETACH_BUG && called[0] == COUNT) { + Native.detach(true); + } } }; callThreadedCallback(cb, init, COUNT, 100, called);