View
154
Download
5
Category
Preview:
Citation preview
GC W JVM (i nie tylko)Witold Bot witold.bolt@jitsolutions.pl
MEMORY OVERVIEw
12nMACHINE
12n
12nOPERATING SYSTEMPROC#1PROC#2
mallocfree
JVMstackheapnativemetaGCmeta GCmalloc/freestack :)
JVM HEAPEdenS0S1tenured / old
TLAB
SURVIVAL
YOUNGOLDWTF?!
Note:Heap size is limited-Xms -XmxResize possible during runtime,but it is discouraged!
MOTIVATIONUltra fast allocation - faster than C/C++Optimized for many, short-time objects on the heapOptimized for threadingOptimized for small objectsSEEMS LEGIT?
JVM HEAPedenS0S1tenured / old
TLABSURVIVAL
YOUNGOLDGC goal: keep eden empty and move living to S0/S1 or OLDGC goal: kill non-living, defragmentation (optional)WHO IS ALIVE?!
HOW TO FIND THE LIVING?ReferencesReference countingReachability graphGC rootsgraph visiting / traveling algorithm
CRAZY REFERENCESMore than you think!
JVM REFERENCESStandard / strong referenceWeak referenceSoft referencePhantom reference (scary!)
What are the use cases?
The AlgorithmsWhat can go wrong?!
GC ALGORITHMSSerial
(-XX:+UseSerialGC)
Parallel(XX:+UseParallelGC)
ParallelOld(XX:+UseParallelOldGC)
STOP!stackoverflow.com/questions/16695874/why-jvm-full-gc-need-stop-the-world
GC ALGORITHMSSerial
(-XX:+UseSerialGC)
Parallel(XX:+UseParallelGC)
ParallelOld(XX:+UseParallelOldGC)
Concurrent Mark & Sweep(-XX:+UseConcMarkSweepGC)
Garbage First (G1)(-XX:+UseG1GC)
GC ALGORITHMSSerial
Parallel
ParallelOld
Concurrent Mark and Sweep (CMS)
Garbage First (G1)ThroughtputLatency
GC TASKSIdentify reachable / non-reachable objectsMove (copy memory) reachable objectsEmpty Eden and S0/S1Deallocate non-reachable objectsDESTRUCTORS IN Java?
FINALIZE()
Finalize methodGoal of this methodWhy it is evil?Try-catch-finally
Try this at home: @Overrideprotected void finalize() throws Throwable {super.finalize();Thread.sleep(10000);}
Controlling GC?When does GC runs?System.gc() / -XX:+DisableExplicitGCOutOfMemoryErrorGet memory / GC infoRuntime.getRuntime().totalMemory() / .freeMemory() / .maxMemory() Logs (-verbose:gc, -XX:+PrintGC, -XX:+PrintGCDetails)Monitoring (jstat, VisualVM )
Collections need memory!
Java CollectionsOne of the key elements for building any logicIn most cases can grow dynamicallyWhat is the memory overhead?How growing is implemented?Can we do anything?
is the root of all evil!
Questions?Witold Bot (witold.bolt@jitsolutions.pl)
Zapraszamy na InfoShare18-20 maja 2016, AmberExpo
Zatrudniamy!rekrutacja@jitsolutions.plCV po polsku lub angielskuKogo szukamy?Java developer (wszystkie poziomy)PL/SQL developerQA / testerzy (automaty i manualne)
Questions?Witold Bot (witold.bolt@jitsolutions.pl)
Thanks for watchingWitold Bot (witold.bolt@jitsolutions.pl)
Recommended