JVM performance    options.  How it works?
Dmitriy Dumanskiy Cogniance, Velti project     Java Team Lead
Xmx2048M -Xms2048M     -XX:ParallelGCThreads=8 -Xincgc     -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPac...
Options may vary perarchitecture / OS / JVM version
JVM 6 ~ 730 optionsJVM 7 ~ 680 options
-X   : are non-standard (not all JVM)-XX : are not stable
TypesBoolean : -XX:+<option> or -XX:-<option>Numeric : -XX:<option>=<number>String   : -XX:<option>=<string>
Categories    Behavioral options    Garbage Collection options    Performance tuning options    Debugging options
-XX:+DoEscapeAnalysis      Analys :    Can objects be created on stack?    Are objects accessed from 1 thread?
-XX:+DoEscapeAnalysis      Analys result :    GlobalEscape    ArgEscape    NoEscape
NoEscapeclass Cursor {    String icon;    int x;    public void create() {        Cursor c = new Cursor(); //HEAP        c...
NoEscape → scalar replacementclass Cursor {    String icon;    int x;    public void create() {        String icon = null;...
NoEscape → scalar replacement
NoEscape → scalar replacement
-XX:+DoEscapeAnalysis    ~20-60% locks elimination~15-20% performance improvement
-XX:+DoEscapeAnalysis
-XX:+AggressiveOpts                            -AggressiveOpts +AggressiveOptsAutoBoxCacheMax                  128        ...
-XX:AutoBoxCacheMax=sizeSets IntegerCache.high value :class Integer {    public static Integer valueOf(int i) {      if(i ...
-XX:AutoBoxCacheMax=size new Integer(1) vs Integer.valueOf(1)       valueOf ~4 times faster
-XX:BiasedLockingStartupDelay=delay        Biased        Thin        Fat
-XX:-OptimizeStringConcatString twenty = «12345678901234567890»;String sb = twenty + twenty + twenty +  twenty;String twen...
-XX:-OptimizeStringConcatString twenty = «12345678901234567890»;String sb = new StringBuilder().append(twenty).append(twen...
-XX:+OptimizeStringConcatString twenty = «12345678901234567890»;String sb = new StringBuilder().append(twenty).append(twen...
-XX:+OptimizeStringConcatString twenty = «12345678901234567890»;StringBuilder sb1 = new StringBuilder();sb1.append(new Str...
XX:+OptimizeFillArrays.fill(), Arrays.copyOf() or code  patterns :for (int i = fromIndex; i < toIndex; i++) {            a...
XX:+EliminateAutoBox    Removes unnecessary AutoBox operations    Works only for Integers
-XX:+UseStringCacheLook like not used anymore
-XX:+UseCompressedStrings    For ASCII characters:       char[] -> byte[]
-XX:+UseCompressedOops    Heap size up to 32Gb    References size 50% smaller    JVM performance boost 2-10%    20 — 6...
-XX:+UseCompressedOops1.2 10.80.60.40.2 0      32-bit   64-bit   64-bit Comp.
-XX:+EliminateLockssynchronized (object) {                          synchronized (object) {   //doSomething1              ...
-XX:+EliminateLockssynchronized (object) {   //doSomething1}                         synchronized (object) {              ...
-XX:+UseLargePages Translation-Lookaside Buffer   (TLB) is a page translation   cache that holds the most-recently used vi...
-XX:CompileThreshold=n    Client mode n = 1500   Server mode n = 10000More profile data — more optimizations
-XX:hashCode=nObject.hashCode() - internaladdress of the object?
-XX:hashCode=nn is :    0   –   Park-Miller RNG (default)    1   –   f (address, global state)    2   –   const 1    3...
JVM performance options. How it works
Upcoming SlideShare
Loading in...5
×

JVM performance options. How it works

3,678

Published on

This is presentation for Cogniance Java Evening 13.02.2013.
My related to topic article you can find here (russian) : http://habrahabr.ru/post/160049/

JVM performance options. How it works

  1. 1. JVM performance options. How it works?
  2. 2. Dmitriy Dumanskiy Cogniance, Velti project Java Team Lead
  3. 3. Xmx2048M -Xms2048M -XX:ParallelGCThreads=8 -Xincgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc -XX:UseSSE=3 -XX:PermSize=128m -XX:LargePageSizeInBytes=4m
  4. 4. Options may vary perarchitecture / OS / JVM version
  5. 5. JVM 6 ~ 730 optionsJVM 7 ~ 680 options
  6. 6. -X : are non-standard (not all JVM)-XX : are not stable
  7. 7. TypesBoolean : -XX:+<option> or -XX:-<option>Numeric : -XX:<option>=<number>String : -XX:<option>=<string>
  8. 8. Categories Behavioral options Garbage Collection options Performance tuning options Debugging options
  9. 9. -XX:+DoEscapeAnalysis Analys : Can objects be created on stack? Are objects accessed from 1 thread?
  10. 10. -XX:+DoEscapeAnalysis Analys result : GlobalEscape ArgEscape NoEscape
  11. 11. NoEscapeclass Cursor { String icon; int x; public void create() { Cursor c = new Cursor(); //HEAP c.icon = null; //HEAP c.x = 0; //HEAP }}
  12. 12. NoEscape → scalar replacementclass Cursor { String icon; int x; public void create() { String icon = null; //ref on stack frame int x = 0; //int on stack frame }}
  13. 13. NoEscape → scalar replacement
  14. 14. NoEscape → scalar replacement
  15. 15. -XX:+DoEscapeAnalysis ~20-60% locks elimination~15-20% performance improvement
  16. 16. -XX:+DoEscapeAnalysis
  17. 17. -XX:+AggressiveOpts -AggressiveOpts +AggressiveOptsAutoBoxCacheMax 128 20000BiasedLockingStartupDelay 4000 500EliminateAutoBox false trueOptimizeFill false trueOptimizeStringConcat false true
  18. 18. -XX:AutoBoxCacheMax=sizeSets IntegerCache.high value :class Integer { public static Integer valueOf(int i) { if(i >= -128 && i <= IntegerCache.high) return IntegerCache.cache[i + 128]; else return new Integer(i); }}
  19. 19. -XX:AutoBoxCacheMax=size new Integer(1) vs Integer.valueOf(1) valueOf ~4 times faster
  20. 20. -XX:BiasedLockingStartupDelay=delay  Biased  Thin  Fat
  21. 21. -XX:-OptimizeStringConcatString twenty = «12345678901234567890»;String sb = twenty + twenty + twenty + twenty;String twenty = «12345678901234567890»;String sb = new StringBuilder().append(twenty).append(twenty).append(twenty).append(twenty).toString();
  22. 22. -XX:-OptimizeStringConcatString twenty = «12345678901234567890»;String sb = new StringBuilder().append(twenty).append(twenty).append(twenty).append(twenty).toString(); new char[16]; new char[34]; new char[70]; new char[142];
  23. 23. -XX:+OptimizeStringConcatString twenty = «12345678901234567890»;String sb = new StringBuilder().append(twenty).append(twenty).append(twenty).append(twenty).toString(); new char[80];
  24. 24. -XX:+OptimizeStringConcatString twenty = «12345678901234567890»;StringBuilder sb1 = new StringBuilder();sb1.append(new StringBuilder() .append(twenty).append(twenty) .append(twenty).append(twenty)); new char[80];
  25. 25. XX:+OptimizeFillArrays.fill(), Arrays.copyOf() or code patterns :for (int i = fromIndex; i < toIndex; i++) { a[i] = val;} Native machine instructions
  26. 26. XX:+EliminateAutoBox Removes unnecessary AutoBox operations Works only for Integers
  27. 27. -XX:+UseStringCacheLook like not used anymore
  28. 28. -XX:+UseCompressedStrings For ASCII characters: char[] -> byte[]
  29. 29. -XX:+UseCompressedOops Heap size up to 32Gb References size 50% smaller JVM performance boost 2-10% 20 — 60% less memory consumption;
  30. 30. -XX:+UseCompressedOops1.2 10.80.60.40.2 0 32-bit 64-bit 64-bit Comp.
  31. 31. -XX:+EliminateLockssynchronized (object) { synchronized (object) { //doSomething1 //doSomething1} //doSomething2synchronized (object) { } //doSomething2}
  32. 32. -XX:+EliminateLockssynchronized (object) { //doSomething1} synchronized (object) { //doSomething1//doSomething2 //doSomething2 //doSomething3synchronized (object) { } //doSomething3}
  33. 33. -XX:+UseLargePages Translation-Lookaside Buffer (TLB) is a page translation cache that holds the most-recently used virtual-to-physical address translations
  34. 34. -XX:CompileThreshold=n Client mode n = 1500 Server mode n = 10000More profile data — more optimizations
  35. 35. -XX:hashCode=nObject.hashCode() - internaladdress of the object?
  36. 36. -XX:hashCode=nn is : 0 – Park-Miller RNG (default) 1 – f (address, global state) 2 – const 1 3 – sequence counter 4 – object address 5 – Thread-local Xorshift
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×