Experimental Tools for Serviceability Tony Printezis L ecturer Univers ity of G las gow Kenneth Russell Member of T ech S taff S un Micros ys tems
Overall Presentation Goal G et an ins ight into examining, debugging, and profiling different as pects of a J ava technology- bas ed V irtual Machine (J V M /J ava V M) us ing two new experimental tools 2
Learning Objectives A s a res ult of this pres entation, you will be convinced that: J ava V M debugging is hard! C urrent debugging tools are not always adequate T here is a need for s pecialis ed tools to help the J ava V M implementor......which might als o be us ed to help application programmers too 3
Speakers Qualifications T ony P rintezis L ecturer, Univers ity of G las gow He has been writing garbage collectors for J ava V Ms for four years K enneth R us s ell Member of tech s taff, S un Micros ys tems He has worked on the J ava HotS pot runtime and compiler for over two years 4
Bug Hunting Ain t Fun! How many all- nighters have you pulled becaus e of a bug in your native code? Now imagine debugging the G C or the J ava V M its elf... 5
Java VM Debugging Facility 6
Some Proper Debugging Tools! G C s py T ony P rintezis Heap vis ualis ation for J ava V Ms L ow impact, high level vis ualis ation J ava HotS pot S erviceability A gent K enneth R us s ell E xaminer and debugger for J ava HotS pot V M P os t mortem analys is of J ava V M 7
GCspy A daptable heap vis ualis ation framework Incorporated into s everal J ava V Ms D eveloped to vis ualis e the behaviour of G arbage C ollectors (G C s ) S calable L arge heap s izes V ery long running applications D ynamic W orks while J ava V M is executing 8
Why Heap Visualisation? G C s have (almos t) chaotic behaviour! O ne s mall change in the application behaviour can have a large effect in the G C performance G C debugging and profiling facilities S till very primitive V is ualis ation provides a convenient way to get an ins ight into the G C s behaviour D ebugging and profiling 9
Visualisation Granularity C oars e granularity Heap blocks, not objects S maller data volumes F as ter to collect / s end / s tore data B ut... L ower level of detail Information los s C an adjus t block s ize to deal with s calability and s creen s ize limitations 10
Client Server Model C lient S erver J ava V M is the s erver V is ualis er is the client F lexibility C an be run as different proces s es C an be run on different machines C an connect / dis connect the vis ualis er during J ava V M execution 12
Portability F ramework is J ava V M and G C independent B ut (s mall) modifications to the J ava V M are needed V is ualis er operates over s ome abs tractions Need to map the G C s s tate to thos e abs tractions A G C s py D river does this O nly the s erver s ide of the framework needs to be cus tomis ed 13
Architecture Server Client Java Application Visualiser Java VM S-S GC Space Space Renderer Renderer 0 1 M&C GC Data Collection S-S Driver M&C Driver Used Roots Objects Cards Marked Server Infrastructure Comms 14 Space 0 Space 1 Stream 0 Stream 1 Socket Stream 0 Stream 1 Stream 2 Client Infrastructure Comms
Performance Impact D ata collection can take a long time S everal s econds for each G C in the cas e of large heaps J ava V M performance is affected No performance penalty when the vis ualis er is not connected! 15
Trace Storing / Replaying G oal S tore trans mis s ions from a J ava V M R eplay them at a later time R eplay tool behaves e xactly like the J ava V M C ompact trace files C ompres s ion 16
Current Implementations T hree J ava technology bas ed V Ms J ava HotS pot V M S un s R es earchv M IB M s J ikes R V M A t leas t eight different G C s O ther s ys tems too Not only limited to J ava V Ms! 18
Future Work B etter, more flexible vis ualis ations O ther vis ualis ation s tyles e.g. S catter plots, His tograms R ewind facilities C onditional breakpoints 19
Java HotSpot Serviceability Agent E xaminer and debugger for J ava HotS pot virtual machine O riginally des igned for pos t mortem analys is R uns no code in target J V M R ecovers high level J ava programming language s tate 20
Motivation J ava HotS pot V M group needed better debugging tools C urrent debuggers not targeted toward debugging the J V M C /C + + debuggers R equire debug info not pres ent in product D o not unders tand J ava language, objects J ava programming language debuggers G ather information via J V M D I D o not work with cras hed J ava V Ms 21
Mechanisms J ava HotS pot S erviceability A gent (S A ) Unders tands layouts of key HotS pot data s tructures T hread lis t S tack frames C ontains code to walk thes e data s tructures D ebugger tuned for J ava HotS pot V M R ecovers s ame information as J V M D I / J D W P - bas ed debuggers 22
Features J ava programming language A P Is Implemented almos t entirely in J ava programming language A ll the way down to read proces s memory E nables cros s O S and cros s C P U debugging C an be bound to exis ting J D I interfaces in J P D A (in progres s ; more later) 23
Features F ine grained heap analys is O bject by object iteration Iteration through objects S tack walking A cces s to local variables, expres s ion s tack, monitors F allback mechanis ms for analyzing cras hes in interpreter or in compiled code 24
Architectural Diagram Target HotSpot JVM /proc dbx Socket Dbx APIs SA's Java VM import module Note that no code is being run in target J ava V M C urrent J P D A runs J V M D I- bas ed code there 25
Evolution F irs t debugger A ttach to running J V M or open core file E xamine all J V M s tate at very low level P roces s s us pended during examination T ools for developers of J V M technology S tack memory dump with annotations O bject ins pection E nd us er tools Heap dumps, livenes s analys is 26
Evolution F irs t debugger Mos t us eful to developers of J ava HotS pot technology Mos t us eful on the S olaris O perating E nvironment B uilt on dbx E s cape hatch to s ee non J V M s tate P orted to W in32 No interaction with proces s No s us pend, res ume No breakpoint s etting, exception catching 28
Observation S A built on very low level debugging primitives read proces s memory fetch thread regis ter s et S ame primitives as C /C + + debuggers W hy not extend to look at more than jus t J ava programming language s tate? 29
Extensions S A A P Is extended: F etch all O S level threads F etch all dynamically loaded objects More platform dependent J ava code : C - level s tack walking (all frames on s tack) P ars ing of C /C + + debug information E nable complete proces s examination s ys tem to be written in J ava programming language 30
Extensions F urther extens ions : R es ume/s us pend proces s P oll for event (s eg fault, etc.) S et breakpoint at machine ins truction R elatively little additional code E nable mos tly complete C /C + + debugger to be written in J ava programming language 31
Extensions C ommunication with J V M D I module S tart with - X run E nables J ava programming language breakpoint s etting and exception catching T his is the only code run in target J ava V M Mos t functionality available without it 32
Observation Now have all primitives neces s ary to build both C /C + + and J ava programming language debuggers S ys tem was originally des igned for pos t mortem analys is of J ava V M Ideally pos ed for building mixed language debugger C an handle cras hes in native code gracefully 33
Current Status E xperimental C /C + + and J ava programming language debugger has been built W ritten in J ava programming language S upports breakpoints in both C and J ava code (J ava technology bas ed code) S upports exception catching D egrades gracefully Mos t of debugger s till works even if target proces s cras hes 34
Availability S A is currently available to s ource licens ees of J ava HotS pot virtual machine 36
Future Work C omplete ports to all S un s upported platforms J D I binding in development A llow current tools to acces s J ava programming language s tate of J ava HotS pot core files via S A D is cus s prototype C /C + + debugging A P Is with tool vendors O ptional extens ions to J D I E nable all tool vendors to build mixed language debuggers 37
Presentation Summary J ava V M debugging is hard! W e pres ented two new debugging tools Heap vis ualis ation with G C s py P os t mortem analys is with the J ava HotS pot S erviceability A gent T hey are us ed by J ava V M implementors T hey operate at two different levels T hey improve debugging effectivenes s 38
Call to Action Need feedback on thes e tools and A P Is W hether they would be us eful F eatures which are needed S hould we s hip them (uns upported) F eedback on G C s py tony@dcs.gla.ac.uk F eedback on the J ava HotS pot S erviceability A gent s a- feedback@s un.com 39