< prev index next >

src/hotspot/share/compiler/oopMap.hpp

Print this page

 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_COMPILER_OOPMAP_HPP
 26 #define SHARE_COMPILER_OOPMAP_HPP
 27 
 28 #include "code/compressedStream.hpp"
 29 #include "code/vmreg.hpp"
 30 #include "memory/allocation.hpp"

 31 #include "oops/oopsHierarchy.hpp"
 32 #include "utilities/growableArray.hpp"
 33 
 34 // Interface for generating the frame map for compiled code.  A frame map
 35 // describes for a specific pc whether each register and frame stack slot is:
 36 //   Oop         - A GC root for current frame
 37 //   Dead        - Dead; can be Zapped for debugging
 38 //   CalleeXX    - Callee saved; also describes which caller register is saved
 39 //   DerivedXX   - A derived oop; original oop is described.
 40 //
 41 // OopMapValue describes a single OopMap entry
 42 
 43 enum class DerivedPointerIterationMode;
 44 class frame;
 45 class RegisterMap;
 46 class OopClosure;

 47 
 48 enum class derived_pointer : intptr_t {};
 49 
 50 class OopMapValue: public StackObj {
 51   friend class VMStructs;
 52 private:
 53   short _value;
 54   int value() const                                 { return _value; }
 55   void set_value(int value)                         { _value = value; }
 56   short _content_reg;
 57 
 58 public:
 59   // Constants
 60   enum { type_bits                = 2,
 61          register_bits            = BitsPerShort - type_bits };
 62 
 63   enum { type_shift               = 0,
 64          register_shift           = type_bits };
 65 
 66   enum { type_mask                = right_n_bits(type_bits),
 67          type_mask_in_place       = type_mask << type_shift,
 68          register_mask            = right_n_bits(register_bits),
 69          register_mask_in_place   = register_mask << register_shift };
 70 
 71   enum oop_types {
 72          oop_value,
 73          narrowoop_value,
 74          callee_saved_value,
 75          derived_oop_value,

 76          unused_value = -1          // Only used as a sentinel value
 77   };
 78 
 79   // Constructors
 80   OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }
 81   OopMapValue (VMReg reg, oop_types t, VMReg reg2) {
 82     set_reg_type(reg, t);
 83     set_content_reg(reg2);
 84   }
 85 
 86  private:
 87     void set_reg_type(VMReg p, oop_types t) {
 88     set_value((p->value() << register_shift) | t);
 89     assert(reg() == p, "sanity check" );
 90     assert(type() == t, "sanity check" );
 91   }
 92 
 93   void set_content_reg(VMReg r) {
 94     if (is_callee_saved()) {
 95       // This can never be a stack location, so we don't need to transform it.

106   // Archiving
107   void write_on(CompressedWriteStream* stream) {
108     stream->write_int(value());
109     if(is_callee_saved() || is_derived_oop()) {
110       stream->write_int(content_reg()->value());
111     }
112   }
113 
114   void read_from(CompressedReadStream* stream) {
115     set_value(stream->read_int());
116     if (is_callee_saved() || is_derived_oop()) {
117       set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));
118     }
119   }
120 
121   // Querying
122   bool is_oop()               { return mask_bits(value(), type_mask_in_place) == oop_value; }
123   bool is_narrowoop()         { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }
124   bool is_callee_saved()      { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }
125   bool is_derived_oop()       { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }


126 
127   VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }
128   oop_types type() const      { return (oop_types)mask_bits(value(), type_mask_in_place); }
129 
130   static bool legal_vm_reg_name(VMReg p) {
131     return (p->value()  == (p->value() & register_mask));
132   }
133 
134   VMReg content_reg() const       { return VMRegImpl::as_VMReg(_content_reg, true); }
135 
136   // Returns offset from sp.
137   int stack_offset() {
138     assert(reg()->is_stack(), "must be stack location");
139     return reg()->reg2stack();
140   }
141 
142   void print_on(outputStream* st) const;
143   void print() const;
144 };
145 
146 
147 class OopMap: public ResourceObj {
148   friend class OopMapStream;
149   friend class VMStructs;


150  private:
151   int  _pc_offset; // offset in the code that this OopMap corresponds to
152   int  _omv_count; // number of OopMapValues in the stream



153   CompressedWriteStream* _write_stream;
154 
155   debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
156 
157   // Accessors
158   int omv_count() const                       { return _omv_count; }
159   void set_omv_count(int value)               { _omv_count = value; }
160   void increment_count()                      { _omv_count++; }


161   CompressedWriteStream* write_stream() const { return _write_stream; }
162   void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
163 
164  private:
165   enum DeepCopyToken { _deep_copy_token };
166   OopMap(DeepCopyToken, OopMap* source);  // used only by deep_copy
167 
168   void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
169 
170  public:
171   OopMap(int frame_size, int arg_count);
172 
173   // pc-offset handling
174   int offset() const     { return _pc_offset; }
175   void set_offset(int o) { _pc_offset = o; }
176   int count() const { return _omv_count; }
177   int data_size() const  { return write_stream()->position(); }
178   address data() const { return write_stream()->buffer(); }



179 
180   // Construction
181   // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
182   // slots to hold 4-byte values like ints and floats in the LP64 build.
183   void set_oop  ( VMReg local);
184   void set_narrowoop(VMReg local);
185   void set_callee_saved( VMReg local, VMReg caller_machine_register );
186   void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
187 
188   int heap_size() const;
189   void copy_data_to(address addr) const;

190   OopMap* deep_copy();
191 
192   bool legal_vm_reg_name(VMReg local) {
193      return OopMapValue::legal_vm_reg_name(local);
194   }
195 
196   // Printing
197   void print_on(outputStream* st) const;
198   void print() const;
199   bool equals(const OopMap* other) const;
200 };
201 


202 class OopMapSet : public ResourceObj {
203   friend class VMStructs;
204  private:
205   GrowableArray<OopMap*> _list;
206 
207   void add(OopMap* value) { _list.append(value); }
208 
209  public:
210   OopMapSet();
211 
212   // returns the number of OopMaps in this OopMapSet
213   int size() const            { return _list.length(); }
214   // returns the OopMap at a given index
215   OopMap* at(int index) const { return _list.at(index); }
216 
217   // Collect OopMaps.
218   void add_gc_map(int pc, OopMap* map);
219 
220   // Methods oops_do() and all_do() filter out NULL oops and
221   // oop == CompressedOops::base() before passing oops
222   // to closures.
223 



224   // Iterates through frame for a compiled method
225   static void oops_do            (const frame* fr,
226                                   const RegisterMap* reg_map,
227                                   OopClosure* f,
228                                   DerivedPointerIterationMode mode);
229   static void update_register_map(const frame* fr, RegisterMap *reg_map);
230 
231   // Iterates through frame for a compiled method for dead ones and values, too
232   static void all_do(const frame* fr, const RegisterMap* reg_map,
233                      OopClosure* oop_fn,
234                      void derived_oop_fn(oop* base, derived_pointer* derived, OopClosure* oop_fn));





235 
236   // Printing
237   void print_on(outputStream* st) const;
238   void print() const;
239 };
240 
241 class ImmutableOopMapBuilder;
242 









243 class ImmutableOopMap {
244   friend class OopMapStream;
245   friend class VMStructs;


246 #ifdef ASSERT
247   friend class ImmutableOopMapBuilder;
248 #endif
249 private:
250   int _count; // contains the number of entries in this OopMap


251 
252   address data_addr() const { return (address) this + sizeof(ImmutableOopMap); }
253 public:
254   ImmutableOopMap(const OopMap* oopmap);
255 
256   int count() const { return _count; }




257 #ifdef ASSERT
258   int nr_of_bytes() const; // this is an expensive operation, only used in debug builds
259 #endif
260 






261   // Printing
262   void print_on(outputStream* st) const;
263   void print() const;
264 };
265 
266 class ImmutableOopMapSet;
267 class ImmutableOopMap;
268 class OopMapSet;
269 
270 class ImmutableOopMapPair {
271   friend class VMStructs;
272 private:
273   int _pc_offset; // program counter offset from the beginning of the method
274   int _oopmap_offset; // offset in the data in the ImmutableOopMapSet where the ImmutableOopMap is located
275 public:
276   ImmutableOopMapPair(int pc_offset, int oopmap_offset) : _pc_offset(pc_offset), _oopmap_offset(oopmap_offset) {
277     assert(pc_offset >= 0 && oopmap_offset >= 0, "check");
278   }
279   const ImmutableOopMap* get_from(const ImmutableOopMapSet* set) const;
280 

286   friend class VMStructs;
287 private:
288   int _count; // nr of ImmutableOopMapPairs in the Set
289   int _size; // nr of bytes including ImmutableOopMapSet itself
290 
291   address data() const { return (address) this + sizeof(*this) + sizeof(ImmutableOopMapPair) * _count; }
292 
293 public:
294   ImmutableOopMapSet(const OopMapSet* oopmap_set, int size) : _count(oopmap_set->size()), _size(size) {}
295 
296   ImmutableOopMap* oopmap_at_offset(int offset) const {
297     assert(offset >= 0 && offset < _size, "must be within boundaries");
298     address addr = data() + offset;
299     return (ImmutableOopMap*) addr;
300   }
301 
302   ImmutableOopMapPair* get_pairs() const { return (ImmutableOopMapPair*) ((address) this + sizeof(*this)); }
303 
304   static ImmutableOopMapSet* build_from(const OopMapSet* oopmap_set);
305 

306   const ImmutableOopMap* find_map_at_offset(int pc_offset) const;

307 
308   const ImmutableOopMapPair* pair_at(int index) const { assert(index >= 0 && index < _count, "check"); return &get_pairs()[index]; }
309 
310   int count() const { return _count; }
311   int nr_of_bytes() const { return _size; }
312 
313   void print_on(outputStream* st) const;
314   void print() const;
315 };
316 
317 class OopMapStream : public StackObj {
318  private:
319   CompressedReadStream* _stream;
320   int _size;
321   int _position;
322   bool _valid_omv;
323   OopMapValue _omv;
324   void find_next();
325 
326  public:
327   OopMapStream(OopMap* oop_map);
328   OopMapStream(const ImmutableOopMap* oop_map);
329   bool is_done()                        { if(!_valid_omv) { find_next(); } return !_valid_omv; }
330   void next()                           { find_next(); }
331   OopMapValue current()                 { return _omv; }
332 #ifdef ASSERT
333   int stream_position() const           { return _stream->position(); }
334 #endif
335 };
336 

337 class ImmutableOopMapBuilder {
338 private:
339   class Mapping;
340 
341 private:
342   const OopMapSet* _set;
343   const OopMap* _empty;
344   const OopMap* _last;
345   int _empty_offset;
346   int _last_offset;
347   int _offset;
348   int _required;
349   Mapping* _mapping;
350   ImmutableOopMapSet* _new_set;
351 
352   /* Used for bookkeeping when building ImmutableOopMaps */
353   class Mapping : public ResourceObj {
354   public:
355     enum kind_t { OOPMAP_UNKNOWN = 0, OOPMAP_NEW = 1, OOPMAP_EMPTY = 2, OOPMAP_DUPLICATE = 3 };
356 

386     if (_last != NULL && _last->count() > 0 && _last->equals(map)) {
387       return true;
388     }
389     return false;
390   }
391 
392 #ifdef ASSERT
393   void verify(address buffer, int size, const ImmutableOopMapSet* set);
394 #endif
395 
396   bool has_empty() const {
397     return _empty_offset != -1;
398   }
399 
400   int size_for(const OopMap* map) const;
401   void fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
402   int fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
403   void fill(ImmutableOopMapSet* set, int size);
404 };
405 























406 
407 // Derived pointer support. This table keeps track of all derived points on a
408 // stack.  It is cleared before each scavenge/GC.  During the traversal of all
409 // oops, it is filled in with references to all locations that contains a
410 // derived oop (assumed to be very few).  When the GC is complete, the derived
411 // pointers are updated based on their base pointers new value and an offset.
412 #if COMPILER2_OR_JVMCI
413 class DerivedPointerTable : public AllStatic {
414   friend class VMStructs;
415  private:
416   class Entry;
417   static bool _active;                                  // do not record pointers for verify pass etc.
418 
419  public:
420   static void clear();                                  // Called before scavenge/GC
421   static void add(derived_pointer* derived, oop *base); // Called during scavenge/GC
422   static void update_pointers();                        // Called after  scavenge/GC
423   static bool is_empty();
424   static bool is_active()                    { return _active; }
425   static void set_active(bool value)         { _active = value; }

 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_COMPILER_OOPMAP_HPP
 26 #define SHARE_COMPILER_OOPMAP_HPP
 27 
 28 #include "code/compressedStream.hpp"
 29 #include "code/vmreg.hpp"
 30 #include "memory/allocation.hpp"
 31 #include "memory/iterator.hpp"
 32 #include "oops/oopsHierarchy.hpp"
 33 #include "utilities/growableArray.hpp"
 34 
 35 // Interface for generating the frame map for compiled code.  A frame map
 36 // describes for a specific pc whether each register and frame stack slot is:
 37 //   Oop         - A GC root for current frame
 38 //   Dead        - Dead; can be Zapped for debugging
 39 //   CalleeXX    - Callee saved; also describes which caller register is saved
 40 //   DerivedXX   - A derived oop; original oop is described.
 41 //
 42 // OopMapValue describes a single OopMap entry
 43 
 44 enum class DerivedPointerIterationMode;
 45 class frame;
 46 class RegisterMap;
 47 class OopClosure;
 48 class CodeBlob;
 49 
 50 enum class derived_pointer : intptr_t {};
 51 
 52 class OopMapValue: public StackObj {
 53   friend class VMStructs;
 54 private:
 55   short _value;
 56   int value() const                                 { return _value; }
 57   void set_value(int value)                         { _value = value; }
 58   short _content_reg;
 59 
 60 public:
 61   // Constants
 62   enum { type_bits                = 2, // 3
 63          register_bits            = BitsPerShort - type_bits };
 64 
 65   enum { type_shift               = 0,
 66          register_shift           = type_bits };
 67 
 68   enum { type_mask                = right_n_bits(type_bits),
 69          type_mask_in_place       = type_mask << type_shift,
 70          register_mask            = right_n_bits(register_bits),
 71          register_mask_in_place   = register_mask << register_shift };
 72 
 73   enum oop_types {
 74          oop_value,
 75          narrowoop_value,
 76          callee_saved_value,
 77          derived_oop_value,
 78          // live_value,
 79          unused_value = -1          // Only used as a sentinel value
 80   };
 81 
 82   // Constructors
 83   OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }
 84   OopMapValue (VMReg reg, oop_types t, VMReg reg2) {
 85     set_reg_type(reg, t);
 86     set_content_reg(reg2);
 87   }
 88 
 89  private:
 90     void set_reg_type(VMReg p, oop_types t) {
 91     set_value((p->value() << register_shift) | t);
 92     assert(reg() == p, "sanity check" );
 93     assert(type() == t, "sanity check" );
 94   }
 95 
 96   void set_content_reg(VMReg r) {
 97     if (is_callee_saved()) {
 98       // This can never be a stack location, so we don't need to transform it.

109   // Archiving
110   void write_on(CompressedWriteStream* stream) {
111     stream->write_int(value());
112     if(is_callee_saved() || is_derived_oop()) {
113       stream->write_int(content_reg()->value());
114     }
115   }
116 
117   void read_from(CompressedReadStream* stream) {
118     set_value(stream->read_int());
119     if (is_callee_saved() || is_derived_oop()) {
120       set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));
121     }
122   }
123 
124   // Querying
125   bool is_oop()               { return mask_bits(value(), type_mask_in_place) == oop_value; }
126   bool is_narrowoop()         { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }
127   bool is_callee_saved()      { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }
128   bool is_derived_oop()       { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }
129   // bool is_live()              { return mask_bits(value(), type_mask_in_place) == live_value; }
130   bool is_oop_or_narrow()     { return is_oop() || is_narrowoop(); }
131 
132   VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }
133   oop_types type() const      { return (oop_types)mask_bits(value(), type_mask_in_place); }
134 
135   static bool legal_vm_reg_name(VMReg p) {
136     return (p->value()  == (p->value() & register_mask));
137   }
138 
139   VMReg content_reg() const       { return VMRegImpl::as_VMReg(_content_reg, true); }
140 
141   // Returns offset from sp.
142   int stack_offset() {
143     assert(reg()->is_stack(), "must be stack location");
144     return reg()->reg2stack();
145   }
146 
147   void print_on(outputStream* st) const;
148   void print() const;
149 };
150 
151 
152 class OopMap: public ResourceObj {
153   friend class OopMapStream;
154   friend class VMStructs;
155   friend class OopMapSet;
156   friend class OopMapSort;
157  private:
158   int  _pc_offset; // offset in the code that this OopMap corresponds to
159   int  _omv_count; // number of OopMapValues in the stream
160   int  _num_oops;  // number of oops
161   int  _index;     // index in OopMapSet
162   bool _has_derived_oops;
163   CompressedWriteStream* _write_stream;
164 
165   debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
166 
167   // Accessors
168   int omv_count() const                       { return _omv_count; }
169   void set_omv_count(int value)               { _omv_count = value; }
170   void increment_count()                      { _omv_count++; }
171   void increment_num_oops()                   { _num_oops++; }
172   void set_has_derived_oops(bool value)       { _has_derived_oops = value; }
173   CompressedWriteStream* write_stream() const { return _write_stream; }
174   void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
175 
176  private:
177   enum DeepCopyToken { _deep_copy_token };
178   OopMap(DeepCopyToken, OopMap* source);  // used only by deep_copy
179 
180   void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
181 
182  public:
183   OopMap(int frame_size, int arg_count);
184 
185   // pc-offset handling
186   int offset() const     { return _pc_offset; }
187   void set_offset(int o) { _pc_offset = o; }
188   int count() const { return _omv_count; }
189   int data_size() const  { return write_stream()->position(); }
190   address data() const { return write_stream()->buffer(); }
191   int num_oops() const { return _num_oops; }
192   bool has_derived_oops() const { return _has_derived_oops; }
193   int index() const { return _index; }
194 
195   // Construction
196   // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
197   // slots to hold 4-byte values like ints and floats in the LP64 build.
198   void set_oop  ( VMReg local);
199   void set_narrowoop(VMReg local);
200   void set_callee_saved( VMReg local, VMReg caller_machine_register );
201   void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
202 
203   int heap_size() const;
204   void copy_data_to(address addr) const;
205   void copy_and_sort_data_to(address addr) const;
206   OopMap* deep_copy();
207 
208   bool legal_vm_reg_name(VMReg local) {
209      return OopMapValue::legal_vm_reg_name(local);
210   }
211 
212   // Printing
213   void print_on(outputStream* st) const;
214   void print() const;
215   bool equals(const OopMap* other) const;
216 };
217 
218 class ImmutableOopMap;
219 
220 class OopMapSet : public ResourceObj {
221   friend class VMStructs;
222  private:
223   GrowableArray<OopMap*> _list;
224 
225   int add(OopMap* value) { return _list.append(value); }
226 
227  public:
228   OopMapSet();
229 
230   // returns the number of OopMaps in this OopMapSet
231   int size() const            { return _list.length(); }
232   // returns the OopMap at a given index
233   OopMap* at(int index) const { return _list.at(index); }
234 
235   // Collect OopMaps.
236   int add_gc_map(int pc, OopMap* map);
237 
238   // Methods oops_do() and all_do() filter out NULL oops and
239   // oop == CompressedOops::base() before passing oops
240   // to closures.
241 
242   static const ImmutableOopMap* find_map(const CodeBlob* cb, address pc);
243   static const ImmutableOopMap* find_map(const frame *fr);
244 
245   // Iterates through frame for a compiled method
246   static void oops_do            (const frame* fr, const RegisterMap* reg_map,
247                                   OopClosure* f, DerivedOopClosure* df);
248   static void oops_do            (const frame* fr, const RegisterMap* reg_map,
249                                   OopClosure* f, DerivedPointerIterationMode mode);
250   static void update_register_map(const frame* fr, RegisterMap *reg_map);
251 
252 #ifndef PRODUCT
253   static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map);
254 #endif
255 
256   // // Iterates through frame for a compiled method for dead ones and values, too
257   // static void all_do(const frame* fr, const RegisterMap* reg_map,
258   //                    OopClosure* oop_fn,
259   //                    DerivedOopClosure* derived_oop_fn,
260   //                    OopClosure* value_fn);
261 
262   // Printing
263   void print_on(outputStream* st) const;
264   void print() const;
265 };
266 
267 class ImmutableOopMapBuilder;
268 
269 class OopMapClosure : public Closure {
270  public:
271   virtual bool handle_type(OopMapValue::oop_types type) { return true; }
272   virtual void do_value(VMReg reg, OopMapValue::oop_types type) = 0;
273 };
274 
275 template <typename OopFnT, typename DerivedOopFnT, typename ValueFilterT>
276 class OopMapDo;
277 
278 class ImmutableOopMap {
279   friend class OopMapStream;
280   friend class VMStructs;
281   template <typename OopFnT, typename DerivedOopFnT, typename ValueFilterT>
282   friend class OopMapDo;
283 #ifdef ASSERT
284   friend class ImmutableOopMapBuilder;
285 #endif
286 private:
287   int _count; // contains the number of entries in this OopMap
288   int _num_oops;
289   bool _has_derived_oops;
290 
291   address data_addr() const { return (address) this + sizeof(ImmutableOopMap); }
292 public:
293   ImmutableOopMap(const OopMap* oopmap);
294 
295   int count() const { return _count; }
296   int num_oops() const { return _num_oops; }
297   bool has_derived_oops() const { return _has_derived_oops; }
298   bool has_any(OopMapValue::oop_types type) const;
299 
300 #ifdef ASSERT
301   int nr_of_bytes() const; // this is an expensive operation, only used in debug builds
302 #endif
303 
304   void oops_do(const frame* fr, const RegisterMap* reg_map, OopClosure* f, DerivedOopClosure* df) const;
305   void oops_do(const frame* fr, const RegisterMap* reg_map, OopClosure* f, DerivedPointerIterationMode derived_mode) const;
306   void all_type_do(const frame *fr, OopMapValue::oop_types type, OopMapClosure* fn) const;
307   void all_type_do(const frame *fr, OopMapClosure* fn) const;
308   void update_register_map(const frame* fr, RegisterMap *reg_map) const;
309 
310   // Printing
311   void print_on(outputStream* st) const;
312   void print() const;
313 };
314 
315 class ImmutableOopMapSet;
316 class ImmutableOopMap;
317 class OopMapSet;
318 
319 class ImmutableOopMapPair {
320   friend class VMStructs;
321 private:
322   int _pc_offset; // program counter offset from the beginning of the method
323   int _oopmap_offset; // offset in the data in the ImmutableOopMapSet where the ImmutableOopMap is located
324 public:
325   ImmutableOopMapPair(int pc_offset, int oopmap_offset) : _pc_offset(pc_offset), _oopmap_offset(oopmap_offset) {
326     assert(pc_offset >= 0 && oopmap_offset >= 0, "check");
327   }
328   const ImmutableOopMap* get_from(const ImmutableOopMapSet* set) const;
329 

335   friend class VMStructs;
336 private:
337   int _count; // nr of ImmutableOopMapPairs in the Set
338   int _size; // nr of bytes including ImmutableOopMapSet itself
339 
340   address data() const { return (address) this + sizeof(*this) + sizeof(ImmutableOopMapPair) * _count; }
341 
342 public:
343   ImmutableOopMapSet(const OopMapSet* oopmap_set, int size) : _count(oopmap_set->size()), _size(size) {}
344 
345   ImmutableOopMap* oopmap_at_offset(int offset) const {
346     assert(offset >= 0 && offset < _size, "must be within boundaries");
347     address addr = data() + offset;
348     return (ImmutableOopMap*) addr;
349   }
350 
351   ImmutableOopMapPair* get_pairs() const { return (ImmutableOopMapPair*) ((address) this + sizeof(*this)); }
352 
353   static ImmutableOopMapSet* build_from(const OopMapSet* oopmap_set);
354 
355   int find_slot_for_offset(int pc_offset) const;
356   const ImmutableOopMap* find_map_at_offset(int pc_offset) const;
357   const ImmutableOopMap* find_map_at_slot(int slot, int pc_offset) const;
358 
359   const ImmutableOopMapPair* pair_at(int index) const { assert(index >= 0 && index < _count, "check"); return &get_pairs()[index]; }
360 
361   int count() const { return _count; }
362   int nr_of_bytes() const { return _size; }
363 
364   void print_on(outputStream* st) const;
365   void print() const;
366 };
367 
368 class OopMapStream : public StackObj {
369  private:
370   CompressedReadStream _stream;
371   int _size;
372   int _position;
373   bool _valid_omv;
374   OopMapValue _omv;
375   void find_next();
376 
377  public:
378   OopMapStream(const OopMap* oop_map);
379   OopMapStream(const ImmutableOopMap* oop_map);
380   bool is_done()                        { if(!_valid_omv) { find_next(); } return !_valid_omv; }
381   void next()                           { find_next(); }
382   OopMapValue current()                 { return _omv; }
383 #ifdef ASSERT
384   int stream_position() const           { return _stream.position(); }
385 #endif
386 };
387 
388 
389 class ImmutableOopMapBuilder {
390 private:
391   class Mapping;
392 
393 private:
394   const OopMapSet* _set;
395   const OopMap* _empty;
396   const OopMap* _last;
397   int _empty_offset;
398   int _last_offset;
399   int _offset;
400   int _required;
401   Mapping* _mapping;
402   ImmutableOopMapSet* _new_set;
403 
404   /* Used for bookkeeping when building ImmutableOopMaps */
405   class Mapping : public ResourceObj {
406   public:
407     enum kind_t { OOPMAP_UNKNOWN = 0, OOPMAP_NEW = 1, OOPMAP_EMPTY = 2, OOPMAP_DUPLICATE = 3 };
408 

438     if (_last != NULL && _last->count() > 0 && _last->equals(map)) {
439       return true;
440     }
441     return false;
442   }
443 
444 #ifdef ASSERT
445   void verify(address buffer, int size, const ImmutableOopMapSet* set);
446 #endif
447 
448   bool has_empty() const {
449     return _empty_offset != -1;
450   }
451 
452   int size_for(const OopMap* map) const;
453   void fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
454   int fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
455   void fill(ImmutableOopMapSet* set, int size);
456 };
457 
458 class SkipNullValue {
459 public:
460   static inline bool should_skip(oop val);
461 };
462 
463 class IncludeAllValues {
464 public:
465   static bool should_skip(oop value) { return false; }
466 };
467 
468 template <typename OopFnT, typename DerivedOopFnT, typename ValueFilterT>
469 class OopMapDo {
470 private:
471   OopFnT* _oop_fn;
472   DerivedOopFnT* _derived_oop_fn;
473 public:
474   OopMapDo(OopFnT* oop_fn, DerivedOopFnT* derived_oop_fn) : _oop_fn(oop_fn), _derived_oop_fn(derived_oop_fn) {}
475   template <typename RegisterMapT>
476   void oops_do(const frame* fr, const RegisterMapT* reg_map, const ImmutableOopMap* oopmap);
477 private:
478   template <typename RegisterMapT>
479   void iterate_oops_do(const frame *fr, const RegisterMapT *reg_map, const ImmutableOopMap* oopmap);
480 };
481 
482 // Derived pointer support. This table keeps track of all derived points on a
483 // stack.  It is cleared before each scavenge/GC.  During the traversal of all
484 // oops, it is filled in with references to all locations that contains a
485 // derived oop (assumed to be very few).  When the GC is complete, the derived
486 // pointers are updated based on their base pointers new value and an offset.
487 #if COMPILER2_OR_JVMCI
488 class DerivedPointerTable : public AllStatic {
489   friend class VMStructs;
490  private:
491   class Entry;
492   static bool _active;                                  // do not record pointers for verify pass etc.
493 
494  public:
495   static void clear();                                  // Called before scavenge/GC
496   static void add(derived_pointer* derived, oop *base); // Called during scavenge/GC
497   static void update_pointers();                        // Called after  scavenge/GC
498   static bool is_empty();
499   static bool is_active()                    { return _active; }
500   static void set_active(bool value)         { _active = value; }
< prev index next >