Comments on: Java 8: The JVM Can Re-capture Objects That Have Escaped https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/ Build Fast Java Applications for the Fastest Business Performance Fri, 01 May 2020 05:21:37 +0000 hourly 1 https://wordpress.org/?v=5.1.1 By: Per Minborg https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-71 Tue, 10 Apr 2018 01:32:06 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-71 Hi Gelin and thanks for your feedback. There are some conditions that must be met in order for EA to work. As can be seen in the comments above, it take some time for the C2 compiler to check the method(s) and do the actual code compile. So, run your code at least 10,000 times, wait for a while (say 1 s) and then check. Make sure you see the C2 compile output in your logs. Let me know if it works.

]]>
By: Unknown https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-72 Mon, 09 Apr 2018 20:57:02 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-72 Hi Minborg,

I just follow your article and do an experiment. Here is my Java version:

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

And my test result

luog@luog-X510UQR:~$ jps | grep Main2
Picked up JAVA_TOOL_OPTIONS: -Djava.security.egd=file:/dev/./urandom -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Djava2d.font.loadFontConf=true
15394 Main2
luog@luog-X510UQR:~$ jmap -histo 15394 | head
Picked up JAVA_TOOL_OPTIONS: -Djava.security.egd=file:/dev/./urandom -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Djava2d.font.loadFontConf=true

num #instances #bytes class name
———————————————-
1: 93 42952200 [I
2: 1215 99256 [C
3: 480 54784 java.lang.Class
4: 1203 28872 java.lang.String
5: 522 25848 [Ljava.lang.Object;
6: 9 25008 [B
7: 388 9312 java.util.LinkedList$Node
luog@luog-X510UQR:~$ jmap -histo 15394 | head
Picked up JAVA_TOOL_OPTIONS: -Djava.security.egd=file:/dev/./urandom -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Djava2d.font.loadFontConf=true

num #instances #bytes class name
———————————————-
1: 93 26951952 [I
2: 1000001 16000016 java.util.Optional
3: 1216 99288 [C
4: 480 54784 java.lang.Class
5: 1204 28896 java.lang.String
6: 522 25848 [Ljava.lang.Object;
7: 9 25008 [B
luog@luog-X510UQR:~$ jmap -histo 15394 | head
Picked up JAVA_TOOL_OPTIONS: -Djava.security.egd=file:/dev/./urandom -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Djava2d.font.loadFontConf=true

num #instances #bytes class name
———————————————-
1: 94 32426544 [I
2: 2000001 32000016 java.util.Optional
3: 1217 99320 [C
4: 480 54784 java.lang.Class
5: 1205 28920 java.lang.String
6: 522 25848 [Ljava.lang.Object;
7: 9 25008 [B

Obviously the Optional instance is still get created after the second pause. Any idea?

]]>
By: Per Minborg https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-148 Wed, 23 Dec 2015 13:49:12 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-148 Interesting post Daniel. I think one factor is that it takes a while for the compiler to actually compile the code. So, during this time, objects are always allocated on the heap. This may explain why less objects are created if the program is slowed down…

]]>
By: Unknown https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-149 Wed, 23 Dec 2015 09:13:01 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-149 I wrote a blog post summarising this thread and a few other ideas. I would be interested to hear your opinion. http://www.rationaljava.com/2015/12/how-long-does-it-take-jvm-to-effect.html

]]>
By: Unknown https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-150 Tue, 22 Dec 2015 09:03:18 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-150 I agree about -Xcomp although it's interesting that it should affect ea.

]]>
By: Per Minborg https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-151 Mon, 21 Dec 2015 19:17:52 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-151 -Xcomp makes the JVM to compile the code right away. IMO, you should not use that flag, because it is better to let the JVM run for a while and gather information on how the method should be compiled for optimum performance. EA is only made on compiled code, so that, as you say, explains why interpreted code does not benefit from EA.

]]>
By: Unknown https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-152 Fri, 18 Dec 2015 13:11:34 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-152 If you run the same program with -Xint (interpreter mode only) or -Xcomp (compile straight away) then there is no escape analysis performed. If you run without either of these flags you get to the ~200k instances, so looks like you are correct.

I'm surprised by the -Xcomp and why escape analysis doesn't seem to happen when the program is run in this mode. Does -Xcomp not trigger the C2 compiler? If anything I would have expected less instances of the Optional.

]]>
By: Per Minborg https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-153 Thu, 17 Dec 2015 18:27:13 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-153 Hi Daniel and thanks for your feedback.

The reason that a bunch of Optionals are created is that it is the C2 compiler that does the escape analysis. It will take some time before C2 kicks in and it will also take some time for it to do the compilation and analysis. So, in that time, the Optionals are created. Once it is done, the Optionals can be 'escaped away'.

Please feel free to drop more comment if you find out more interesting things!

]]>
By: Unknown https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-154 Thu, 17 Dec 2015 15:03:24 +0000 https://speedment.com/java-8-the-jvm-can-re-capture-objects-that-have-escaped/#comment-154 Thanks for an interesting article.

What's puzzling is why we have 245760 instances of the Optional. If this code was inlined and escape analysis had been effected those should have been 'escaped away'. You can prove this by replacing the Optional with an inner class, say NameWrapper (a POJO wrapper for the middleName) no instances will be created because of inlining and escape analysis.

The strange thing is that if you change the value coming back from the Optional on every call (for example by adding on the index) no instances of the Object are created.

I've tried running a few experiments to see if I can spot a pattern but there's nothing obvious.

]]>