tags:

views:

1421

answers:

2

How different is Apple's 1.6 Java VM from Sun's? Are there any major performance differences? Do they both share any code, or is Apple's built completely independently?

I have been amazed with the performance of the 1.6 JVM under Linux and Windows, especially on floating-point calculations (it is basically neck-and-neck with optimized C), and I'm curious about whether that same high performance exists under the Mac OS X version.

My guess would be that Sun provides Apple with the JVM/JIT/Hotspot code, and Apple handles the OSX-specific parts, but I would like to have this confirmed or refuted...

+4  A: 

As you've identified Apple has assumed responsibility for providing the JVM for OSX. Unfortunately, this has meant that Java is often several updates behind JVM updates for other platforms.

Whilst it's likely (but I couldn't find confirmation) that the source code for OSX's JVM is strongly based on Sun's implementation, since Java is not a Sun product, but a Sun specification, it's up to Apple to implement it in the right way, making the most of platform specific features.

According to James Gosling, the reason Apple rolled their own JVM is because they "wanted to do it themselves". I'd guess that, originally, Apple wanted responsibility for the Mac JVM so they could integrate it tightly with OSX, in a way that only Apple could, as the owners of the OS.

ninesided
One reason may be that they needed more control over the JVM in order to make the Cocoa-Java Bridge. Just a guess though, with no evidence to back that up.
Coxy
And they needed a PowerPC implementation.
Maurice Perry
another good point
ninesided
cocoa-java is deprecated
KitsuneYMG
+9  A: 

You are correct. Apple builds HotSpot and the core of the JVM (java.io, java.lang, etc.) from the unmodified source it receives from Sun. There are a few places where HotSpot has to be modified to accommodate OS X's Mach underpinnings, but by and large, it's the same code. The PowerPC version was written entirely in-house.

I haven't followed the "benchmark wars" in some time, but I do know the performance for 1.6 is generally excellent. Keep in mind that on Leopard Java 6 is 64-bit only, and is the 'server edition' of HotSpot.

Apple's AWT is entirely its own implementation since it's written in Cocoa. There are large parts of the AWT that are common across all platforms, such as the Java parts of java.awt and java.awt.peer, but Apple wrote its own peer implementations.

(I spent 8 years on Apple's Java team, so these are first-hand observations.)

Scott K.
Ah. But how does performance compare? I'm working on an open source project right now, and it's a real pain trying to improve performance because the Sun JVM and Apple JVM have different characteristics. Specifically, I think the implementation of System.arraycopy differs. Can you enlighten on any of this, or give specific figures at all?
BobMcGee
System.arraycopy is implemented natively, but it was done in HotSpot, and may have been optimized in some way. It's been a long time since I saw that code. You may want to ask on Apple's java-dev mailing list -- the HotSpot engineers read that list.
Scott K.