1 /*
2  * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.
3  *
4  * This code is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.
7  *
8  * This code is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCODEROOTS_HPP
25 #define SHARE_GC_SHENANDOAH_SHENANDOAHCODEROOTS_HPP
26 
27 #include "code/codeCache.hpp"
28 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
29 #include "gc/shenandoah/shenandoahLock.hpp"
30 #include "gc/shenandoah/shenandoahNMethod.hpp"
31 #include "gc/shenandoah/shenandoahPadding.hpp"
32 #include "memory/allocation.hpp"
33 #include "memory/iterator.hpp"
34 #include "utilities/globalDefinitions.hpp"
35 
36 class ShenandoahHeap;
37 class ShenandoahHeapRegion;
38 
39 class ShenandoahParallelCodeHeapIterator {
40   friend class CodeCache;
41 private:
42   CodeHeap*     _heap;
43   shenandoah_padding(0);
44   volatile int  _claimed_idx;
45   volatile bool _finished;
46   shenandoah_padding(1);
47 public:
48   ShenandoahParallelCodeHeapIterator(CodeHeap* heap);
49   void parallel_blobs_do(CodeBlobClosure* f);
50 };
51 
52 class ShenandoahParallelCodeCacheIterator {
53   friend class CodeCache;
54 private:
55   ShenandoahParallelCodeHeapIterator* _iters;
56   int                       _length;
57 
58   NONCOPYABLE(ShenandoahParallelCodeCacheIterator);
59 
60 public:
61   ShenandoahParallelCodeCacheIterator(const GrowableArray<CodeHeap*>* heaps);
62   ~ShenandoahParallelCodeCacheIterator();
63   void parallel_blobs_do(CodeBlobClosure* f);
64 };
65 
66 class ShenandoahCodeRootsIterator {
67   friend class ShenandoahCodeRoots;
68 protected:
69   ShenandoahParallelCodeCacheIterator _par_iterator;
70   ShenandoahSharedFlag _seq_claimed;
71   ShenandoahNMethodTableSnapshot* _table_snapshot;
72 
73 protected:
74   ShenandoahCodeRootsIterator();
75   ~ShenandoahCodeRootsIterator();
76 
77   template<bool CSET_FILTER>
78   void dispatch_parallel_blobs_do(CodeBlobClosure *f);
79 
80   template<bool CSET_FILTER>
81   void fast_parallel_blobs_do(CodeBlobClosure *f);
82 };
83 
84 class ShenandoahAllCodeRootsIterator : public ShenandoahCodeRootsIterator {
85 public:
ShenandoahAllCodeRootsIterator()86   ShenandoahAllCodeRootsIterator() : ShenandoahCodeRootsIterator() {};
87   void possibly_parallel_blobs_do(CodeBlobClosure *f);
88 };
89 
90 class ShenandoahCsetCodeRootsIterator : public ShenandoahCodeRootsIterator {
91 public:
ShenandoahCsetCodeRootsIterator()92   ShenandoahCsetCodeRootsIterator() : ShenandoahCodeRootsIterator() {};
93   void possibly_parallel_blobs_do(CodeBlobClosure* f);
94 };
95 
96 class ShenandoahCodeRoots : public AllStatic {
97   friend class ShenandoahHeap;
98   friend class ShenandoahCodeRootsIterator;
99 
100 public:
101   static void initialize();
102   static void register_nmethod(nmethod* nm);
103   static void unregister_nmethod(nmethod* nm);
104   static void flush_nmethod(nmethod* nm);
105 
table()106   static ShenandoahNMethodTable* table() {
107     return _nmethod_table;
108   }
109 
110   // Concurrent nmethod unloading support
111   static void unlink(WorkGang* workers, bool unloading_occurred);
112   static void purge(WorkGang* workers);
113   static void arm_nmethods();
114   static void disarm_nmethods();
disarmed_value()115   static int  disarmed_value()         { return _disarmed_value; }
disarmed_value_address()116   static int* disarmed_value_address() { return &_disarmed_value; }
117 
118 private:
119   static ShenandoahNMethodTable* _nmethod_table;
120   static int                     _disarmed_value;
121 };
122 
123 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCODEROOTS_HPP
124