34
Java Behind The Scenes Igor Dmitriev #LTS Logeek Night, Kyiv 2016

Igor Dmitriev: "Java behind the scenes"

Embed Size (px)

Citation preview

Page 1: Igor Dmitriev: "Java behind the scenes"

JavaBehindTheScenes

IgorDmitriev#LTSLogeekNight,Kyiv 2016

Page 2: Igor Dmitriev: "Java behind the scenes"

[email protected]_dmitriievihor_dmitriievigor-dmitriev-3a29b15a

Page 3: Igor Dmitriev: "Java behind the scenes"
Page 4: Igor Dmitriev: "Java behind the scenes"
Page 5: Igor Dmitriev: "Java behind the scenes"
Page 6: Igor Dmitriev: "Java behind the scenes"
Page 7: Igor Dmitriev: "Java behind the scenes"

EmptyArrayListisiniIalizedwithObjectarrayofsize10:Object[]elementData=newObject[10];

Page 8: Igor Dmitriev: "Java behind the scenes"
Page 9: Igor Dmitriev: "Java behind the scenes"
Page 10: Igor Dmitriev: "Java behind the scenes"

Delombok

Page 11: Igor Dmitriev: "Java behind the scenes"

NathanReynoldsIsanArchitectatandworksinPSR(Performance,ScalabilityandReliability),teamdedicatedtowardsopImizingOracleMiddlewaresoVware.HeistheExalogicPerformanceArchitect.In this role, he oversees the technical aspects of analyzingprofiles, figuring out opImizaIons, opImizing code andmeasuringperformanceimpact.

Page 12: Igor Dmitriev: "Java behind the scenes"

Analysed670JavaheapdumpsfromdifferentJavaprogramstofindoutmemoryhogs.Mostpopularobjects:String,char[],Object[],ArrayList,HashMapHeapusagepercollecIon:20.1%-  UnusedcollecIons-  SmallcollecIons,4orfewerelements(mostsignificantproblem)

-  SparsecollecIons,capacityis2Imesormorethanwhatyouneed

Page 13: Igor Dmitriev: "Java behind the scenes"

jdk1.7.0_40ArrayList

Page 14: Igor Dmitriev: "Java behind the scenes"
Page 15: Igor Dmitriev: "Java behind the scenes"

jdk1.7.0_40HashMap

Page 16: Igor Dmitriev: "Java behind the scenes"

jdk1.8.0_25HashMap

Page 17: Igor Dmitriev: "Java behind the scenes"

jdk1.8.0_b132HashMap

hashcollision

Page 18: Igor Dmitriev: "Java behind the scenes"
Page 19: Igor Dmitriev: "Java behind the scenes"

-Node<K,V>[]table[10]-  table.length=64-  O(n)-  Client(number)

Page 20: Igor Dmitriev: "Java behind the scenes"
Page 21: Igor Dmitriev: "Java behind the scenes"

-  Node<K,V>[]table[10]-  table.length=64-  O(logn)-  Client(number)

Page 22: Igor Dmitriev: "Java behind the scenes"
Page 23: Igor Dmitriev: "Java behind the scenes"

Non-comparableClient

Page 24: Igor Dmitriev: "Java behind the scenes"

HashMapWhen?

Page 25: Igor Dmitriev: "Java behind the scenes"

How?ComparableComparableisused

Page 26: Igor Dmitriev: "Java behind the scenes"

Non-comparableIfkeyclassesareequal–idenItyHashCode,otherwise-className.compareTo

Page 27: Igor Dmitriev: "Java behind the scenes"

Whydowegetatreewhenweadd11element?

Page 28: Igor Dmitriev: "Java behind the scenes"

ConcurrentHashMapjdk1.7.0_40

-  concurrencyLevel(default16)-  Segment-  RetrievaloperaIonsarenon-blocking-  Fail-safeiterator-  sun.misc.UnsafeisusedforconcurrencyoperaIons

Page 29: Igor Dmitriev: "Java behind the scenes"
Page 30: Igor Dmitriev: "Java behind the scenes"

jdk1.8.0_25Changes-  Nolongerhassegments-linkedarray-  Balancedtreeinsteadoflinkedlistforhugecollisions

Page 31: Igor Dmitriev: "Java behind the scenes"
Page 32: Igor Dmitriev: "Java behind the scenes"
Page 33: Igor Dmitriev: "Java behind the scenes"

UsefulreferencesJavaMemoryHogshjps://www.youtube.com/watch?v=gz4LFnOstesJavaLanguageandPlamormFutures:ASneakPeekbyBrianGoetzhjps://www.youtube.com/watch?v=oGll155-vuQАлексейШипилёв—ОчёммолчатHeapDump-ы�hjps://www.youtube.com/watch?v=r_bnfv-nlcsАлексейШипилёв—Катехизисjava.lang.String��hjps://www.youtube.com/watch?v=SZFe3m1DV1AJDKReleaseNoteshjp://www.oracle.com/technetwork/java/javase/jdk-relnotes-index-2162236.html

Page 34: Igor Dmitriev: "Java behind the scenes"