Q regarding threading issues for SWT mode

Anthony Petrov anthony.petrov at oracle.com
Tue Dec 13 05:28:02 PST 2011


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