Operating System
– Java Virtual
– Machine
–
–
–
–
Hardware
–
–
–
–
–
–
Class (.class) File Class Loader
Runtime Data Areas
Java Native
Method Code
Heap Thread Method PC Registers
Area Cache
Stacks Stacks
Execution JIT Compiler / Garbage Native Native
Method Method
Engine Interpreter Collector Libraries
Interface
Runtime
Object Object Constant Method nmethods
Pool Code
Object
nmethods
Object Field Method
Object Data Data
Heap Method Area
Thread 3
Thread 1 Thread 1 Thread 2 Thread 3
Stack Frame
Thread 2
Native
Thread 3 Stack Frame Stack Frame Stack Frame Method
Stacks
PC Registers Java Thread Stacks Native Area
Thread
PC Register
Metadata
Stack Frame
Runtime
Local Variable Array Constant Pool
Return Value Operand Stack Reference
Runtime Constant Pool
Field Data
Constant Class
Constant FieldRef
Constant MethodRef
Constant String Method Data
Constant Integer
Constant Float
.. Method Code
Operating System
Java JVM
Source
Code Class Loader
Java Runtime Data Areas
Compiler
Execution JIT
Interpreter
Java Engine Compiler
Bytecode
Hardware
Linking
Loading Verifying
Preparing
Resolving Initializing
–
Bootstrap
Class Loader
Launcher$ExtClassLoader
Launcher$AppClassLoader
ClassLoader
User Defined User Defined
Class Loader Class Loader
Java Memory Model
Heap Method Area Native Area
Runtime Field &
Old Method Native
Young Generation Constant Method Code Cache MMAP
Generation Code Stack
Pool Data
Eden Survivor 0 Survivor 1
–
Runtime
Local Variable Array Constant Pool
Return Value Operand Stack Reference
– Thread
PC Register
Stack Frame
Heap Space
Young Generation Old Generation
From To
Eden
Survivor Survivor Tenured
–
Method Area
Permanent Generation
Runtime Constant Pool
–
Field & Method Data
Method Code
Heap Space Method Area Native Area
Young Generation Old Generation Permanent Generation
Code Cache
Runtime Constant Pool
MMAP
From To
Eden
Survivor Survivor Tenured Field & Method Data
Method Code Native Stack
–
–
Method Area Native Area
Permanent Generation
Runtime Constant Pool Metaspace
Field & Method Data
Compressed
Method Code
Class Space *
–
Native Area
Code Cache
–
–
–
Used Memory Free Memory Unalocated
- object instances, etc - - ready for allocation - Memory
–
–
–
–
–
–
–
Maximum Java stack size
PermGen replacement
Non-reachable
objects - Garbage
–
–
– Reachable
objects
–
–
GC Roots
–
–
allocations
Minor GC Young
Generation
promotions
Major / Full GC
Old
Generation
Permanent Generation /
Metaspace
Eden
allocations
Young
Generation
From To
Survivor Survivor
Old
Generation
after Minor GC
Eden
Young
Generation
From To
Survivor Survivor
swap
Old
Generation
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
long start = System.nanoTime();
/* Code to be measured */
long end = System.nanoTime();
long elapsed = end - start;
–
–
–
–
–
synchronized (object) {
/* critical section */
}
synchronized (object) {
{ /* critical section */
/* non-critical section */ /* non-critical section */
} /* critical section */
}
synchronized (object) {
/* critical section */
}
–
Thread 1 Thread 1
synchronized (A) { synchronized (B) {
/* critical section */ /* critical section */
} }
OS mutex / conditional variables
lock A lock B
Atomic operations (CAS)
Heap Stack Register Heap Stack Register
newly compiled: f() + g()
context: f(), g()
context: f() + g()
values of locals: f(), g()
values of locals: f() + g()
function: g()
locals: []
function: f() function: f() + g()
locals: [i, j] locals: [i, j]
... ...
Space Address
Native Memory Buffer
Java Heap
–
Java Byte Array
–
non-direct
java.nio.ByteBuffer
direct
java.nio.ByteBuffer
–
–
1. log.debug("First argument = [" + arg1 + "], second argument = [" + arg2 + "], third argument = [" + arg3 + "]");
2. if (log.isDebugEnabled()) {
log.debug("First argument = [" + arg1 + "], second argument = [" + arg2 + "], third argument = [" + arg3 + "]");
}
3. if (log.isDebugEnabled()) {
log.debug("First argument = [{}], second argument = [{}], third argument = [{}]", arg1, arg2, arg3);
}
4. log.debug("First argument = [{}], second argument = [{}], third argument = [{}]", arg1, arg2, arg3);
5. log.debug(() -> "First argument = [" + arg1 + "], second argument = [" + arg2 + "], third argument = [" + arg3 + "]");
public void debug(String format, Object arg) {
if (logger.isDebugEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg);
logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable());
}
}