Profiling information is important for the Jamaica compiler to perform optimization of an application. We strongly recommended building applications using profiling information gathered using a profiling run.
The builder's -profile option and the jamaicavmp command provide simple means to profile an application. Setting the -profile option enables profiling. The builder will then link the application with the profiling version of the JamaicaVM libraries.
During profiling the Jamaica Virtual Machine counts, among other things, the number of bytecode instructions executed within every method of the application. The number of instructions can be used as a measure for the time spent in each method.
At the end of execution, the total number of bytecode instructions executed by each method is written to a file with the name of the main class of the Java application and the suffix .prof, such that it can be used for further processing. 'Hot spots' (the most likely sources for further performance enhancements by optimization) in the application can easily be determined using this file.
Jamaica's compilation technology is able to use the data generated using the -profile option to guide the compilation process, producing optimal performance with the minimum increase in code size.
Example:
Here is a demonstration of the profiler using the HelloWorld example previously presented in Figure 6-2. First, it is built using the -profile option:
> jamaica -profile HelloWorld
Reading configuration from '/usr/local/jamaica/etc/jamaica.conf'...
Jamaica Builder Tool 3.0 Release 1
+ HelloWorld__.c
+ HelloWorld__.h
Class file compaction gain: 66.18455% (7189668 ==> 2431219)
+ HelloWorld__nc.o
* C compiling 'HelloWorld__.c'
* linking
* stripping
|
The generated executable HelloWorld now prints the profiling information after execution. The output may look like this [1]:
> ./HelloWorld 10000
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
...
Hello World!
Hello World!
Hello World!
Hello World!
Start writing profile data into file 'HelloWorld.prof'
Write instantiation data...
Write invokation data...
Write heap data...
0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Done writing profile data
|
Alternatively, for a simple application, the profile can also be created using the jamaicavmp command without first building a stand-alone executable, as follows:
> jamaicavmp HelloWorld 10000
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
...
Hello World!
Hello World!
Hello World!
Hello World!
Start writing profile data into file 'HelloWorld.prof'
Write instantiation data...
Write invokation data...
Write heap data...
0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Done writing profile data
|
| [1] | For better results, we run the application with the command line argument 10000 such that startup code does not dominate |