1 /*
 2  * Copyright (c) 2015, 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_G1_G1CODEBLOBCLOSURE_HPP
26 #define SHARE_GC_G1_G1CODEBLOBCLOSURE_HPP
27 
28 #include "gc/g1/g1CollectedHeap.hpp"
29 #include "memory/iterator.hpp"
30 
31 class G1ConcurrentMark;
32 class nmethod;
33 
34 class G1CodeBlobClosure : public CodeBlobClosure {
35   // Gather nmethod remembered set entries.
36   class HeapRegionGatheringOopClosure : public OopClosure {
37     G1CollectedHeap* _g1h;
38     OopClosure* _work;
39     nmethod* _nm;
40 
41     template <typename T>
42     void do_oop_work(T* p);
43 
44   public:
45     HeapRegionGatheringOopClosure(OopClosure* oc) : _g1h(G1CollectedHeap::heap()), _work(oc), _nm(NULL) {}
46 
47     void do_oop(oop* o);
48     void do_oop(narrowOop* o);
49 
50     void set_nm(nmethod* nm) {
51       _nm = nm;
52     }
53   };
54 
55   // Mark all oops below TAMS.
56   class MarkingOopClosure : public OopClosure {
57     G1ConcurrentMark* _cm;
58     uint _worker_id;
59 
60     template <typename T>
61     void do_oop_work(T* p);
62 
63   public:
64     MarkingOopClosure(uint worker_id);
65 
66     void do_oop(oop* o);
67     void do_oop(narrowOop* o);
68   };
69 
70   HeapRegionGatheringOopClosure _oc;
71   MarkingOopClosure _marking_oc;
72 
73   bool _strong;
74 public:
75   G1CodeBlobClosure(uint worker_id, OopClosure* oc, bool strong) :
76     _oc(oc), _marking_oc(worker_id), _strong(strong) { }
77 
78   void do_evacuation_and_fixup(nmethod* nm);
79   void do_marking(nmethod* nm);
80 
81   void do_code_blob(CodeBlob* cb);
82 };
83 
84 #endif // SHARE_GC_G1_G1CODEBLOBCLOSURE_HPP