This document discusses the performance improvements to the Java Virtual Machine (JVM) over time. It notes that early versions of Java from 1995-1998 had performance issues compared to modern versions and other languages due to the immaturity of JIT compilation and garbage collection techniques. The document outlines many specific performance optimizations added to the JVM over subsequent releases, such as just-in-time compilation, generational garbage collection, escape analysis, speculative optimizations, and multithreading improvements. It concludes that with these ongoing enhancements, Java now has performance on par with C/C++ in many cases and continues to improve for multicore processors.
How to Troubleshoot Apps for the Modern Connected Worker
What your jvm can do for you
1. Ask not what you can do for
your JVM, ask what your JVM
can do for you
Ett långsamt mellanlager eller har vi
någon nytta av den sett till
prestanda?
Mattias Isegran Bergander
14. Förbättringar genom åren 1.5 1.6 1.7
http://geeknizer.com/java-7-whats-new-performance-benchmark-1-5-1-6-1-7/
15. Det längre svaret...
Några uppenbara:
● GC i separat(a) tråd(ar)
● JIT kompilering i bakgrunden
● Bättre utnyttjande av CPU, i386, i586,
Core2, ..., 32/64bit, SSE/1/2/4.2
○ Ny JVM => bättre prestanda gratis
utan omkompilering
● Fler intrinsics
16. Det längre svaret...
Bättre analys ger tex:
● Null check elimination, VM behöver göra:
if (object == null) throw
new NullPointerException()
● Array bounds check elimination
0>=i && i < array.length
● Hoist duplicates & repeated use
int length = array.length;
for (int i=0;i<array.length;i++) {
if (array.length ...) {
17. Det längre svaret...
VM-lager inte bara nackdelar i prestanda:
● Pointers make optimizations hard
x = y + 2 * (...)
*p = ...
arr[j] = ...
z = x + ...
● Garbage Collection -> memory locality
● Runtime optimeringar
○ CPU, P4, Sandy Bridge, SSE, cache sizes, cores, ...
○ Current class hierarchy and inlining
○ Branch predications
19. Det längre svaret...
Några intressanta
● Virtual method inlining
● Escape Analysis (java 6u14, default enabled java7)
20. Så vad har vi nu då?
Programspråket Java hör till kategorin "de
snabba språken", tillsammans med Fortran
och C/C++
~50-100% av C/C++ prestanda
Ibland snabbare!
Quake2 vs Jake2 (Java5)
Men går utan problem att hitta fall
där C++ är snabbare...
21. Escape Analysis
Tex Dimension, Point, get/set, men inte begränsat till det...
http://weblogs.java.net/blog/forax/archive/2009/10/06/jdk7-do-escape-analysis-default
24. Generational and Copying GC
Allokera en större bit Heap i förväg
Effektivisera per tråd med trådlokalt
minne så ingen contention...
25. Generational and Copying GC
Generational:
● Young, Old (and Perm)
Young
● De flesta objekt är kortlivade, 92-98%
● Bevara (kopiera) bara de levande!
Minne:
31. February 2, 2004
Bill Venners: When I asked you earlier (In Part IV) about why non-virtual methods are the
default in C#, one of your reasons was performance. You said:
We can observe that as people write code in Java, they forget to mark their methods final.
Therefore, those methods are virtual. Because they're virtual, they don't perform as well.
There's just performance overhead associated with being a virtual method.
Another thing that happens in the adaptive optimizing JVMs is they'll inline virtual method
invocations, because a lot of times only one or two implementations are actually being used.
Anders Hejlsberg:
They can never inline a virtual method invocation.
http://www.artima.com/intv/choices.html
32. Framtiden
● Tiered compilation default?
● Disruptor pattern
● Azul ZingVM -Cliff Click
○ Scalability
○ 512GB heap
○ Pauseless Garbage Collection
● Java 8
○ Hotspot <-> JRockit
○ Mer multicore i VM och API (ForkJoin med lambda tex)
● Java 9
○ Self-tuning JVM
○ Hypervisor integration
○ Tail calls, continuations
○ "Massive multicore scalability"