提交 c43477ee 编写于 作者: A anashaty

8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled

Reviewed-by: serb, bae
上级 f4327351
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* questions. * questions.
*/ */
#import <Cocoa/Cocoa.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h> #import <JavaNativeFoundation/JavaNativeFoundation.h>
#import "sun_lwawt_macosx_CFRetainedResource.h" #import "sun_lwawt_macosx_CFRetainedResource.h"
...@@ -37,7 +38,10 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CFRetainedResource_nativeCFRelease ...@@ -37,7 +38,10 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CFRetainedResource_nativeCFRelease
(JNIEnv *env, jclass clazz, jlong ptr, jboolean releaseOnAppKitThread) (JNIEnv *env, jclass clazz, jlong ptr, jboolean releaseOnAppKitThread)
{ {
if (releaseOnAppKitThread) { if (releaseOnAppKitThread) {
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ // Releasing resources on the main AppKit message loop only
// Releasing resources on the nested loops may cause dangling
// pointers after the nested loop is exited
[NSApp postRunnableEvent:^(){
CFRelease(jlong_to_ptr(ptr)); CFRelease(jlong_to_ptr(ptr));
}]; }];
} else { } else {
......
...@@ -339,8 +339,10 @@ JNF_COCOA_ENTER(env); ...@@ -339,8 +339,10 @@ JNF_COCOA_ENTER(env);
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.010]]; beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.010]];
if (processEvents) { if (processEvents) {
//We do not spin a runloop here as date is nil, so does not matter which mode to use //We do not spin a runloop here as date is nil, so does not matter which mode to use
// Processing all events excluding NSApplicationDefined which need to be processed
// on the main loop only (those events are intended for disposing resources)
NSEvent *event; NSEvent *event;
if ((event = [NSApp nextEventMatchingMask:NSAnyEventMask if ((event = [NSApp nextEventMatchingMask:(NSAnyEventMask & ~NSApplicationDefined)
untilDate:nil untilDate:nil
inMode:NSDefaultRunLoopMode inMode:NSDefaultRunLoopMode
dequeue:YES]) != nil) { dequeue:YES]) != nil) {
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
- (void) registerWithProcessManager; - (void) registerWithProcessManager;
- (void) setDockIconWithEnv:(JNIEnv *)env; - (void) setDockIconWithEnv:(JNIEnv *)env;
- (void) postDummyEvent; - (void) postDummyEvent;
- (void) postRunnableEvent:(void (^)())block;
- (void) waitForDummyEvent; - (void) waitForDummyEvent;
+ (void) runAWTLoopWithApp:(NSApplication*)app; + (void) runAWTLoopWithApp:(NSApplication*)app;
......
...@@ -338,9 +338,13 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -338,9 +338,13 @@ AWT_ASSERT_APPKIT_THREAD;
- (void)sendEvent:(NSEvent *)event - (void)sendEvent:(NSEvent *)event
{ {
if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) { if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp) && [event subtype] == 0) {
[seenDummyEventLock lockWhenCondition:NO]; [seenDummyEventLock lockWhenCondition:NO];
[seenDummyEventLock unlockWithCondition:YES]; [seenDummyEventLock unlockWithCondition:YES];
} else if ([event type] == NSApplicationDefined && [event subtype] == 777) {
void (^block)() = (void (^)()) [event data1];
block();
[block release];
} else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) { } else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) {
// Cocoa won't send us key up event when releasing a key while Cmd is down, // Cocoa won't send us key up event when releasing a key while Cmd is down,
// so we have to do it ourselves. // so we have to do it ourselves.
...@@ -350,6 +354,33 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -350,6 +354,33 @@ AWT_ASSERT_APPKIT_THREAD;
} }
} }
/*
* Posts the block to the AppKit event queue which will be executed
* on the main AppKit loop.
* While running nested loops this event will be ignored.
*/
- (void)postRunnableEvent:(void (^)())block
{
void (^copy)() = [block copy];
NSInteger encode = (NSInteger) copy;
[copy retain];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
location: NSMakePoint(0,0)
modifierFlags: 0
timestamp: 0
windowNumber: 0
context: nil
subtype: 777
data1: encode
data2: 0];
[NSApp postEvent: event atStart: NO];
[pool drain];
}
- (void)postDummyEvent { - (void)postDummyEvent {
seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO]; seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime; dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
......
...@@ -2905,13 +2905,13 @@ search: ...@@ -2905,13 +2905,13 @@ search:
return comp; return comp;
} }
if (flavor1.isFlavorTextType()) { // if (flavor1.isFlavorTextType()) {
return 1; // return 1;
} // }
//
if (flavor2.isFlavorTextType()) { // if (flavor2.isFlavorTextType()) {
return -1; // return -1;
} // }
// Next, look for application/x-java-* types. Prefer unknown // Next, look for application/x-java-* types. Prefer unknown
// MIME types because if the user provides his own data flavor, // MIME types because if the user provides his own data flavor,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册