
This article introduces some of the Java features in
Leopard. With improvements including better performance, 64-bit computing, new options for
choosing the version of Java you want to run, and new tools to better
analyse your Java code, Leopard reflects Apple's focus on providing the
best possible Java experience on Mac OS X and supporting the latest
hardware, while preserving compatibility.
Take Advantage of Intel 64-bit Computing
Mac OS X Leopard breaks the barriers of 32-bit computing
and allows you to run next generation 64-bit applications side-by-side
with current 32-bit software in the same operating system. On Macs with
Intel Core 2 Duo or Xeon processors, this support
is extended to Java applications.
For traditional desktop applications like word processors and
spreadsheets, the 32-bit address space that has been used for the last
few decades is enough. For the next generation of data intensive
applications, such as those that work with the human genome or
geospatial data, the 4GB of memory space that 32-bit addressing allows
suddenly becomes very limiting. Sixty-four-bit computing shatters the 4GB limit
allowing applications to address more than 16 exabytes of memory
space.
To put the difference between 32-bit and 64-bit computing into
perspective, imagine that you are working with a dataset in which the
road area of the Golden Gate bridge can be represented in a 32-bit
address space. With 64 bits of address space, you have the ability to model
the entire surface of the Earth at the same resolution.
There are several ways to run your Java application in 64-bit mode. On the
command line, you can use the -d64 flag. For example, you
can set a launch script to execute the following:
/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/java -d64 MyApp
For double-clickable bundled applications, you can request that the 64-bit virtual machine be used by adding the following to your application's Info.plist file:
<key>JVMArchs</key>
<array>
<string>x86_64</string>
</array>
If the 64-bit virtual machine isn't available, the default 32-bit
version will be used.
For pure Java applications running on 64-bit capable Intel hardware,
either of the above steps is all you need to run your Java application in
64-bit mode. If you have native code in your application, however, you
need to create a universal library that contains an
x86_64 executable as well as PPC and
i386 variants.
Once you have your application running in 64-bit mode, you'll
probably want to increase the heap size. On the command line, you need
to use the -Xms and -Xmx arguments to define
the initial and maximum heap sizes. For a bundled application, you'll
need to add the following to your Info.plist file:
<key>VMOptions.x86_64</key>
<string>-Xms2g -Xmx8g</string>
An important thing to note is that when running with large heaps of
memory, it can take longer for the virtual machine's garbage collector
to operate. You may want to experiment with alternative garbage
collectors, such as the Concurrent Mark and Sweep collector, enabled
with the -XX:+UseConcMarkSweepGC runtime flag, or the
Parallel collector, enabled with the -XX:+UseParallelGC
runtime flag.
Run Multiple Versions of Java
Mac OS X includes multiple versions of Java, and lets you run them
side by side. The Java Preferences Application, located in the
/Applications/Utilities/Java folder, lets you set the
version of Java that is used by default on the command line as well as
for applets, package applications, and Java Web Start applications. If
you want to use a version of the JDK that's not the default, you can
directly execute the version you want to use on the command line.
To make it easy to use multiple versions of Java on the command line,
here's a tip. Add the following two lines to your
~/.bash_profile file:
alias java15=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/java
alias java14=/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Commands/java
Now, when you open a new shell, you're set to go. For example:
$ java14 -version
java version "1.4.2_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_16-b05-302)
Java HotSpot(TM) Client VM (build 1.4.2-85, mixed mode)
$ java15 -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)
You can take this tip one step further and add the ability to run
your applications with a 64-bit address space. For example, you could
define the following alias in your ~/.bash_profile
file:
alias java64="java15 -d64"
Then, when you open a new shell, you'll be able to do the following:
$ java64 -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_13-119, mixed mode)
Developer Tools Support
Instruments, introduced in Leopard, helps
developers better understand how their applications run.
It lets you visualize multiple aspects of system and application
performance over time, including CPU load, network activity, graphics
activity, user events, and memory allocations. For the Java developer,
Instruments provides built-in support for inspecting Java applications
as they run, including monitoring activity on every thread.
In addition to ground-breaking performance and analysis tools, Leopard includes several Java-community developed tools, including Ant and Maven. By including these command-line tools, you can more easily get right to work on your Java software with a minimum of setup. You can download any open source Java project and have everything you need to get right down to business.
As well, Xcode's new Organizer features drag-and-drop support for Ant-based projects. You can either open up a directory containing your codebase, or create a fresh Ant-based project right from the Organizer. After that, building your project is as simple as pushing the Build button.
Run Faster
Leopard includes the best community-developed tools, such as
Ant and Maven, support for 64-bit applications to Java, and
unprecedented visibility into the inner workings of your
applications. Yet another important feature is the enhanced performance of the Java runtime
on Leopard. Java applications will see an average of 10% improvement in
performance on Leopard compared to Mac OS X Tiger. These performance
increases are due to work done both in the Java virtual machine and in the
operating system as a whole.
Also, Java applications that take advantage of
64-bit support can see even greater improvements in performance, thanks
to being able to take better advantage of the increased registers and
other features of the Intel Core 2 Duo and Xeon processors that aren't
available to 32-bit applications.
Posted: 2007-12-04
|