Thread launching quirks on Apple Java

If you run this as an applet on Apple Java, you might be surprised.


System.out.println("A");

new Thread(){public void run(){ System.out.println("1"); }}.start();

System.out.println("B");

Runnable r = new Runnable(){public void run(){ System.out.println("2"); }};
int stackSize = 32*1024;
new Thread(null, r, "name", stackSize).start();

System.out.println("C");


For me it prints A, B, C and 1… ::slight_smile:

So “2” is never printed. Have you tried any of the other Thread constructors?

Well, they all redirect to / call the most explicit constructor.

So for all constructors, eventually the same path is taken, only the arguments are different.

I think the problem is that the stackSize is very small. The Javadoc says the behaviour on explicitly setting this value is very VM implementation dependant, but not executing the Thread at all is not really following the intention of the spec, eh.

Well that’s no good… I don’t like to use threads because they get so complicated.

You could be using synchronized!

Could anybody with a Mac please test the above code, just to be sure I don’t have either corrupt software or hardware.

Tested on Core 2 Duo Macbook, Mac OS X 10.5.5, Java 6:

A
B
1
C
Invalid memory access of location fffffff8 rip=010f374c

What the … ?!

Thank you VERY much for confirming!

This is a serious bug!


A
B
1
C

Program exited with status 0.

Whoops.

(Edit: oops, these results are from running this snippet as an application, not an applet; I should have read Riven’s first post more carefully, I’ll try running as an applet later)

Using the various Apple JVMs:
1.5:


A
B
1
C

1.6 beta:


A
B
1
C
Invalid memory access of location fffffff8 rip=010a19e6
#
# An unexpected Java error has been detected by HotSpot Virtual Machine.
#
# If this error is reproducible, please report it with the following information: 
#   1. Provide the steps to reproduce, a test case, and any relevant information 
#   2. The corresponding JavaNativeCrash_pid<num>.crash.log (Java state) 
#   3. The corresponding <name>.crash.log (native state; generated by CrashReporter) 
#   4. This data: 
#
# Java VM: Java HotSpot(TM) 64-Bit Server VM (1.6.0_04-b12-45-optimized mixed mode)
# An unexpected error has been detected by Java Runtime Environment:
#
#  Bus Error (0xa) at pc=0x00000001010a19e6#
#  Bus Error (0xa) at pc=0x00000001010a19e6, pid=16027, tid=4300226560
#
# Java VM: Java HotSpot(TM) 64-Bit Server VM (1.6.0_04-b12-45-optimized mixed mode macosx-amd64)
# An error report file with more information is saved as:
# /Users/eric/Library/Logs/Java/JavaNativeCrash_pid16027.crash.log
#
#
# File report at: http://bugreport.apple.com/
#

And, for good measure, I tried with 1.4 as well:


A
B
C
1
2

Looks like things have gotten worse as the version number increases…

Out of curiosity, could someone post results with Sun JVMs?

It’s interesting that 1.4 works better. My result above is from 1.5.

All Sun VMs (Windows, Linux) work fine

1.4.2, 1.5, 1.6

I posted this problem on the Apple Java mailing list, with a link to this thread (http://lists.apple.com/archives/Java-dev/2008/Sep/msg00457.html). Since Apple’s Java team actually reads this list, and replies to it, there should be a fairly large chance of an ‘official’ reply in the next week or so.

In Java 1.5 it certainly does not crash the entire JVM. It just does not execute the Thread. My applet keeps functioning.

We have a reply, it is indeed a bug:
http://lists.apple.com/archives/Java-dev/2008/Sep/msg00471.html

I already reported it into their issue tracking system.

Wow what a truly fluid response. Prolific, you might say. ::slight_smile:

Bedankt Dennis!

Any chance to see the progress in the issuetracker, like a tracking id?

I reported it under Bug ID# 6256466, but it seems Apple’s issue tracker doesn’t allow public access to issues.

@Demonpants: We had to wait 18 months before Apple released Java 6, which created the question if they would even continue their Java support at all. So getting ANY sort of reply on a Java-related matter is already a miracle. I think the chance of Steve Jobs responding to my mailing list post is fairly low.

@Riven: Are you Dutch? :slight_smile:

Yup yup yup, even living quite near you.

One of Apple’s Jva guys contacted me to inform me that this bug has been fixed in their Java Update 5, which was released last week. So compliments to Riven for finding something that they rank as ‘serious issue’ :slight_smile:

So many emotions…!

bored :persecutioncomplex: immortal

                     ::)