java memory presentation ibm 7

Post on 15-Jan-2015

242 Views

Category:

Software

10 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Java;Memory

Yury Bubnov zStore

Object o = new Object();

Object o = new Object();

java.lang.OutOfMemoryError:  Java  heap  space

Object o = new Object();

java.lang.OutOfMemoryError:  Java  heap  space

Heap

Heap

How many?

Heap

How many?Size?

class Structure{ byte b; short i; Object o; }

1 2 4/8

class Structure{ byte b; short i; Object o; }

class Structure{ byte b; short i; Object o; }

mark klass

2 1 1 4

class Structure{ byte b; short i; Object o; }

2

8

mark klass

2 1 1 4

class Structure{ byte b; short i; Object o; }

mark

klass

2 1 5

8

class Structure{ byte b; short i; Object o; }

mark

klass

2 1 5

8

4

8

Memory address

...01100100100111011001011000

Memory address

...01100100100111011001011000

Memory address

...01100100100111011001011000

32 bit pointer

Memory address

...01100100100111011001011000

32 bit pointer .... to 35 bit

Memory address

...01100100100111011001011000

32 bit pointer .... to 35 bit

2^35≈32GB (25-28GB Heap)

Memory address

...01100100100111011001011000

32 bit pointer .... to 35 bit

2^35≈32GB (25-28GB Heap)

IBM J9: Java 6 SR1, by default since Java7 SR4 Hotspot: since Java 6u14, by default since u23

class Structure{ byte b; short i; Object o; }

mark

klass 1 2 1

4 4

class Structure{ byte b; short i; Object o; }

3

8

mark

klass 1 2 1

4 4

klass flagsmonitor 4

1 3 2 2=24b

klassflags size*

monitor8

1 3 2 2

klass flagsmonitor 1 3

4 2 2

=40b

=24b

i386

x64

x64C

IBM J9 Java6

What’s the object size?class Structure{ byte b;short i;Object o;}

What’s the object size?

HS 32b 16b

HS 64b before u14 32b

HS 64b after u14 (u27) 24b

J9 32b 24b

J9 64b 40b

J9 64b compressed 24b

class Structure{ byte b;short i;Object o;}

Mind the gap

Mind the gapbyte[][][] b = new byte[10][100][1000];

Mind the gap

byte[][][] b = new byte[1000][100][10];

byte[][][] b = new byte[10][100][1000];

Mind the gap

byte[][][] b = new byte[1000][100][10];

byte[][][] b = new byte[10][100][1000];

1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a)

Mind the gap

byte[][][] b = new byte[1000][100][10];

byte[][][] b = new byte[10][100][1000];

4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a)

1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a)

Mind the gap

byte[][][] b = new byte[1000][100][10];

byte[][][] b = new byte[10][100][1000];

4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a)

1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a)

x100

Mind the gap

byte[][][] b = new byte[1000][100][10];

byte[][][] b = new byte[10][100][1000];

4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a)

1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a)

x100 x100

Mind the gap

byte[][][] b = new byte[1000][100][10];

byte[][][] b = new byte[10][100][1000];

4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a)

1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a)

x100 x100 x250

header4 1 3

2 6=24bx64C

IBM J9 Java7 for ebay

Structure:

header

8=16bx64C

byte[8]:

*Could be as little as 4 bytes (JavaOne 2011)

Garbage Collection

Garbage Collection1. Starts if allocation fails or System.gc()* called or condition met

Garbage Collection1. Starts if allocation fails or System.gc()* called or condition met

2. Stop-of-the-world operation

Garbage Collection1. Starts if allocation fails or System.gc()* called or condition met

2. Stop-of-the-world operation

3. Mark, Sweep and Compact*

Mark

Mark

MarkPermGen

Stack

JNI

Stack Stack

MarkPermGen

Stack

JNIX X

X

X

Stack Stack

Mark

A

B C

DE

A B0 0 0

C D E0 0 0 0 0 0 0 0 0 0

Mark

A

B C

DE

1A B

0 0C D E0 0 0 0 0 0 0 0 0 0

A

Mark

A

B C

DE

1A B

0C D E

0 0 0 0 0 0 0 0 0

Mark

A

B C

DE

BC

1 1

1A B

0C D E

0 0 0 0 0 0 0 0

Mark

A

B C

DE CE

1 1 1

1A B

0C D E

0 0 0 0 0 0 0 0

Mark

A

B C

DE E

1 1 1

1A B

0C D E

0 0 0 0 0 0 0 0

Mark

A

B C

DE

1 1 1

1A B C D E

0 0 0

Mark

A

B C

DE

1 1 11 1 1 1 1 1

1A B C D E

0 0 0

Mark

A

B C

DE

1 1 11 1 1 1 1 1

References

References1. Strong - always marked !

2. Soft - not marked if too old or need memory !

3. Weak - not marked if no strong reference !

4. Phantom - correct implementation of finalize() method

Mark

MarkSerial

Mark

MarkParallel

MarkPermGen

JNI

Stack Stack Stack

MarkPermGen

JNI

Stack Stack Stack

MarkPermGen

JNI

Stack Stack Stack

MarkPermGen

JNI

Stack Stack Stack

MarkPermGen

JNI

Stack Stack Stack

MarkPermGen

JNI

Stack Stack Stack

MarkPermGen

JNI

Stack Stack Stack

MarkPermGen

JNI

Concurrent

Stack Stack Stack

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Serial

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

... 1 0 0 1 1 1 0 0 0 1 1 ...

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

... 1 0 0 1 1 1 0 0 0 1 1 ...

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Parallel

... 1 0 0 1 1 1 0 0 0 1 1 ...

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Sweep

... 1 0 0 1 1 1 0 0 0 1 1 ...

Concurrent

1 1 0 0 1 1 1 0 0 0 1 1 ...

Compact

1 1 1 1 1 1 1 0 0 0 0 0 ...

optthuput (default in Java6) parallel mark and compact. contiguous heap !optavgpause concurrent mark and sweep. contiguous heap !gencon (default in Java7) copying GC for young area concurrent mark for old area !

balanced (new for Java7) heap split to small regions (G1)

Types of Garbage Collection

Heap

Heap (J9)

Young/Eden

Old/Tenured

Heap (J9)

Allocation

Old/Tenured

Survivor

Heap (J9)

Heap (J9)

Heap (J9)

Heap (J9)

Heap (J9)

Balanced GC

Balanced GC

Balanced GC

Balanced GC

0 Free Free 1 3

Free 0 0 2 0

Free 2 10 11 5

0 2 Free 3 1

1 Free 15 Free 0

Balanced GC

Balanced GC

1. Partial garbage collection (PGC)

Balanced GC

1. Partial garbage collection (PGC)

2. Global mark phase (GMP)

Balanced GC

1. Partial garbage collection (PGC)

2. Global mark phase (GMP)

3. Global garbage collection (GGC)

Partial Garbage Collection

1. All Eden regions

2. Regions from CMP3. Statistics

Partial Garbage Collection

0 Free 0 1 3 2

Free 1 Free 2 4 Free

1. All Eden regions

2. Regions from CMP3. Statistics

Arraylets

PermGen

PermGen

Bootstrap System

PermGen

Bootstrap System Ext

PermGen

Bootstrap System Ext Web

App

PermGen

Bootstrap System Ext Web

AppWebApp

PermGen

Bootstrap System Ext Web

AppWebApp

WebApp

PermGen

Bootstrap System Ext Web

AppWebApp

WebApp

WebApp

PermGen

Bootstrap System Ext Web

AppWebApp

WebApp

WebApp

WebApp

PermGen

Bootstrap System Ext Web

AppWebApp

WebApp

WebApp

WebApp

java.lang.OutOfMemoryError:  PermGen  space

PermGen

Bootstrap System Ext Web

AppWebApp

WebApp

WebApp

PermGen

Bootstrap System Ext Web

AppWebApp

WebApp

WebApp

Heap

PermGen

Bootstrap System Ext Web

AppWebApp

WebApp

WebApp

Stack

Heap

Stack

Stack

Stack

Stack

Stack

Stack

Stack

java.lang.StackOverflowError

Memory

Memory

Allocation

Old/Tenured

Survivor

Memory

Allocation

Old/Tenured

Survivor

PermGen

Memory

Allocation

Old/Tenured

Survivor

PermGen

Stack Stack Stack

Memory

Allocation

Old/Tenured

Survivor

PermGen GC

Stack Stack Stack

Memory

Allocation

Old/Tenured

Survivor

PermGen

JNI

GC

Stack Stack Stack

Memory

Allocation

Old/Tenured

Survivor

PermGen

JNI

GC

Net

Stack Stack Stack

Memory

Allocation

Old/Tenured

Survivor

PermGen

JNI

GC

Net

NIO

Stack Stack Stack

Memory

Allocation

Old/Tenured

Survivor

PermGen

JNI

GC

Net

NIO

JIT

Stack Stack Stack

Memory

Allocation

Old/Tenured

Survivor

PermGen

JNI

GC

Net

NIO

JIT

CL

Stack Stack Stack

Memory

Allocation

Old/Tenured

Survivor

PermGen

JNI

GC

Net

NIO

JIT

CL

Stack Stack Stack C++

Paging

Paging1. Linux/Windows use Virtual memory and “paging” to reference physical !

2. Pages mapped to physical only when referenced !

3. OS manages pages

Real size of Java Process?

Real size of Java Process?1. Architecture: 32 vs 64

Real size of Java Process?1. Architecture: 32 vs 64

2. JVM vendor: Oracle vs IBM

Real size of Java Process?1. Architecture: 32 vs 64

2. JVM vendor: Oracle vs IBM

3. JVM version incl. update

Real size of Java Process?1. Architecture: 32 vs 64

2. JVM vendor: Oracle vs IBM

3. JVM version incl. update

4. JVM settings

Real size of Java Process?1. Architecture: 32 vs 64

2. JVM vendor: Oracle vs IBM

3. JVM version incl. update

5. OS (above applies)

4. JVM settings

Real size of Java Process?1. Architecture: 32 vs 64

2. JVM vendor: Oracle vs IBM

3. JVM version incl. update

5. OS (above applies)

+ Run under real load for long time

4. JVM settings

?

Heap

Young/Eden

Old/Tenured

Heap (HS)Young/Eden

Old/Tenured

Survivor 1 Survivor 2

Heap (HS)

Heap (HS)

Heap (HS)TLAB TLH

Heap (HS)TLAB TLH

Heap (HS)TLAB TLH

Heap (HS)

Heap (HS)

Heap (HS)

Heap (HS)X X X

Heap (HS)

Heap (HS)

Heap (HS)

Heap (HS)X XX XX

X

Heap (HS)

Heap (HS)

Heap (HS)

Heap (HS)X XX XX

X

Heap (HS)

Heap (J9)

Allocation

Old/Tenured

Survivor

Garbage Collection

Serial Parallel Concurrent

Which one to choose?

top related