Igor Dmitriev: "Java behind the scenes"

Preview:

Citation preview

JavaBehindTheScenes

IgorDmitriev#LTSLogeekNight,Kyiv 2016

IgorDmitrievihor.dmitriiev@gmail.comihor_dmitriievihor_dmitriievigor-dmitriev-3a29b15a

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

Delombok

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

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

-  SparsecollecIons,capacityis2Imesormorethanwhatyouneed

jdk1.7.0_40ArrayList

jdk1.7.0_40HashMap

jdk1.8.0_25HashMap

jdk1.8.0_b132HashMap

hashcollision

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

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

Non-comparableClient

HashMapWhen?

How?ComparableComparableisused

Non-comparableIfkeyclassesareequal–idenItyHashCode,otherwise-className.compareTo

Whydowegetatreewhenweadd11element?

ConcurrentHashMapjdk1.7.0_40

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

jdk1.8.0_25Changes-  Nolongerhassegments-linkedarray-  Balancedtreeinsteadoflinkedlistforhugecollisions

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