Java Reference
In-Depth Information
where the code is actually spending more time and which things are more fruitful to optim-
ize. In this case, although the ImmutableMap.get() method is consuming 12% of the total
time, it is called 4.7 million times. We can have a much greater performance impact by redu-
cing the total number of calls to this method rather than speeding up its implementation.
On the other hand, instrumented profilers work by altering the bytecode sequence of classes
as they are loaded (inserting code to count the invocations, and so on). They are much more
likely to introduce performance differences into the application than are sampling profilers.
For example, the JVM will inline small methods (see Chapter 4 ) so that no method invoca-
tion is needed when the small-method code is executed. The compiler makes that decision
based on the size of the code; depending on how the code is instrumented, it may no longer
be eligible to be inlined. This may cause the instrumented profiler to overestimate the contri-
bution of certain methods. And inlining is just one example of a decision that the compiler
makes based on the layout of the code; in general, the more the code is instrumented
(changed), the more likely it is that its execution profile will change.
There is also an interesting technical reason why the ImmutableMap.get() method shows
up in this profile and not the sampling profile. Sampling profilers in Java can only take the
sample of a thread when the thread is at a safepoint—essentially, whenever it is allocating
memory. The get() method may never arrive at a safepoint and so may never get sampled.
That means the sampling profile can underestimate the contribution of that method to the
program execution.
In this example, both the instrumented and sampled profiles pointed to the same general area
of the code: classloading and class resolution. In practice, it is possible for different profilers
to point to completely different areas of the code. Profilers are good estimators, but they are
only making estimates: some of them will be wrong some of the time.
1. Instrumented profilers yield more information about an application, but can pos-
sibly have a greater effect on the application than a sampling profiler.
2. Instrumented profilers should be set up to instrument small sections of the
code—a few classes or packages. That limits their impact on the application's per-
Search WWH ::

Custom Search