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