1 /*
   2  * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 // The VM_CMS_Operation is slightly different from
  26 // a VM_GC_Operation -- and would not have subclassed easily
  27 // to VM_GC_Operation without several changes to VM_GC_Operation.
  28 // To minimize the changes, we have replicated some of the VM_GC_Operation
  29 // functionality here. We will consolidate that back by doing subclassing
  30 // as appropriate in Dolphin.
  31 //
  32 //  VM_Operation
  33 //    VM_CMS_Operation
  34 //    - implements the common portion of work done in support
  35 //      of CMS' stop-world phases (initial mark and remark).
  36 //
  37 //      VM_CMS_Initial_Mark
  38 //      VM_CMS_Final_Mark
  39 //
  40 
  41 // Forward decl.
  42 class CMSCollector;
  43 
  44 class VM_CMS_Operation: public VM_Operation {
  45  protected:
  46   CMSCollector*  _collector;                 // associated collector
  47   bool           _prologue_succeeded;     // whether doit_prologue succeeded
  48 
  49   bool lost_race() const;
  50 
  51   // java.lang.ref.Reference support
  52   void acquire_pending_list_lock();
  53   void release_and_notify_pending_list_lock();
  54 
  55  public:
  56   VM_CMS_Operation(CMSCollector* collector):
  57     _collector(collector),
  58     _prologue_succeeded(false) {}
  59   ~VM_CMS_Operation() {}
  60 
  61   // The legal collector state for executing this CMS op.
  62   virtual const CMSCollector::CollectorState legal_state() const = 0;
  63 
  64   // Whether the pending list lock needs to be held
  65   virtual const bool needs_pll() const = 0;
  66 
  67   // Execute operations in the context of the caller,
  68   // prior to execution of the vm operation itself.
  69   virtual bool doit_prologue();
  70   // Execute operations in the context of the caller,
  71   // following completion of the vm operation.
  72   virtual void doit_epilogue();
  73 
  74   virtual bool evaluate_at_safepoint() const { return true; }
  75   virtual bool is_cheap_allocated() const { return false; }
  76   virtual bool allow_nested_vm_operations() const  { return false; }
  77   bool prologue_succeeded() const { return _prologue_succeeded; }
  78 
  79   void verify_before_gc();
  80   void verify_after_gc();
  81 };
  82 
  83 
  84 // VM_CMS_Operation for the initial marking phase of CMS.
  85 class VM_CMS_Initial_Mark: public VM_CMS_Operation {
  86  public:
  87   VM_CMS_Initial_Mark(CMSCollector* _collector) :
  88     VM_CMS_Operation(_collector) {}
  89 
  90   virtual VMOp_Type type() const { return VMOp_CMS_Initial_Mark; }
  91   virtual void doit();
  92 
  93   virtual const CMSCollector::CollectorState legal_state() const {
  94     return CMSCollector::InitialMarking;
  95   }
  96 
  97   virtual const bool needs_pll() const {
  98     return false;
  99   }
 100 };
 101 
 102 // VM_CMS_Operation for the final remark phase of CMS.
 103 class VM_CMS_Final_Remark: public VM_CMS_Operation {
 104  public:
 105   VM_CMS_Final_Remark(CMSCollector* _collector) :
 106     VM_CMS_Operation(_collector) {}
 107   virtual VMOp_Type type() const { return VMOp_CMS_Final_Remark; }
 108   virtual void doit();
 109 
 110   virtual const CMSCollector::CollectorState legal_state() const {
 111     return CMSCollector::FinalMarking;
 112   }
 113 
 114   virtual const bool needs_pll() const {
 115     return true;
 116   }
 117 };
 118 
 119 
 120 // VM operation to invoke a concurrent collection of the heap as a
 121 // GenCollectedHeap heap.
 122 class VM_GenCollectFullConcurrent: public VM_GC_Operation {
 123  public:
 124   VM_GenCollectFullConcurrent(unsigned int gc_count_before,
 125                               unsigned int full_gc_count_before,
 126                               GCCause::Cause gc_cause)
 127     : VM_GC_Operation(gc_count_before, full_gc_count_before, true /* full */) {
 128     _gc_cause = gc_cause;
 129     assert(FullGCCount_lock != NULL, "Error");
 130     assert(UseAsyncConcMarkSweepGC, "Else will hang caller");
 131   }
 132   ~VM_GenCollectFullConcurrent() {}
 133   virtual VMOp_Type type() const { return VMOp_GenCollectFullConcurrent; }
 134   virtual void doit();
 135   virtual void doit_epilogue();
 136   virtual bool is_cheap_allocated() const { return false; }
 137   virtual bool evaluate_at_safepoint() const;
 138 };