Your SlideShare is downloading. ×

JVM performance options. How it works

3,292

Published on

This is presentation for Cogniance Java Evening 13.02.2013. …

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/

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,292
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
55
Comments
0
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JVM performance options. How it works?
  • 2. Dmitriy Dumanskiy Cogniance, Velti project Java Team Lead
  • 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. Options may vary perarchitecture / OS / JVM version
  • 5. JVM 6 ~ 730 optionsJVM 7 ~ 680 options
  • 6. -X : are non-standard (not all JVM)-XX : are not stable
  • 7. TypesBoolean : -XX:+<option> or -XX:-<option>Numeric : -XX:<option>=<number>String : -XX:<option>=<string>
  • 8. Categories Behavioral options Garbage Collection options Performance tuning options Debugging options
  • 9. -XX:+DoEscapeAnalysis Analys : Can objects be created on stack? Are objects accessed from 1 thread?
  • 10. -XX:+DoEscapeAnalysis Analys result : GlobalEscape ArgEscape NoEscape
  • 11. NoEscapeclass Cursor { String icon; int x; public void create() { Cursor c = new Cursor(); //HEAP c.icon = null; //HEAP c.x = 0; //HEAP }}
  • 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. NoEscape → scalar replacement
  • 14. NoEscape → scalar replacement
  • 15. -XX:+DoEscapeAnalysis ~20-60% locks elimination~15-20% performance improvement
  • 16. -XX:+DoEscapeAnalysis
  • 17. -XX:+AggressiveOpts -AggressiveOpts +AggressiveOptsAutoBoxCacheMax 128 20000BiasedLockingStartupDelay 4000 500EliminateAutoBox false trueOptimizeFill false trueOptimizeStringConcat false true
  • 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. -XX:AutoBoxCacheMax=size new Integer(1) vs Integer.valueOf(1) valueOf ~4 times faster
  • 20. -XX:BiasedLockingStartupDelay=delay  Biased  Thin  Fat
  • 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. -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. -XX:+OptimizeStringConcatString twenty = «12345678901234567890»;String sb = new StringBuilder().append(twenty).append(twenty).append(twenty).append(twenty).toString(); new char[80];
  • 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. XX:+OptimizeFillArrays.fill(), Arrays.copyOf() or code patterns :for (int i = fromIndex; i < toIndex; i++) { a[i] = val;} Native machine instructions
  • 26. XX:+EliminateAutoBox Removes unnecessary AutoBox operations Works only for Integers
  • 27. -XX:+UseStringCacheLook like not used anymore
  • 28. -XX:+UseCompressedStrings For ASCII characters: char[] -> byte[]
  • 29. -XX:+UseCompressedOops Heap size up to 32Gb References size 50% smaller JVM performance boost 2-10% 20 — 60% less memory consumption;
  • 30. -XX:+UseCompressedOops1.2 10.80.60.40.2 0 32-bit 64-bit 64-bit Comp.
  • 31. -XX:+EliminateLockssynchronized (object) { synchronized (object) { //doSomething1 //doSomething1} //doSomething2synchronized (object) { } //doSomething2}
  • 32. -XX:+EliminateLockssynchronized (object) { //doSomething1} synchronized (object) { //doSomething1//doSomething2 //doSomething2 //doSomething3synchronized (object) { } //doSomething3}
  • 33. -XX:+UseLargePages Translation-Lookaside Buffer (TLB) is a page translation cache that holds the most-recently used virtual-to-physical address translations
  • 34. -XX:CompileThreshold=n Client mode n = 1500 Server mode n = 10000More profile data — more optimizations
  • 35. -XX:hashCode=nObject.hashCode() - internaladdress of the object?
  • 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

×