tech talks annual 2015 kees jan koster_how to allocate an object in 10 nanoseconds
TRANSCRIPT
Kees Jan Koster [email protected]
new Object();as quick as updating a pointer…
Kees Jan Koster [email protected]
old generationeden survivor spaces
scavenger minor gc
mark-sweep full gc
Kees Jan Koster [email protected]
Kees Jan Koster [email protected]
throughput garbage collector (-XX:+UseParallelGC -XX:+UseParallelOldGC)
* compacting (no unexpected long pauses)* relatively low CPU overhead* uses multiple cores to collect
CPU bound (batch) application?
yesserial garbage collector (-XX:+UseSerialGC)
* short pauses since the heap is tiny* compacting (no unexpected long pauses)* low CPU overhead
heap <= 128 MBand/or
single CPU?
G1 collector (-XX:+UseG1GC)
* concurrent GC, normally low pauses* non-compacting (may cause long pauses)* high CPU overhead
CMS collector (-XX:+UseConcMarkSweepGC -XX:+UseParNewGC)
* concurrent GC, normally low pauses* non-compacting (may cause long pauses)* high CPU overhead
heap <= 4GB
no
no
no
yes
yes
objective: - pick the most likely GC candidate
pick the right heap size for your application
Kees Jan Koster [email protected]
throughput garbage collector (-XX:+UseParallelGC -XX:+UseParallelOldGC)
* compacting (no unexpected long pauses)* relatively low CPU overhead* uses multiple cores to collect
CPU bound (batch) application?
yesserial garbage collector (-XX:+UseSerialGC)
* short pauses since the heap is tiny* compacting (no unexpected long pauses)* low CPU overhead
heap <= 128 MBand/or
single CPU?
G1 collector (-XX:+UseG1GC)
* concurrent GC, normally low pauses* non-compacting (may cause long pauses)* high CPU overhead
CMS collector (-XX:+UseConcMarkSweepGC -XX:+UseParNewGC)
* concurrent GC, normally low pauses* non-compacting (may cause long pauses)* high CPU overhead
heap <= 4GB
no
no
no
yes
yes
objective: - pick the most likely GC candidate
pick the right heap size for your application
Kees Jan Koster [email protected]
throughput garbage collector (-XX:+UseParallelGC -XX:+UseParallelOldGC)
* compacting (no unexpected long pauses)* relatively low CPU overhead* uses multiple cores to collect
CPU bound (batch) application?
yesserial garbage collector (-XX:+UseSerialGC)
* short pauses since the heap is tiny* compacting (no unexpected long pauses)* low CPU overhead
heap <= 128 MBand/or
single CPU?
G1 collector (-XX:+UseG1GC)
* concurrent GC, normally low pauses* non-compacting (may cause long pauses)* high CPU overhead
CMS collector (-XX:+UseConcMarkSweepGC -XX:+UseParNewGC)
* concurrent GC, normally low pauses* non-compacting (may cause long pauses)* high CPU overhead
heap <= 4GB
no
no
no
yes
yes
objective: - pick the most likely GC candidate
pick the right heap size for your application
Kees Jan Koster [email protected]
old generationeden
synchronized (pointer) {pointer += bytesToAllocate;
}
Kees Jan Koster [email protected]
CPU CPU CPU
main memory acces time ~200 clock cycles
cache ~15 clks cache ~15 clks cache ~15 clks
http://gotocon.com/dl/jaoo-aarhus-2009/slides/BrianGoetz_TheConcurrencyRevolutionTheHardwareStory.pdf
Kees Jan Koster [email protected]
http://www.javaspecialists.eu/archive/Issue179.html
private static long test() {long total = 0;for (int i = 0; i < 10000; i++) {
CalculatorVarArgs calc = new CalculatorVarArgs();total += calc.add(i, i / 2);
}return total;
}
Kees Jan Koster [email protected]
https://blog.codecentric.de/en/2014/08/string-deduplication-new-feature-java-8-update-20-2/
-XX:+UseG1GC -XX:+UseStringDeduplication
"foo";"bar";"foo and bar";"bar";"bar";"foo";
"bar";"foo and bar";
"foo";
Kees Jan Koster [email protected]
pointer += bytesToAllocate;
Kees Jan Koster [email protected]
+31651838192