Transcript
Page 1: JVM performance options. How it works

JVM performance options.

How it works?

Page 2: JVM performance options. How it works

Dmitriy DumanskiyCogniance, Velti project

Java Team Lead

Page 3: JVM performance options. How it works

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

Page 4: JVM performance options. How it works
Page 5: JVM performance options. How it works

Options may vary per

architecture / OS / JVM version

Page 6: JVM performance options. How it works

JVM 6 ~ 730 options

JVM 7 ~ 680 options

Page 7: JVM performance options. How it works

-X : are non-standard (not all JVM)

-XX : are not stable

Page 8: JVM performance options. How it works

Boolean : -XX:+<option> or -XX:-<option>

Numeric : -XX:<option>=<number>

String : -XX:<option>=<string>

Types

Page 9: JVM performance options. How it works

Categories

Behavioral options

Garbage Collection options

Performance tuning options

Debugging options

Page 10: JVM performance options. How it works

Analys : Can objects be created on stack?

Are objects accessed from 1 thread?

-XX:+DoEscapeAnalysis

Page 11: JVM performance options. How it works

Analys result : GlobalEscape

ArgEscape

NoEscape

-XX:+DoEscapeAnalysis

Page 12: JVM performance options. How it works

NoEscape

class Cursor {

String icon;

int x;

public void create() {

Cursor c = new Cursor(); //HEAP

c.icon = null; //HEAP

c.x = 0; //HEAP

}

}

Page 13: JVM performance options. How it works

NoEscape → scalar replacement

class Cursor {

String icon;

int x;

public void create() {

String icon = null; //ref on stack frame

int x = 0; //int on stack frame

}

}

Page 14: JVM performance options. How it works

NoEscape → scalar replacement

Page 15: JVM performance options. How it works

NoEscape → scalar replacement

Page 16: JVM performance options. How it works

-XX:+DoEscapeAnalysis

~20-60% locks elimination

~15-20% performance improvement

Page 17: JVM performance options. How it works

-XX:+DoEscapeAnalysis

Page 18: JVM performance options. How it works

-XX:+AggressiveOpts

-AggressiveOpts +AggressiveOpts

AutoBoxCacheMax 128 20000

BiasedLockingStartupDelay 4000 500

EliminateAutoBox false true

OptimizeFill false true

OptimizeStringConcat false true

Page 19: JVM performance options. How it works

-XX:AutoBoxCacheMax=size

class Integer {public static Integer valueOf(int i) {

if(i >= -128 && i <= IntegerCache.high) return IntegerCache.cache[i + 128]; else return new Integer(i); }}

Sets IntegerCache.high value :

Page 20: JVM performance options. How it works

-XX:AutoBoxCacheMax=size

new Integer(1) vs Integer.valueOf(1)

valueOf ~4 times faster

Page 21: JVM performance options. How it works

-XX:BiasedLockingStartupDelay=delay

Biased

Thin

Fat

Page 22: JVM performance options. How it works

-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();

Page 23: JVM performance options. How it works

-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];

Page 24: JVM performance options. How it works

-XX:+OptimizeStringConcatString twenty = «12345678901234567890»;

String sb = new StringBuilder()

.append(twenty).append(twenty)

.append(twenty).append(twenty).toString();

new char[80];

Page 25: JVM performance options. How it works

-XX:+OptimizeStringConcatString twenty = «12345678901234567890»;

StringBuilder sb1 = new StringBuilder();

sb1.append(new StringBuilder()

.append(twenty).append(twenty)

.append(twenty).append(twenty)

);

new char[80];

Page 26: JVM performance options. How it works

XX:+OptimizeFillArrays.fill(), Arrays.copyOf() or code patterns :

for (int i = fromIndex; i < toIndex; i++) {

a[i] = val;

}

Native machine instructions

Page 27: JVM performance options. How it works

XX:+EliminateAutoBox

Removes unnecessary AutoBox operations

Works only for Integers

Page 28: JVM performance options. How it works

-XX:+UseStringCache

Look like not used anymore

Page 29: JVM performance options. How it works

-XX:+UseCompressedStrings

For ASCII characters:

char[] -> byte[]

Page 30: JVM performance options. How it works

-XX:+UseCompressedOops

Heap size up to 32GbReferences size 50% smallerJVM performance boost 2-10%20 — 60% less memory consumption;

Page 31: JVM performance options. How it works

-XX:+UseCompressedOops

32-bit 64-bit 64-bit Comp.0

0.2

0.4

0.6

0.8

1

1.2

Page 32: JVM performance options. How it works

-XX:+EliminateLocks

synchronized (object) { //doSomething1}synchronized (object) { //doSomething2}

synchronized (object) { //doSomething1 //doSomething2}

Page 33: JVM performance options. How it works

-XX:+EliminateLockssynchronized (object) { //doSomething1}

//doSomething2

synchronized (object) { //doSomething3}

synchronized (object) { //doSomething1 //doSomething2 //doSomething3}

Page 34: JVM performance options. How it works

-XX:+UseLargePages

Translation-Lookaside Buffer (TLB) is a page translation cache that holds the most-

recently used virtual-to-physical address translations

Page 35: JVM performance options. How it works

-XX:CompileThreshold=n

Client mode n = 1500

Server mode n = 10000

More profile data — more optimizations

Page 36: JVM performance options. How it works

-XX:hashCode=n

Object.hashCode() - internal address of the object?

Page 37: JVM performance options. How it works

-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


Recommended