Reference Object Processing in On-The-Fly Garbage Collection

Reference Object Processing in On-The-Fly Garbage Collection

Reference Object Processing in On-The-Fly Garbage Collection Tomoharu Ugawa, Kochi University of Technology Richard Jones, Carl Ritson, University of Kent Weak Pointers • Weak pointers are a mechanism to allow mutators to communicate with GC • java.lang.ref.Reference • Specification requires us to process weak references atomically from the view point of mutators • Fully concurrent (on-the-fly) GC never stops all mutators Java reference types stronger • Strong - usual references. • Soft - used for caches that the GC can reclaim. • Weak - used for canonicalize mappings (e.g., interned strings) that do not prevent GC from reclaiming their keys or values. • Phantom - used for scheduling pre-mortem cleanup actions more flexibility than finalisers. weaker Java reference types stronger • Strong - usual references. • Soft - used for caches that the GC can reclaim. reduce to strong/weak references • Weak - used for canonicalize mapping (e.g., interned strings) that do not prevent GC from reclaiming their keys or values. • Phantom - used for scheduling pre-mortem cleanup actions more flexibility than finalisers. no interaction with mutators weaker root strongly Reachability reachable Strongly - can be reached without traversing any strong other references. reference Weakly - not strongly reachable but can be reached by traversing weak references. weak reference • No formal specification • Specification is written in English. • There are errors in implementations • We formalised the specification root strongly GC actions reachable The GC finds all strongly reachable objects and reclaims others. The GC “clears” references whose referents are weakly reachable. • Weak reference to Strongly - to be retained • Weak reference to Weakly - to be cleared root strongly Reference.get() reachable Reference Normal object object Reference.get() - returns a strong reference to its target or null if the GC has cleared. get() may make some objects that were weakly reachable strongly reachable. root strongly Reference.get() reachable Reference Normal object object get() Reference.get() - returns a strong reference to its target or null if the GC has cleared. get() may make some objects that were weakly reachable strongly reachable. Race A O B Race A O B • Collector clears weak reference A Race get() A O B • Collector clears weak reference A Race get() A O B • Collector clears weak reference A • Mutator makes O strongly reachable by creating a strong reference to the upstream from the OpenJDK mailing list “I've been tuning a Java 7u51, Solaris 10, T4 system with 24G heap. My customer is not very happy with the remark pauses of up to 2 seconds.” Thomas Viessmann “It looks like the application is using a lot of Reference objects. The time Pauses (sec) spent in remark is dominated by 2 reference processing.” Bengt Rutisson 1 blue: reference processing 0 Solutions • Stop the world - Pauseless GC [Click et al., 2005], Staccato [McCloskey et al., 2008] • Stop all mutators and process references • Lock - “On-the-fly” GC [Domani et al., 2000] • Block any mutator that calls get() • On-the-fly - Metronome-TS [Auerbach et al., 2008] • Implementation technique is not public Global GC State GC and mutator race in TRACING • GC want to finish tracing and then start clearing • Mutator force GC to do more work by collector by collector (atomic) REPEAT by mutator (atomic) get() start tracing start tracing no tracing work NORMAL TRACING CLEARING GC traces strongly reachable objects TRACING State • GC traverses strong references • to colour strongly reachable objects black Write barrier • REPEAT • insertion barrier [Dijkstra] deletion barrier (a.k.a. snapshot) [Yuasa] • NORMAL TRACING CLEARING • Read barrier for Reference.get() TRACING State • GC traverses strong references • to colour strongly reachable objects black Write barrier • REPEAT • insertion barrier [Dijkstra] deletion barrier (a.k.a. snapshot) [Yuasa] • NORMAL TRACING CLEARING • Read barrier for Reference.get() Insertion Barrier INVARIANT: Root is grey (allows root to refer to white objects) GC repeat tracing until it finds root black • REPEAT • Reference.get() changes the state to REPEAT to notify the GC that the root may not be black NORMAL TRACING CLEARING root get() Deletion Barrier INVARIANT: Root is black --- root is never rescanned Reference.get() colours target grey • REPEAT • Reference.get() changes the state to REPEAT to notify the GC that the root may not be black NORMAL TRACING CLEARING root get() CLEARING Once GC enters CLEARING state Reference.get() returns null if its target is white • REPEAT • no more objects become strongly reachable • GC clears weak references whose targets are white NORMAL TRACING CLEARING get() returns null Evaluation • Jikes RVM • Sapphire on-the-fly copying collector • Trigger GC immediately after the previous GC completes • Configuration • Core i7-4770 (4-core, 3.4 GHz) • 1 GB heap • 2 collector threads Pause Time distribution • Stop-the-world GC, or • Block mutator.get() with “lock” 100 100 100 STW STW STW lock ins lock ins lock ins lock del 10 lock del 10 lock del 10 1 1 1 avrora2009 lusearch2009 0.1 jython2006 0.1 0.1 0 6 12 18 24 30 0 6 12 18 24 30 0 6 12 18 24 30 Note 3ms logarithmic 100 100 100 buckets STW scale STW STW lock ins lock ins lock ins Frequency (%) Frequency 10 lock del 10 lock del 10 lock del 1 1 1 0.1 pmd2009 0.1 sunflow2009 0.1 xalan2009 0 6 12 18 24 30 0 6 12 18 24 30 0 6 12 18 24 30 Pause times (ms) Pause Time distribution 100 STW lock ins 10 lock del 1 0.1 xalan2009 0 6 12 18 24 30 Pause time Reference Processing Phase Time Mutators blocked Mutators running 100 100 STW OTF ins lock ins OTF del 10 10 lock del 1 1 avrora2009 0.1 0.1 0 6 12 18 24 30 0 6 12 18 24 30 100 100 STW OTF ins lock ins OTF del 10 10 lock del lusearch2009 1 1 0.1 0.1 0 30 60 90 120 150 180 210 240 270 300 0 30 60 90 120 150 180 210 240 270 300 100 100 STW OTF ins lock ins OTF del 10 lock del 10 1 1 xalan2009 0.1 0.1 0 6 12 18 24 30 0 6 12 18 24 30 Execution times Conclusion • Reference types are frequently used in a significant number of programs. • On-the-fly GC must not ignore reference types. • Formalised the definition of reference types. • On-the-fly reference processing. • Model checked with SPIN. • Implemented in Jikes RVM. • On-the-fly reference processing phases are longer in the worst case, but with deletion barrier, not by much. • Overall execution time is not increased significantly by processing references on-the-fly, and is often reduced. http://github.com/perlfu/sapphire Questions? Reference type usage 2 2 2 T = 3790ms T = 4480ms T = 3005ms pmd2009 3 1 xalan2009 1 sunflow2009 1 0 0 0 2 2 T = 4139ms T = 2651ms x-axis: 1 lusearch2009 1 luindex2009 Normalised execution time 0 0 2 2 T = 13639 T = 5112ms ms 1 1 Calls to get() per msec x 10 msec get()per Calls to Jython2006 avrora2009 0 0 Model Checking • Model checked with SPIN • Correctness: appears to mutators to be processed by GC atomically • Terminates only with deletion barrier inline getRef(i, ret) { r r r do::(refState == NORMAL || reference objects refState == REPEAT) -> o o o if::CLEARED[i] -> ret = NULL normal objects ::else -> ret = i x fi; root break ::(refState == TRACING) -> Figure 7: The model if::(!CLEARED[i] && (mark[i] == WHITE)) -> CAS(refState, TRACING, REPEAT) /* continue */ ::(!CLEARED[i] && (mark[i] != WHITE)) -> ret = i; while(true) break int i =random.nextInt{ (5); ::else -> switch (i) ret = NULL; case 0: x{ = vr .get();break; 0 break case 1: x = vr .get();break; 1 fi case 2: x = vr .get();break; 2 ::(refState == CLEANING) -> case 3: if (x = null) x = x.next; break; if::(!CLEARED[i] && (mark[i] == WHITE)) -> case 4: x =null;break;! ret = NULL } ::(!CLEARED[i] && (mark[i] != WHITE)) -> } ret = i ::else -> ret = NULL Figure 8: Simple mutator fi; break od; d_step { /* d_step is an atomic action */ since o is weakly-reachable through w,themutatormayalsoseeo, getRef_arg = i; getRef_ret = ret contrary to P2.! Since bounded model checking does not deal with infinite state, }; we checked the properties for the limited model shown in Fig. 7. } This model has three pairs of reference and normal objects, namely Figure 9: Promela model of a Reference.get() method with an r0,r1,r2 for references and o0,o1,o2 for the corresponding nor- insertion barrier mal objects. These normal objects are linked in a list, but there are no other strong references to them. We assumed that all reference objects remain directly strongly reachable from the root and that the mutator can always call get() methods on them. However, we found that, with an insertion barrier, the mutator Fig. 8 shows the mutator’s pseudocode: vri is a local variable can continually prevent the collector from breaking out of the whose value is a reference object ri,andx is another local variable. The mutator repeatedly and arbitrarily calls a get() method to load termination loop, even if we assume weakly fair scheduling. The the referent to x,loadsthe‘next’objectofx,orclearsx.Sincewe reason for this is that, while the collector is tracing or checking focus on the behaviour of references, the mutator does not write to if the work queue is empty, a mutator has a chance to load a any object. Thus, our model does not have write barriers. white referent to a local variable x and then clear x.Themutator Fig. 9 shows the model of the get() method on the reference changes refState to REPEAT when it loads a reference with get(), thus forcing the collector to trace again.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    32 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us