concurrent compaction in jvm garbage collection · garbage collection parallel processing garbage...

37
Concurrent Compaction in JVM Garbage Collection Jacob P. Opdahl University of Minnesota, Morris [email protected] December 5, 2015 Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 1 / 30

Upload: others

Post on 02-Jun-2020

25 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Concurrent Compaction in JVM Garbage Collection

Jacob P. Opdahl

University of Minnesota, Morris

[email protected]

December 5, 2015

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 1 / 30

Page 2: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Overview Introduction

Automatic Memory Management

Implicit allocation and deallocation of memory

Languages: Java, C#, Python, and moreWe focus on the Java Virtual Machineand languages it supports

Abstracts details away from the developer

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 2 / 30

Page 3: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Overview Introduction

Implicit Deallocation

Memory is a finite resource

Garbage: objects that are no longer reachable

Garbage Collection (GC): detecting andremoving garbage

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 3 / 30

Page 4: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Overview Introduction

Stopping the World

GC requires processing resources

When only one processor is used, collectorsstop the world

Problem: applications today are subjected toincreasing pauses

More memoryMore strenuous applications

Use parallel processing to solve!

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 4 / 30

Page 5: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Overview Outline

Outline

1 BackgroundGarbage CollectionParallel ProcessingGarbage Collection with Parallel Processing

2 Continuously Concurrent Compacting Collector (C4)

3 Field Pinning Protocol

4 Conclusions

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 5 / 30

Page 6: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Background

Outline

1 BackgroundGarbage CollectionParallel ProcessingGarbage Collection with Parallel Processing

2 Continuously Concurrent Compacting Collector (C4)

3 Field Pinning Protocol

4 Conclusions

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 6 / 30

Page 7: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Background GC Basics

Memory

Heap: contiguous memory location used by the JVMObjects are stored here

Stack: memory for short-lived, method-specific valuesStores references: memory addresses of objects

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 7 / 30

Page 8: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Background GC Basics

GC Cycle

Set Condemnation: determine which objects are garbage

Compaction: reclaim memory while fighting heap fragmentation

Set condemnation done by tracingDetect all reachable objects by chaining references

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 8 / 30

Page 9: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Background GC Basics

Compaction

Consists of two stepsRelocation: move objects

from-space and to-space

Remapping: update object references

Free Space

(Heap before)

(Heap after)

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 9 / 30

Page 10: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Background PP Basics

Processes and Threads

Process: instance of a program being runExamples: JVM, word processorHas its own memory space

Thread: sequence of independent instructionsthat can run on its own

Component of a processPossible to run multiple in parallel

Parallel Processing: running multiple threadssimultaneously with multiple processors

wikipedia.org/wiki/Thread_

%28computing%29

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 10 / 30

Page 11: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Background PP Basics

Synchronization

Threads do not coordinate automatically

Independent instructions!

Poses new challengesExample: losing object modifications

Need to keep threads synchronized

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 11 / 30

Page 12: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Background GC with PP

Concurrency

We distinguish between application threads and GC threads

Concurrent GC: collector runs at the same time as the applicationDoes not stop the world

Our focus: concurrent compaction!

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 12 / 30

Page 13: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4

Outline

1 Background

2 Continuously Concurrent Compacting Collector (C4)

3 Field Pinning Protocol

4 Conclusions

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 13 / 30

Page 14: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4

Continuously Concurrent Compacting Collector (C4)

Researchers: G. Tene, B. Iyengar, and M. Wolf at Azul Systems

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 14 / 30

Page 15: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4 Explanation

Loaded Value Barrier (LVB)

Read Barrier: instructions to run before a thread accesses memory

LVB protects from-space from application threadsFrom-space: where objects were located before moving

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 15 / 30

Page 16: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4 Explanation

Loaded Value Barrier (LVB)

Rule: application can only use moved objectsIf a thread breaks this, the barrier will correct the situation

This facilitates concurrent relocation and remapping

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 15 / 30

Page 17: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4 Explanation

Concurrent Relocation

GC threads simply relocate objects

All references point to from-space!Application threads certain to trigger LVB

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 16 / 30

Page 18: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4 Explanation

Concurrent Relocation

LVB instructions for applications threadsIf the object was moved, find itIf the object is being moved, waitIf the object is unmoved, move it

In all cases, update the reference after using the object in to-space

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 16 / 30

Page 19: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4 Explanation

Concurrent Remapping

To update all references, need to traverse all reachable ones

Combine remapping with next tracing phase

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 17 / 30

Page 20: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4 Test Results

Testing Environment

Tested against two collectors with non-concurrent compaction

Improvements from concurrent compaction

Server environments used

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 18 / 30

Page 21: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

C4 Test Results

Results

C4:Fastest response timesMaintains them for largestrange of heap sizesLeast impact on application

Worst Case Response Times

C4

Serial

Serial

Heap Size (Gb)0 5 10 15 20 25 30 35

10

1

0.1

0.01

Wor

st C

ase

Res

pons

e T

imes

(se

cs)

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 19 / 30

Page 22: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP

Outline

1 Background

2 Continuously Concurrent Compacting Collector (C4)

3 Field Pinning Protocol

4 Conclusions

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 20 / 30

Page 23: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP

Field Pinning Protocol (FPP)

Implemented into a host GC algorithm

Differs from C4 - barrier-free!

Researchers: E. Österlund and W. Löwe at Linnaeus University

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 21 / 30

Page 24: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Hazard Pointers

Hazard Pointers: values that show which objects an application threadis accessing

Inform other threads of objects that are in use

Main goal: safely access objects without worrying about relocation

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 22 / 30

Page 25: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Example

Object = CoffeeApplication Thread =Person w/ Coffee Cup

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 23 / 30

Page 26: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Example

Object = CoffeeApplication Thread =Person w/ Coffee CupRelocation Thread =Person* = Responsible! = Impeded

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 23 / 30

Page 27: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Example

Object = CoffeeApplication Thread =Person w/ Coffee CupRelocation Thread =Person* = Responsible! = Impeded

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 23 / 30

Page 28: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Example

Object = CoffeeApplication Thread =Person w/ Coffee CupRelocation Thread =Person* = Responsible! = Impeded

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 23 / 30

Page 29: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Example

Object = CoffeeApplication Thread =Person w/ Coffee CupRelocation Thread =Person* = Responsible! = Impeded

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 23 / 30

Page 30: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Example

Object = CoffeeApplication Thread =Person w/ Coffee CupRelocation Thread =Person* = Responsible! = Impeded

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 23 / 30

Page 31: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Explanation

Concurrent Relocation and Responsibility

Responsibility: thread required to try relocating an objectComes from hazard pointers (coffee cups) impeding copying

Relocation with FPPGC threads attempt to relocate objectsImpeding application threads are made responsible

When finished with the object, try to move

Responsibility passed to impeding threads until relocationsucceeds

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 24 / 30

Page 32: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Test Results

Testing Environment

Implemented in the Garbage-First (G1) Garbage CollectorConcurrent tracing and remappingRelocation requires stop-the-world pauses

Tested against the default G1 collector

Improvements from solely concurrent relocation

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 25 / 30

Page 33: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

FPP Test Results

Results

G1 with FPP on average50% shorter delays thanstandard G1

Less impact onapplicationperformance

Concurrent relocationwithout barriers is feasible!

Benchmark G1 G1 w/ FPPpmd 40.82 ms 5.02 mslusearch 2.73 ms 2.72 mstomcat 12.31 ms 5.48 mstradebeans 31.73 ms 11.81 msfop 37.39 ms 13.22 ms

Table: Average GC Delays

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 26 / 30

Page 34: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Conclusions

Outline

1 Background

2 Continuously Concurrent Compacting Collector (C4)

3 Field Pinning Protocol

4 Conclusions

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 27 / 30

Page 35: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Conclusions

Conclusions

Moving toward concurrent compaction without barriersC4 - heavily relies on barriersFPP - barrier-free

Tough to compare them directly

All tests showed that concurrency can improve applicationperformance

Approach used will depend on intended environment

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 28 / 30

Page 36: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

Conclusions

Thanks for your time!

Questions?

Contact: [email protected]

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 29 / 30

Page 37: Concurrent Compaction in JVM Garbage Collection · Garbage Collection Parallel Processing Garbage Collection with Parallel Processing 2 Continuously Concurrent Compacting Collector

References

References

G. Tene, B. Iyengar, and M. Wolf.C4: the continuously concurrent compacting collector.2011 ACM SIGPLAN International Symposium on MemoryManagement (ISMM 2011). ACM, New York, NY, USA, 79-88.

E. Österlund and W. Löwe.Concurrent compaction using a field pinning protocol.2015 ACM SIGPLAN International Symposium on MemoryManagement (ISMM 2015). ACM, New York, NY, USA, 56-69.

See the UMM Opdahl Fall ’15 paper for additional references.

Jacob Opdahl (UMM) Concurrent Compaction in JVM GC December 5, 2015 30 / 30