hg: macosx-port/macosx-port/jdk: Fix for MACOSX_PORT-456: DnDTextDropTest 0001 fails in JCK-runtime-7 interactive
Mike Swingler
swingler at apple.com
Tue Nov 15 09:53:03 PST 2011
On Nov 15, 2011, at 10:02 AM, Alexander Zuev wrote:
> On 11/15/11 6:47 PM, Mike Swingler wrote:
>>
>> On Nov 15, 2011, at 2:59 AM, alexander.zuev at oracle.com wrote:
>>
>>> Changeset: bd6849181039
>>> Author: kizune
>>> Date: 2011-11-15 14:58 +0300
>>> URL: http://hg.openjdk.java.net/macosx-port/macosx-port/jdk/rev/bd6849181039
>>>
>>> Fix for MACOSX_PORT-456: DnDTextDropTest 0001 fails in JCK-runtime-7 interactive
>>>
>>> ! src/macosx/native/sun/awt/CDropTarget.m
>>> ! src/macosx/native/sun/awt/CDropTargetContextPeer.m
>>>
>>
>> This seems problematic:
>> --- a/src/macosx/native/sun/awt/CDropTarget.m Mon Nov 14 21:09:29 2011 +0300
>> +++ b/src/macosx/native/sun/awt/CDropTarget.m Tue Nov 15 14:58:46 2011 +0300
>> @@ -320,7 +320,11 @@ extern JNFClassInfo jc_CDropTargetContex
>>
>> - (jobject) copyDraggingDataForFormat:(jlong)format
>> {
>> - JNIEnv* env = [ThreadUtilities getJNIEnv]; // Can be called from threads other than the native event thread!
>> + __block JNIEnv* env;
>> +
>> + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
>> + env = [ThreadUtilities getJNIEnv]; // Can be called from threads other than the native event thread!
>> + }];
>> NSData* data = nil;
>>
>> // Convert the Java format (datatransferer int index) to a pasteboard format (NSString):
>>
>> You can't use the AppKit/Thread-0 Env from another thread, or HotSpot can crash. You need to use an Env that is local to your thread, no matter what thread it gets called from, and if that means attaching the current thread, so be-it.
> So you saying that using AppKit's env is not thread-safe? Should we just execute the rest of the method on the AppKit thread synchronously by packing the rest of the code (well, minus the return part of course) into this block?
No, you should be able to use the +getJNIEnvUncached variant which unconditionally attaches the current thread, or you need to re-think how the callers are accessing this function. Since it's returning a jobject, perhaps you should redesign it to take an Env from it's caller.
Regards,
~Mike
More information about the macosx-port-dev
mailing list