hotspot/src/share/vm/gc/shared/preservedMarks.hpp
changeset 37422 8a7443b5edf8
parent 37045 41e3f98fa3dc
child 38080 bb02a3ad3b0a
equal deleted inserted replaced
37421:505b09d74f49 37422:8a7443b5edf8
    42     _o->set_mark(_m);
    42     _o->set_mark(_m);
    43   }
    43   }
    44 };
    44 };
    45 typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack;
    45 typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack;
    46 
    46 
       
    47 class WorkGang;
       
    48 
    47 class PreservedMarks VALUE_OBJ_CLASS_SPEC {
    49 class PreservedMarks VALUE_OBJ_CLASS_SPEC {
    48 private:
    50 private:
    49   OopAndMarkOopStack _stack;
    51   OopAndMarkOopStack _stack;
    50 
    52 
    51   inline bool should_preserve_mark(oop obj, markOop m) const;
    53   inline bool should_preserve_mark(oop obj, markOop m) const;
    52   inline void push(oop obj, markOop m);
    54   inline void push(oop obj, markOop m);
    53 
    55 
    54 public:
    56 public:
    55   bool is_empty() const { return _stack.is_empty(); }
       
    56   size_t size() const { return _stack.size(); }
    57   size_t size() const { return _stack.size(); }
    57   inline void push_if_necessary(oop obj, markOop m);
    58   inline void push_if_necessary(oop obj, markOop m);
    58   // Iterate over the stack, restore the preserved marks, then reclaim
    59   // Iterate over the stack, restore all preserved marks, and
    59   // the memory taken up by stack chunks.
    60   // reclaim the memory taken up by the stack segments.
    60   void restore();
    61   void restore();
    61   ~PreservedMarks() { assert(is_empty(), "should have been cleared"); }
    62 
       
    63   inline static void init_forwarded_mark(oop obj);
       
    64 
       
    65   // Assert the stack is empty and has no cached segments.
       
    66   void assert_empty() PRODUCT_RETURN;
       
    67 
       
    68   inline PreservedMarks();
       
    69   ~PreservedMarks() { assert_empty(); }
    62 };
    70 };
    63 
    71 
    64 class RemoveForwardedPointerClosure: public ObjectClosure {
    72 class RemoveForwardedPointerClosure: public ObjectClosure {
    65 public:
    73 public:
    66   virtual void do_object(oop obj);
    74   virtual void do_object(oop obj);
    80   // Stack array (typically, one stack per GC worker) of length _num.
    88   // Stack array (typically, one stack per GC worker) of length _num.
    81   // This should be != NULL if the stacks have been initialized,
    89   // This should be != NULL if the stacks have been initialized,
    82   // or == NULL if they have not.
    90   // or == NULL if they have not.
    83   Padded<PreservedMarks>* _stacks;
    91   Padded<PreservedMarks>* _stacks;
    84 
    92 
       
    93   // Internal version of restore() that uses a WorkGang for parallelism.
       
    94   void restore_internal(WorkGang* workers, volatile size_t* total_size_addr);
       
    95 
    85 public:
    96 public:
       
    97   uint num() const { return _num; }
       
    98 
    86   // Return the i'th stack.
    99   // Return the i'th stack.
    87   PreservedMarks* get(uint i = 0) const {
   100   PreservedMarks* get(uint i = 0) const {
    88     assert(_num > 0 && _stacks != NULL, "stacks should have been initialized");
   101     assert(_num > 0 && _stacks != NULL, "stacks should have been initialized");
    89     assert(i < _num, "pre-condition");
   102     assert(i < _num, "pre-condition");
    90     return (_stacks + i);
   103     return (_stacks + i);
    91   }
   104   }
    92 
   105 
    93   // Allocate stack array.
   106   // Allocate stack array.
    94   void init(uint num);
   107   void init(uint num);
    95   // Iterate over all stacks, restore all preserved marks, then
   108 
    96   // reclaim the memory taken up by stack chunks.
   109   // Itrerate over all stacks, restore all presered marks, and reclaim
       
   110   // the memory taken up by the stack segments. If the executor is
       
   111   // NULL, restoration will be done serially. If the executor is not
       
   112   // NULL, restoration could be done in parallel (when it makes
       
   113   // sense). Supported executors: WorkGang (Serial, CMS, G1)
       
   114   template <class E>
       
   115   inline void restore(E* executor);
       
   116 
       
   117   // Do the restoration serially. Temporary, to be used by PS until we
       
   118   // can support GCTaskManager in restore(E*).
    97   void restore();
   119   void restore();
       
   120 
    98   // Reclaim stack array.
   121   // Reclaim stack array.
    99   void reclaim();
   122   void reclaim();
   100 
   123 
   101   // Assert all the stacks are empty.
   124   // Assert all the stacks are empty and have no cached segments.
   102   void assert_empty() PRODUCT_RETURN;
   125   void assert_empty() PRODUCT_RETURN;
   103 
   126 
   104   PreservedMarksSet(bool in_c_heap)
   127   PreservedMarksSet(bool in_c_heap)
   105       : _in_c_heap(in_c_heap), _num(0), _stacks(NULL) { }
   128       : _in_c_heap(in_c_heap), _num(0), _stacks(NULL) { }
   106 
   129