Q regarding threading issues for SWT mode

steve.x.northover at oracle.com steve.x.northover at oracle.com
Tue Dec 13 09:56:50 PST 2011


Hi folks,

It's been a while since I have looked at this stuff.  First off, SWT is 
cocoa application.  There is a carbon port, but that port is no longer 
active.  Mike and I had the discussion about supporting carbon 
applications when I accidentally sent him an SWT carbon jar.  He 
indicated that he wanted to throw out the code that supported carbon for 
1.7 and I think that this is fine.

Here is the class that contains the SWT startup code: 
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/bundles/org.eclipse.swt/Eclipse%20SWT/cocoa/org/eclipse/swt/widgets/Display.java

It looks as if SWT uses objc_setClass to hammer the running 
NSApplication instance.

Steve

On 13/12/2011 8:28 AM, Anthony Petrov wrote:
> Hi Mike, Steve,
>
> There's a couple of issues ([1] and [2]) that arise when running Java 
> in the SWT-compatible mode (i.e. with the -XstartOnFirstThread 
> specified). I've got a couple of questions for you guys.
>
>
> 1. I would second to Mike's comment in [2] regarding mandating that 
> the SWT must already be running the event loop before trying to access 
> AWT. What bothers me though, is that these same applications work fine 
> with Apple JDK (according to user comments), but fail only when 
> running with OpenJDK. Is that only because of the 
> AWT_ASSERT_NOT_APPKIT_THREAD assertion at line 267 in awt.m at:
>
> http://hg.openjdk.java.net/macosx-port/macosx-port/jdk/file/13d69fd25daa/src/macosx/native/sun/awt/awt.m 
>
>
> which actually seems to be completely unnecessary there? Or might 
> there be any other reason?
>
>
> 2. If we've started the VM on the main thread, and let's suppose SWT 
> has already been initialized. Do I understand correctly that at line 
> 350 of the aforementioned file we'll see that the app is already 
> running? Or will we actually start a new Cocoa loop for the AWT? 
> There's a comment at line 335 that says SWT doesn't call 
> NSApplicationLoad(). The spec for NSApplicationLoad() states this 
> function initializes an instance of NSApplication. So do I understand 
> correctly that SWT itself does NOT actually create its own NSApp 
> instance? Is SWT a Carbon-only library? To rephrase my question: if 
> Cocoa code (AWT) is embedded within a Carbon app (SWT), would [NSApp 
> isRunning] return YES or NO after the Carbon app has already been 
> initialized and is running? My guess is that it would still return YES 
> even though there was not an explicit initialization of the Cocoa 
> event loop, but I'd like to double check this with those who have 
> expertise in Cocoa/Carbon/SWT.
>
> Thanks in advance for your answers!
>
> [1] http://java.net/jira/browse/MACOSX_PORT-719 (unable to launch 
> debug mode in eclipse)
> [2] http://java.net/jira/browse/MACOSX_PORT-720 (java.awt.Font causes 
> Cocoa AWT: Running on AppKit thread 0 when not expected)
>
> -- 
> best regards,
> Anthony


More information about the macosx-port-dev mailing list