< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahNMethod.hpp

Print this page

 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_SHENANDOAH_SHENANDOAHNMETHOD_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_HPP
 27 
 28 #include "code/nmethod.hpp"
 29 #include "gc/shenandoah/shenandoahHeap.hpp"
 30 #include "gc/shenandoah/shenandoahLock.hpp"
 31 #include "gc/shenandoah/shenandoahPadding.hpp"
 32 #include "memory/allocation.hpp"
 33 #include "runtime/atomic.hpp"
 34 #include "utilities/growableArray.hpp"
 35 


 36 // Use ShenandoahReentrantLock as ShenandoahNMethodLock
 37 typedef ShenandoahReentrantLock<ShenandoahSimpleLock> ShenandoahNMethodLock;
 38 typedef ShenandoahLocker<ShenandoahNMethodLock>       ShenandoahNMethodLocker;
 39 







 40 // ShenandoahNMethod tuple records the internal locations of oop slots within reclocation stream in
 41 // the nmethod. This allows us to quickly scan the oops without doing the nmethod-internal scans,
 42 // that sometimes involves parsing the machine code. Note it does not record the oops themselves,
 43 // because it would then require handling these tuples as the new class of roots.
 44 class ShenandoahNMethod : public CHeapObj<mtGC> {
 45 private:
 46   nmethod* const          _nm;
 47   oop**                   _oops;
 48   int                     _oops_count;


 49   bool                    _has_non_immed_oops;
 50   bool                    _unregistered;
 51   ShenandoahNMethodLock   _lock;
 52   ShenandoahNMethodLock   _ic_lock;
 53 
 54 public:
 55   ShenandoahNMethod(nmethod *nm, GrowableArray<oop*>& oops, bool has_non_immed_oops);
 56   ~ShenandoahNMethod();
 57 















 58   inline nmethod* nm() const;
 59   inline ShenandoahNMethodLock* lock();
 60   inline ShenandoahNMethodLock* ic_lock();
 61   inline void oops_do(OopClosure* oops, bool fix_relocations = false);
 62   // Update oops when the nmethod is re-registered
 63   void update();
 64 
 65   inline bool is_unregistered() const;
 66 
 67   static ShenandoahNMethod* for_nmethod(nmethod* nm);
 68   static inline ShenandoahNMethodLock* lock_for_nmethod(nmethod* nm);
 69   static inline ShenandoahNMethodLock* ic_lock_for_nmethod(nmethod* nm);
 70 
 71   static void heal_nmethod(nmethod* nm);

 72   static inline void heal_nmethod_metadata(ShenandoahNMethod* nmethod_data);
 73   static inline void disarm_nmethod(nmethod* nm);
 74 
 75   static inline ShenandoahNMethod* gc_data(nmethod* nm);
 76   static inline void attach_gc_data(nmethod* nm, ShenandoahNMethod* gc_data);
 77 
 78   void assert_correct() NOT_DEBUG_RETURN;
 79   void assert_same_oops() NOT_DEBUG_RETURN;
 80 




 81 private:
 82   static void detect_reloc_oops(nmethod* nm, GrowableArray<oop*>& oops, bool& _has_non_immed_oops);


 83 };
 84 
 85 class ShenandoahNMethodTable;
 86 
 87 // ShenandoahNMethodList holds registered nmethod data. The list is reference counted.
 88 class ShenandoahNMethodList : public CHeapObj<mtGC> {
 89 private:
 90   ShenandoahNMethod** _list;
 91   const int           _size;
 92   uint                _ref_count;
 93 
 94 private:
 95   ~ShenandoahNMethodList();
 96 
 97 public:
 98   ShenandoahNMethodList(int size);
 99 
100   // Reference counting with CoceCache_lock held
101   ShenandoahNMethodList* acquire();
102   void release();

122   shenandoah_padding(0);
123   Atomic<size_t>            _claimed;
124   shenandoah_padding(1);
125 
126 public:
127   ShenandoahNMethodTableSnapshot(ShenandoahNMethodTable* table);
128   ~ShenandoahNMethodTableSnapshot();
129 
130   void parallel_nmethods_do(NMethodClosure *f);
131   void concurrent_nmethods_do(NMethodClosure* cl);
132 };
133 
134 class ShenandoahNMethodTable : public CHeapObj<mtGC> {
135   friend class ShenandoahNMethodTableSnapshot;
136 private:
137   enum {
138     minSize = 1024
139   };
140 
141   ShenandoahHeap* const  _heap;


142   ShenandoahNMethodList* _list;
143 
144   int                    _index;
145   ShenandoahLock         _lock;
146   int                    _itr_cnt;
147 
148 public:
149   ShenandoahNMethodTable();
150   ~ShenandoahNMethodTable();
151 
152   void register_nmethod(nmethod* nm);
153   void unregister_nmethod(nmethod* nm);
154 
155   bool contain(nmethod* nm) const;
156   int length() const { return _index; }
157 
158   // Table iteration support
159   ShenandoahNMethodTableSnapshot* snapshot_for_iteration();
160   void finish_iteration(ShenandoahNMethodTableSnapshot* snapshot);
161 

 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_SHENANDOAH_SHENANDOAHNMETHOD_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_HPP
 27 
 28 #include "code/nmethod.hpp"
 29 #include "gc/shenandoah/shenandoahHeap.hpp"
 30 #include "gc/shenandoah/shenandoahLock.hpp"
 31 #include "gc/shenandoah/shenandoahPadding.hpp"
 32 #include "memory/allocation.hpp"
 33 #include "runtime/atomic.hpp"
 34 #include "utilities/growableArray.hpp"
 35 
 36 class BarrierSetNMethod;
 37 
 38 // Use ShenandoahReentrantLock as ShenandoahNMethodLock
 39 typedef ShenandoahReentrantLock<ShenandoahSimpleLock> ShenandoahNMethodLock;
 40 typedef ShenandoahLocker<ShenandoahNMethodLock>       ShenandoahNMethodLocker;
 41 
 42 struct ShenandoahPatchableJump {
 43   int32_t _rel_pc;
 44   int32_t _rel_target_pc;
 45   char _gc_state;
 46   bool _jump_when_state;
 47 };
 48 
 49 // ShenandoahNMethod tuple records the internal locations of oop slots within reclocation stream in
 50 // the nmethod. This allows us to quickly scan the oops without doing the nmethod-internal scans,
 51 // that sometimes involves parsing the machine code. Note it does not record the oops themselves,
 52 // because it would then require handling these tuples as the new class of roots.
 53 class ShenandoahNMethod : public CHeapObj<mtGC> {
 54 private:
 55   nmethod* const          _nm;
 56   oop**                   _oops;
 57   int                     _oops_count;
 58   ShenandoahPatchableJump* _patchable_jumps;
 59   int                     _patchable_jumps_count;
 60   bool                    _has_non_immed_oops;
 61   bool                    _unregistered;
 62   ShenandoahNMethodLock   _lock;
 63   ShenandoahNMethodLock   _ic_lock;
 64 
 65 public:
 66   ShenandoahNMethod(nmethod *nm);
 67   ~ShenandoahNMethod();
 68 
 69   static bool decode_reloc_jump_when_state(uint16_t reloc) {
 70     return (reloc & (1 << 8)) != 0;
 71   }
 72 
 73   static char decode_reloc_gc_state(uint16_t reloc) {
 74     return (reloc & 0xFF);
 75   }
 76 
 77   static uint16_t encode_to_reloc(char gc_state, bool jump_when_state) {
 78     uint16_t res = (gc_state & 0xFF) | (jump_when_state ? (1 << 8) : 0);
 79     assert(decode_reloc_jump_when_state(res) == jump_when_state, "Round-trip");
 80     assert(decode_reloc_gc_state(res) == gc_state, "Round-trip");
 81     return res;
 82   }
 83 
 84   inline nmethod* nm() const;
 85   inline ShenandoahNMethodLock* lock();
 86   inline ShenandoahNMethodLock* ic_lock();
 87   inline void oops_do(OopClosure* oops, bool fix_relocations = false);
 88   // Update oops when the nmethod is re-registered
 89   void update();
 90 
 91   inline bool is_unregistered() const;
 92 
 93   static ShenandoahNMethod* for_nmethod(nmethod* nm);
 94   static inline ShenandoahNMethodLock* lock_for_nmethod(nmethod* nm);
 95   static inline ShenandoahNMethodLock* ic_lock_for_nmethod(nmethod* nm);
 96 
 97   static bool handle_oops(nmethod* nm);
 98   static bool handle_jumps(nmethod* nm);
 99   static inline void heal_nmethod_metadata(ShenandoahNMethod* nmethod_data);
100   static inline void disarm_nmethod(nmethod* nm);
101 
102   static inline ShenandoahNMethod* gc_data(nmethod* nm);
103   static inline void attach_gc_data(nmethod* nm, ShenandoahNMethod* gc_data);
104 
105   void assert_correct() NOT_DEBUG_RETURN;
106   void assert_same_oops() NOT_DEBUG_RETURN;
107 
108   bool has_patchable_jumps() {
109     return _patchable_jumps_count > 0;
110   }
111 
112 private:
113   void init_from(nmethod* nm);
114   static void parse(nmethod* nm, GrowableArray<oop*>& oops, bool& _has_non_immed_oops, GrowableArray<ShenandoahPatchableJump>& jumps);
115   static bool patch_jump(address pc, address target_pc, bool should_jump);
116 };
117 
118 class ShenandoahNMethodTable;
119 
120 // ShenandoahNMethodList holds registered nmethod data. The list is reference counted.
121 class ShenandoahNMethodList : public CHeapObj<mtGC> {
122 private:
123   ShenandoahNMethod** _list;
124   const int           _size;
125   uint                _ref_count;
126 
127 private:
128   ~ShenandoahNMethodList();
129 
130 public:
131   ShenandoahNMethodList(int size);
132 
133   // Reference counting with CoceCache_lock held
134   ShenandoahNMethodList* acquire();
135   void release();

155   shenandoah_padding(0);
156   Atomic<size_t>            _claimed;
157   shenandoah_padding(1);
158 
159 public:
160   ShenandoahNMethodTableSnapshot(ShenandoahNMethodTable* table);
161   ~ShenandoahNMethodTableSnapshot();
162 
163   void parallel_nmethods_do(NMethodClosure *f);
164   void concurrent_nmethods_do(NMethodClosure* cl);
165 };
166 
167 class ShenandoahNMethodTable : public CHeapObj<mtGC> {
168   friend class ShenandoahNMethodTableSnapshot;
169 private:
170   enum {
171     minSize = 1024
172   };
173 
174   ShenandoahHeap* const  _heap;
175   BarrierSetNMethod* const _bs_nm;
176 
177   ShenandoahNMethodList* _list;
178 
179   int                    _index;
180   ShenandoahLock         _lock;
181   int                    _itr_cnt;
182 
183 public:
184   ShenandoahNMethodTable();
185   ~ShenandoahNMethodTable();
186 
187   void register_nmethod(nmethod* nm);
188   void unregister_nmethod(nmethod* nm);
189 
190   bool contain(nmethod* nm) const;
191   int length() const { return _index; }
192 
193   // Table iteration support
194   ShenandoahNMethodTableSnapshot* snapshot_for_iteration();
195   void finish_iteration(ShenandoahNMethodTableSnapshot* snapshot);
196 
< prev index next >