Fine-Tuning Performance
This topic discusses ways to fine-tune the performance of your
compiled Java code using hpj command options and
other techniques. Detailed information about hpj
command options is found in the topic hpj
Command.
Improving Execution Speed
Specify one or more of the following options on the hpj
command:
- -O
- Compile with optimization. By
default, HPCJ compiles your code without optimizations
turned on. You can usually generate code that runs
significantly faster by specifying the -O
option. This causes a number of optimizations to be
performed, including the usual low-level ones, such as
constant propagation, dead code elimination, loop
unrolling, and others, as well as a few higher-level,
Java-specific optimizations.
-
- -architecture arch
- Generate code for the specified architecture. Code generation is normally done for a
default, generic form of the processor of your machine.
You can also instruct HPCJ to specialize its code
generation to a particular architecture. Use the -architecture
option to pass HPCJ the type of machine you want your
code to run on. The arguments for this option vary by
operating system/platform and are summarized in the topic
hpj
Command.
-
- -tune arch
- Tune code generation for the specified architecture. Code generation is normally tuned for a
default, generic form of the processor of your machine.
The -tune option passes HPCJ the type of
architecture for which it should optimize code. The
arguments for this command vary by operating
system/platform and are summarized in the topic hpj
Command.
-
For example, you might use the
following options and arguments to obtain the best
performance on a Pentium II processor.-architecture pentium2 -tune pentium2
- -[no]maxmem size
[Do not] Restrict optimizations to use no more than size
kilobytes. The compiler needs a
certain amount of memory/space to perform optimizations.
The -maxmem option can be used to
increase the size of the area which gets allocated for
this purpose. If you notice compilation messages
informing you that better optimizations can be achieved
with more memory, consider increasing the size
value. The argument should be the amount of memory (in
Kilobytes) that should be reserved. The range of valid
arguments is from 1 to 2097152. You can also specify the -nomaxmem
option to give the backend unlimited space. This is
equivalent to specifying -maxmem
2097152. Both the -maxmem and -nomaxmem
options are ignored if you don't compile with -O.
-
- -spill size
Restrict the register spill area to size bytes.
-
Improving Execution Speed Using
Unsafe Options
In this section, some options are discussed that can be used to
improve performance, but they will result in code which is not
fully-compliant with the Java specifications. For this reason,
these options should be used with care.
Java requires that all object member
(data or method) accesses be guarded by a null-pointer check, and
that all array accesses be subjected to a bounds check, throwing
the following errors at run time if a violation is detected
java.lang.NullPointerException
java.lang.ArrayIndexOutOfBoundsException
Many unnecessary checks will be removed
by the optimizer if you specify the -O option,
but in order to be conservatively correct, many checks will also
remain. If you know your application will not generate such
errors, you can prevent all such checks from being generated in
the first place by specifying the following options on the
command line during compilation:
-XP 2,-qdebug=jnoruncheck
These options ensure that neither null
pointer checks nor array bounds checks will be generated.
However, they are debug options and are not supported. Note that
removing run time checks can result in a significant performance
increase, particularly for array-intensive code.
Reducing Executable Size
Use one or more of the following strategies to reduce the size of
your executables:
- If compilation size is a serious
problem, specify the -compact option.
This option causes optimizations to be biased toward
reducing code size rather than increasing speed.
- If you build an executable, it can
often result in a rather large application. Consider
building separate DLL files and running your code with
the hpjava command. This does not change
the amount of code to be executed, but any code built as
a dynamic library can be shared by several HPCJ
applications.
- If you include classes which are
never called in your executable (or in a .jll), it can
result in unnecessarily large code. If you know exactly
which files are used by your application, you can build
separate DLLs to ensure that only the necessary classes
get loaded. To determine which classes are used by your
code, run your application with java
(the JDK-supplied virtual machine interpreter) using the -verbose
option and note which classes are loaded.
- If you use the -g
option to generate debug information, it can greatly
increase code size. Ensure that you build your final code
without the -g option. You can also
specify the -nog option later on the
command line to cancel any previous -g
options).
- Optimizing with -O
may also help reduce code size, since optimized code is
often smaller than non-optimized code.
- Code size can also be reduced by
eliminating run-time checks for null pointers and array
index bounds violations. Additional information is found
above in the section Improving Execution Speed Using
Unsafe Options.


Java Executables and DLLs

Building Executables and DLLs
Running Executables and DLLs
hpj Command
hpjava Command