1/*
2 * Copyright (c) 2005, 2019, 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#ifndef SHARE_GC_CMS_CMSVMOPERATIONS_HPP
26#define SHARE_GC_CMS_CMSVMOPERATIONS_HPP
27
28#include "gc/cms/concurrentMarkSweepGeneration.hpp"
29#include "gc/shared/gcCause.hpp"
30#include "gc/shared/gcId.hpp"
31#include "gc/shared/gcVMOperations.hpp"
32#include "runtime/vmOperations.hpp"
33
34// The VM_CMS_Operation is slightly different from
35// a VM_GC_Operation -- and would not have subclassed easily
36// to VM_GC_Operation without several changes to VM_GC_Operation.
37// To minimize the changes, we have replicated some of the VM_GC_Operation
38// functionality here. We will consolidate that back by doing subclassing
39// as appropriate in Dolphin.
40//
41// VM_Operation
42// VM_CMS_Operation
43// - implements the common portion of work done in support
44// of CMS' stop-world phases (initial mark and remark).
45//
46// VM_CMS_Initial_Mark
47// VM_CMS_Final_Mark
48//
49
50// Forward decl.
51class CMSCollector;
52
53class VM_CMS_Operation: public VM_Operation {
54 protected:
55 CMSCollector* _collector; // associated collector
56 bool _prologue_succeeded; // whether doit_prologue succeeded
57 uint _gc_id;
58
59 bool lost_race() const;
60
61 public:
62 VM_CMS_Operation(CMSCollector* collector):
63 _collector(collector),
64 _prologue_succeeded(false),
65 _gc_id(GCId::current()) {}
66 ~VM_CMS_Operation() {}
67
68 // The legal collector state for executing this CMS op.
69 virtual const CMSCollector::CollectorState legal_state() const = 0;
70
71 // Whether the pending list lock needs to be held
72 virtual const bool needs_pending_list_lock() const = 0;
73
74 // Execute operations in the context of the caller,
75 // prior to execution of the vm operation itself.
76 virtual bool doit_prologue();
77 // Execute operations in the context of the caller,
78 // following completion of the vm operation.
79 virtual void doit_epilogue();
80
81 virtual bool evaluate_at_safepoint() const { return true; }
82 virtual bool is_cheap_allocated() const { return false; }
83 virtual bool allow_nested_vm_operations() const { return false; }
84 bool prologue_succeeded() const { return _prologue_succeeded; }
85
86 void verify_before_gc();
87 void verify_after_gc();
88};
89
90
91// VM_CMS_Operation for the initial marking phase of CMS.
92class VM_CMS_Initial_Mark: public VM_CMS_Operation {
93 public:
94 VM_CMS_Initial_Mark(CMSCollector* _collector) :
95 VM_CMS_Operation(_collector) {}
96
97 virtual VMOp_Type type() const { return VMOp_CMS_Initial_Mark; }
98 virtual void doit();
99
100 virtual const CMSCollector::CollectorState legal_state() const {
101 return CMSCollector::InitialMarking;
102 }
103
104 virtual const bool needs_pending_list_lock() const {
105 return false;
106 }
107};
108
109// VM_CMS_Operation for the final remark phase of CMS.
110class VM_CMS_Final_Remark: public VM_CMS_Operation {
111 public:
112 VM_CMS_Final_Remark(CMSCollector* _collector) :
113 VM_CMS_Operation(_collector) {}
114 virtual VMOp_Type type() const { return VMOp_CMS_Final_Remark; }
115 virtual void doit();
116
117 virtual const CMSCollector::CollectorState legal_state() const {
118 return CMSCollector::FinalMarking;
119 }
120
121 virtual const bool needs_pending_list_lock() const {
122 return true;
123 }
124};
125
126
127// VM operation to invoke a concurrent collection of the heap as a
128// GenCollectedHeap heap.
129class VM_GenCollectFullConcurrent: public VM_GC_Operation {
130 public:
131 VM_GenCollectFullConcurrent(uint gc_count_before,
132 uint full_gc_count_before,
133 GCCause::Cause gc_cause)
134 : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true /* full */)
135 {
136 assert(FullGCCount_lock != NULL, "Error");
137 }
138 ~VM_GenCollectFullConcurrent() {}
139 virtual VMOp_Type type() const { return VMOp_GenCollectFullConcurrent; }
140 virtual void doit();
141 virtual void doit_epilogue();
142 virtual bool is_cheap_allocated() const { return false; }
143 virtual bool evaluate_at_safepoint() const;
144};
145
146#endif // SHARE_GC_CMS_CMSVMOPERATIONS_HPP
147