7171163: [macosx] Shortcomings in the design of the secondary native event loop made JavaFX DnD deadlock
Reviewed-by: anthony, art
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java Wed Jun 13 18:43:07 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java Fri Jun 15 18:28:33 2012 +0400
@@ -41,10 +41,11 @@
}
public void enter() {
- toolkit.startNativeNestedEventLoop();
+ // Execute the next AppKit event while we are waiting for system to
+ // finish our request - this will save us from biting our own tail
+ toolkit.executeNextAppKitEvent();
}
public void exit() {
- toolkit.stopNativeNestedEventLoop();
}
}
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Wed Jun 13 18:43:07 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Fri Jun 15 18:28:33 2012 +0400
@@ -63,9 +63,7 @@
private static native void initIDs();
- static native void startNativeNestedEventLoop();
-
- static native void stopNativeNestedEventLoop();
+ static native void executeNextAppKitEvent();
private static CInputMethodDescriptor sInputMethodDescriptor;
--- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m Wed Jun 13 18:43:07 2012 +0400
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m Fri Jun 15 18:28:33 2012 +0400
@@ -42,7 +42,6 @@
@implementation AWTToolkit
static long eventCount;
-static bool shouldKeepRunningNestedLoop = NO;
+ (long) getEventCount{
return eventCount;
@@ -460,33 +459,18 @@
/*
* Class: sun_lwawt_macosx_LWCToolkit
- * Method: startNativeNestedEventLoop
+ * Method: executeNextAppKitEvent
* Signature: ()V
*/
-JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeNestedEventLoop
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_executeNextAppKitEvent
(JNIEnv *env, jclass cls)
{
- if(!shouldKeepRunningNestedLoop) {
- NSRunLoop *theRL = [NSRunLoop currentRunLoop];
- NSApplication * app = [NSApplication sharedApplication];
- shouldKeepRunningNestedLoop = YES;
- while (shouldKeepRunningNestedLoop && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
- {
- NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
- if (event != nil) {
- [app sendEvent: event];
- }
- }
+ // Simply get the next event in native loop and pass it to execution
+ // We'll be called repeatedly so there's no need to block here
+ NSRunLoop *theRL = [NSRunLoop currentRunLoop];
+ NSApplication * app = [NSApplication sharedApplication];
+ NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
+ if (event != nil) {
+ [app sendEvent: event];
}
}
-
-/*
- * Class: sun_lwawt_macosx_LWCToolkit
- * Method: stopNativeNestedEventLoop
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop
-(JNIEnv *env, jclass cls)
-{
- shouldKeepRunningNestedLoop = NO;
-}
--- a/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java Wed Jun 13 18:43:07 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java Fri Jun 15 18:28:33 2012 +0400
@@ -498,7 +498,7 @@
postDropTargetEvent(component, x, y, dropAction, actions,
formats, nativeCtxt,
SunDropTargetEvent.MOUSE_DROPPED,
- !SunDropTargetContextPeer.DISPATCH_SYNC);
+ SunDropTargetContextPeer.DISPATCH_SYNC);
}
/**