Skip to main content

Can´t get escape analysis to work - Howto properly enable this feature ?

1 reply [Last post]
Joined: 2010-05-02

Dear Community,

I have read lots of information concerning the Escape Analysis optimization of the jdk. A lot of sources tell that Escape Analysis is readily available and working by default in jdk7 and possible to turn on since jdk6u14.

I am using jdk6u16 and the latest windows jdk7 and can't verify any positive results concerning escape analysis.

I tried different scenarios like this one:

public void rotate(float angle, Vector3 axis) {
Matrix3 rotationMatrix = new Matrix3();

rotationMatrix.loadAxisAngleRotation(angle, axis);

In this function a local object, the rotationMatrix is created and afterwards used to transform the coordinate axes of the matrix class, which the rotate function is a member of. If i understand EA-analysis right, this should be a great example for this kind of optimization. The matrix and its subobjects are detected as non-escaping objects and are allocated on the stack as a consequence.

Unfortunately I can't verify that. I get a high allocation count using this method. I also ran tests on the command line like this:

java -server -XX:+DoEscapeAnalysis -XX+AggressiveOpts

and i get no results. Neither in jdk6 nor 7.

I also tried the "defensive copy" example.

the matrix class has vector subobjects for its axes.

class Matrix3 {
private Vector3 x, y, z;
private Point3 pos

Vector3 getX() {
//Defensive copy
return new Vector3(x);

This either didn't work out the vector3 gets allocated although i used a simple "println" of its components in a for loop, without doing any writes or passing the object further on. I believe the error must be on my side. It would be great if you could point out how to enable EA analysis and how to verify how and when it actually works.

I used the -Xloggc mechanism and the netbeans memory profiler.

This is really important to me, as I am developing a real game in java and you might now, that especially for arithmetics, with lots of temporary objects EA analysis is crucial ! It really is important to me, mentally I always counted on that feature design wise. Now that I actually try it out and get negative results I get wet feets concering the language I chose. If you could help me out, you could save me a lot of trouble. I really don't want to switch languages.

Thank you for your kind attention,

My version is:
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b91)
Java HotSpot(TM) Client VM (build 18.0-b03, mixed mode, sharing)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-05-02

By the way... If you care. I solved the problem. It is the profiler, which hooks into the allocation mechanism and prevents EA - analysis. Or formulated differently, the profiler counts every allocation, regardless if it is omitted when EA is turned on.

If have had some great optimization results through EA. I am happy that it works great. It makes java an whole new language. EA allows programming patterns that are not possible, at least not performant without EA. I will totally rely on it, there is no step back (-;

Thank you,