< 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 
  33 // Interface for generating the frame map for compiled code.  A frame map
  34 // describes for a specific pc whether each register and frame stack slot is:
  35 //   Oop         - A GC root for current frame
  36 //   Dead        - Dead; can be Zapped for debugging
  37 //   CalleeXX    - Callee saved; also describes which caller register is saved
  38 //   DerivedXX   - A derived oop; original oop is described.
  39 //
  40 // OopMapValue describes a single OopMap entry
  41 
  42 class frame;
  43 class RegisterMap;
  44 class OopClosure;

  45 
  46 class OopMapValue: public StackObj {
  47   friend class VMStructs;
  48 private:
  49   short _value;
  50   int value() const                                 { return _value; }
  51   void set_value(int value)                         { _value = value; }
  52   short _content_reg;
  53 
  54 public:
  55   // Constants
  56   enum { type_bits                = 4,
  57          register_bits            = BitsPerShort - type_bits };
  58 
  59   enum { type_shift               = 0,
  60          register_shift           = type_bits };
  61 
  62   enum { type_mask                = right_n_bits(type_bits),
  63          type_mask_in_place       = type_mask << type_shift,
  64          register_mask            = right_n_bits(register_bits),
  65          register_mask_in_place   = register_mask << register_shift };
  66 
  67   enum oop_types {              // must fit in type_bits
  68          unused_value =0,       // powers of 2, for masking OopMapStream
  69          oop_value = 1,
  70          narrowoop_value = 2,
  71          callee_saved_value = 4,
  72          derived_oop_value= 8 };

  73 
  74   // Constructors
  75   OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }
  76   OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg, t); set_content_reg(VMRegImpl::Bad()); }
  77   OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg, t); set_content_reg(reg2); }
  78   OopMapValue (CompressedReadStream* stream) { read_from(stream); }





  79 
  80   // Archiving
  81   void write_on(CompressedWriteStream* stream) {
  82     stream->write_int(value());
  83     if(is_callee_saved() || is_derived_oop()) {
  84       stream->write_int(content_reg()->value());
  85     }
  86   }
  87 
  88   void read_from(CompressedReadStream* stream) {
  89     set_value(stream->read_int());
  90     if (is_callee_saved() || is_derived_oop()) {
  91       set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));
  92     }
  93   }
  94 
  95   // Querying
  96   bool is_oop()               { return mask_bits(value(), type_mask_in_place) == oop_value; }
  97   bool is_narrowoop()           { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }
  98   bool is_callee_saved()      { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }
  99   bool is_derived_oop()       { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }


 100 
 101   void set_oop()              { set_value((value() & register_mask_in_place) | oop_value); }
 102   void set_narrowoop()          { set_value((value() & register_mask_in_place) | narrowoop_value); }
 103   void set_callee_saved()     { set_value((value() & register_mask_in_place) | callee_saved_value); }
 104   void set_derived_oop()      { set_value((value() & register_mask_in_place) | derived_oop_value); }

 105 
 106   VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }
 107   oop_types type() const      { return (oop_types)mask_bits(value(), type_mask_in_place); }
 108 
 109   static bool legal_vm_reg_name(VMReg p) {
 110     return (p->value()  == (p->value() & register_mask));
 111   }
 112 
 113   void set_reg_type(VMReg p, oop_types t) {
 114     set_value((p->value() << register_shift) | t);
 115     assert(reg() == p, "sanity check" );
 116     assert(type() == t, "sanity check" );
 117   }
 118 
 119 
 120   VMReg content_reg() const       { return VMRegImpl::as_VMReg(_content_reg, true); }
 121   void set_content_reg(VMReg r)   { _content_reg = r->value(); }
 122 
 123   // Physical location queries
 124   bool is_register_loc()      { return reg()->is_reg(); }
 125   bool is_stack_loc()         { return reg()->is_stack(); }
 126 
 127   // Returns offset from sp.
 128   int stack_offset() {
 129     assert(is_stack_loc(), "must be stack location");
 130     return reg()->reg2stack();
 131   }
 132 
 133   void print_on(outputStream* st) const;
 134   void print() const;
 135 };
 136 
 137 
 138 class OopMap: public ResourceObj {
 139   friend class OopMapStream;
 140   friend class VMStructs;


 141  private:
 142   int  _pc_offset; // offset in the code that this OopMap corresponds to
 143   int  _omv_count; // number of OopMapValues in the stream


 144   CompressedWriteStream* _write_stream;
 145 
 146   debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
 147 
 148   // Accessors
 149   int omv_count() const                       { return _omv_count; }
 150   void set_omv_count(int value)               { _omv_count = value; }
 151   void increment_count()                      { _omv_count++; }

 152   CompressedWriteStream* write_stream() const { return _write_stream; }
 153   void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
 154 
 155  private:
 156   enum DeepCopyToken { _deep_copy_token };
 157   OopMap(DeepCopyToken, OopMap* source);  // used only by deep_copy
 158 
 159  public:
 160   OopMap(int frame_size, int arg_count);
 161 
 162   // pc-offset handling
 163   int offset() const     { return _pc_offset; }
 164   void set_offset(int o) { _pc_offset = o; }
 165   int count() const { return _omv_count; }
 166   int data_size() const  { return write_stream()->position(); }
 167   address data() const { return write_stream()->buffer(); }


 168 
 169   // Check to avoid double insertion
 170   debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })
 171 
 172   // Construction
 173   // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
 174   // slots to hold 4-byte values like ints and floats in the LP64 build.
 175   void set_oop  ( VMReg local);
 176   void set_value( VMReg local);
 177   void set_narrowoop(VMReg local);
 178   void set_dead ( VMReg local);
 179   void set_callee_saved( VMReg local, VMReg caller_machine_register );
 180   void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
 181   void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
 182 
 183   int heap_size() const;
 184   void copy_data_to(address addr) const;

 185   OopMap* deep_copy();
 186 
 187   bool has_derived_pointer() const PRODUCT_RETURN0;
 188 
 189   bool legal_vm_reg_name(VMReg local) {
 190      return OopMapValue::legal_vm_reg_name(local);
 191   }
 192 
 193   // Printing
 194   void print_on(outputStream* st) const;
 195   void print() const;
 196   bool equals(const OopMap* other) const;
 197 };
 198 

 199 
 200 class OopMapSet : public ResourceObj {
 201   friend class VMStructs;
 202  private:
 203   int _om_count;
 204   int _om_size;
 205   OopMap** _om_data;
 206 
 207   int om_count() const              { return _om_count; }
 208   void set_om_count(int value)      { _om_count = value; }
 209   void increment_count()            { _om_count++; }
 210   int om_size() const               { return _om_size; }
 211   void set_om_size(int value)       { _om_size = value; }
 212   OopMap** om_data() const          { return _om_data; }
 213   void set_om_data(OopMap** value)  { _om_data = value; }
 214   void grow_om_data();
 215   void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }
 216 
 217  public:
 218   OopMapSet();
 219 
 220   // returns the number of OopMaps in this OopMapSet
 221   int size() const            { return _om_count; }
 222   // returns the OopMap at a given index
 223   OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }
 224 
 225   // Collect OopMaps.
 226   void add_gc_map(int pc, OopMap* map);
 227 
 228   // Returns the only oop map. Used for reconstructing
 229   // Adapter frames during deoptimization
 230   OopMap* singular_oop_map();
 231 
 232   // returns OopMap in that is anchored to the pc
 233   OopMap* find_map_at_offset(int pc_offset) const;
 234 
 235   int heap_size() const;
 236 
 237   // Methods oops_do() and all_do() filter out NULL oops and
 238   // oop == CompressedOops::base() before passing oops
 239   // to closures.
 240 



 241   // Iterates through frame for a compiled method


 242   static void oops_do            (const frame* fr,
 243                                   const RegisterMap* reg_map, OopClosure* f);
 244   static void update_register_map(const frame* fr, RegisterMap *reg_map);
 245 
 246   // Iterates through frame for a compiled method for dead ones and values, too
 247   static void all_do(const frame* fr, const RegisterMap* reg_map,
 248                      OopClosure* oop_fn,
 249                      void derived_oop_fn(oop* base, oop* derived),
 250                      OopClosure* value_fn);




 251 
 252   // Printing
 253   void print_on(outputStream* st) const;
 254   void print() const;
 255 };
 256 
 257 class ImmutableOopMapBuilder;
 258 





























 259 class ImmutableOopMap {
 260   friend class OopMapStream;
 261   friend class VMStructs;



 262 #ifdef ASSERT
 263   friend class ImmutableOopMapBuilder;
 264 #endif
 265 private:



 266   int _count; // contains the number of entries in this OopMap

 267 
 268   address data_addr() const { return (address) this + sizeof(ImmutableOopMap); }
 269 public:
 270   ImmutableOopMap(const OopMap* oopmap);
 271 


 272   bool has_derived_pointer() const PRODUCT_RETURN0;

 273   int count() const { return _count; }

 274 #ifdef ASSERT
 275   int nr_of_bytes() const; // this is an expensive operation, only used in debug builds
 276 #endif
 277 




 278   // Printing
 279   void print_on(outputStream* st) const;
 280   void print() const;




 281 };
 282 
 283 class ImmutableOopMapSet;
 284 class ImmutableOopMap;
 285 class OopMapSet;
 286 
 287 class ImmutableOopMapPair {
 288   friend class VMStructs;
 289 private:
 290   int _pc_offset; // program counter offset from the beginning of the method
 291   int _oopmap_offset; // offset in the data in the ImmutableOopMapSet where the ImmutableOopMap is located
 292 public:
 293   ImmutableOopMapPair(int pc_offset, int oopmap_offset) : _pc_offset(pc_offset), _oopmap_offset(oopmap_offset) {
 294     assert(pc_offset >= 0 && oopmap_offset >= 0, "check");
 295   }
 296   const ImmutableOopMap* get_from(const ImmutableOopMapSet* set) const;
 297 
 298   int pc_offset() const { return _pc_offset; }
 299   int oopmap_offset() const { return _oopmap_offset; }
 300 };


 303   friend class VMStructs;
 304 private:
 305   int _count; // nr of ImmutableOopMapPairs in the Set
 306   int _size; // nr of bytes including ImmutableOopMapSet itself
 307 
 308   address data() const { return (address) this + sizeof(*this) + sizeof(ImmutableOopMapPair) * _count; }
 309 
 310 public:
 311   ImmutableOopMapSet(const OopMapSet* oopmap_set, int size) : _count(oopmap_set->size()), _size(size) {}
 312 
 313   ImmutableOopMap* oopmap_at_offset(int offset) const {
 314     assert(offset >= 0 && offset < _size, "must be within boundaries");
 315     address addr = data() + offset;
 316     return (ImmutableOopMap*) addr;
 317   }
 318 
 319   ImmutableOopMapPair* get_pairs() const { return (ImmutableOopMapPair*) ((address) this + sizeof(*this)); }
 320 
 321   static ImmutableOopMapSet* build_from(const OopMapSet* oopmap_set);
 322 

 323   const ImmutableOopMap* find_map_at_offset(int pc_offset) const;

 324 
 325   const ImmutableOopMapPair* pair_at(int index) const { assert(index >= 0 && index < _count, "check"); return &get_pairs()[index]; }
 326 
 327   int count() const { return _count; }
 328   int nr_of_bytes() const { return _size; }
 329 
 330   void print_on(outputStream* st) const;
 331   void print() const;
 332 };
 333 
 334 class OopMapStream : public StackObj {
 335  private:
 336   CompressedReadStream* _stream;
 337   int _mask;
 338   int _size;
 339   int _position;
 340   bool _valid_omv;
 341   OopMapValue _omv;
 342   void find_next();
 343 
 344  public:
 345   OopMapStream(OopMap* oop_map, int oop_types_mask = OopMapValue::type_mask_in_place);
 346   OopMapStream(const ImmutableOopMap* oop_map, int oop_types_mask = OopMapValue::type_mask_in_place);
 347   bool is_done()                        { if(!_valid_omv) { find_next(); } return !_valid_omv; }
 348   void next()                           { find_next(); }
 349   OopMapValue current()                 { return _omv; }
 350 #ifdef ASSERT
 351   int stream_position() const           { return _stream->position(); }
 352 #endif
 353 };
 354 













 355 class ImmutableOopMapBuilder {
 356 private:
 357   class Mapping;
 358 
 359 private:
 360   const OopMapSet* _set;
 361   const OopMap* _empty;
 362   const OopMap* _last;
 363   int _empty_offset;
 364   int _last_offset;
 365   int _offset;
 366   int _required;
 367   Mapping* _mapping;
 368   ImmutableOopMapSet* _new_set;
 369 
 370   /* Used for bookkeeping when building ImmutableOopMaps */
 371   class Mapping : public ResourceObj {
 372   public:
 373     enum kind_t { OOPMAP_UNKNOWN = 0, OOPMAP_NEW = 1, OOPMAP_EMPTY = 2, OOPMAP_DUPLICATE = 3 };
 374 


 404     if (_last != NULL && _last->count() > 0 && _last->equals(map)) {
 405       return true;
 406     }
 407     return false;
 408   }
 409 
 410 #ifdef ASSERT
 411   void verify(address buffer, int size, const ImmutableOopMapSet* set);
 412 #endif
 413 
 414   bool has_empty() const {
 415     return _empty_offset != -1;
 416   }
 417 
 418   int size_for(const OopMap* map) const;
 419   void fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
 420   int fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
 421   void fill(ImmutableOopMapSet* set, int size);
 422 };
 423 



























 424 
 425 // Derived pointer support. This table keeps track of all derived points on a
 426 // stack.  It is cleared before each scavenge/GC.  During the traversal of all
 427 // oops, it is filled in with references to all locations that contains a
 428 // derived oop (assumed to be very few).  When the GC is complete, the derived
 429 // pointers are updated based on their base pointers new value and an offset.
 430 #if COMPILER2_OR_JVMCI
 431 class DerivedPointerTable : public AllStatic {
 432   friend class VMStructs;
 433  private:
 434   class Entry;
 435   static bool _active;                      // do not record pointers for verify pass etc.
 436 
 437  public:
 438   static void clear();                       // Called before scavenge/GC
 439   static void add(oop *derived, oop *base);  // Called during scavenge/GC
 440   static void update_pointers();             // Called after  scavenge/GC
 441   static bool is_empty();
 442   static bool is_active()                    { return _active; }
 443   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 
  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 class frame;
  44 class RegisterMap;
  45 class OopClosure;
  46 class CodeBlob;
  47 
  48 class OopMapValue {
  49   friend class VMStructs;
  50 private:
  51   short _value;
  52   int value() const                                 { return _value; }
  53   void set_value(int value)                         { _value = value; }
  54   short _content_reg;
  55 
  56 public:
  57   // Constants
  58   enum { type_bits                = 4, // 5,
  59          register_bits            = BitsPerShort - type_bits };
  60 
  61   enum { type_shift               = 0,
  62          register_shift           = type_bits };
  63 
  64   enum { type_mask                = right_n_bits(type_bits),
  65          type_mask_in_place       = type_mask << type_shift,
  66          register_mask            = right_n_bits(register_bits),
  67          register_mask_in_place   = register_mask << register_shift };
  68 
  69   enum oop_types {              // must fit in type_bits
  70          unused_value =0,       // powers of 2, for masking OopMapStream
  71          oop_value = 1,
  72          narrowoop_value = 2,
  73          callee_saved_value = 4,
  74          derived_oop_value= 8,
  75          /*live_value = 16*/ };
  76 
  77   // Constructors
  78   OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }
  79   OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg, t); set_content_reg(VMRegImpl::Bad()); }
  80   OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg, t); set_content_reg(reg2); }
  81   OopMapValue (CompressedReadStream* stream) { read_from(stream); }
  82   OopMapValue (const OopMapValue& o) : _value(o._value), _content_reg(o._content_reg) {}
  83 
  84   bool equals(const OopMapValue& o) {
  85     return _value == o._value && _content_reg == o._content_reg;
  86   }
  87 
  88   // Archiving
  89   void write_on(CompressedWriteStream* stream) {
  90     stream->write_int(value());
  91     if(is_callee_saved() || is_derived_oop()) {
  92       stream->write_int(content_reg()->value());
  93     }
  94   }
  95 
  96   void read_from(CompressedReadStream* stream) {
  97     set_value(stream->read_int());
  98     if (is_callee_saved() || is_derived_oop()) {
  99       set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));
 100     }
 101   }
 102 
 103   // Querying
 104   bool is_oop()               { return mask_bits(value(), type_mask_in_place) == oop_value; }
 105   bool is_narrowoop()           { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }
 106   bool is_callee_saved()      { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }
 107   bool is_derived_oop()       { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }
 108   // bool is_live()              { return mask_bits(value(), type_mask_in_place) == live_value; }
 109   bool is_oop_or_narrow()     { return is_oop() || is_narrowoop(); }
 110 
 111   void set_oop()              { set_value((value() & register_mask_in_place) | oop_value); }
 112   void set_narrowoop()          { set_value((value() & register_mask_in_place) | narrowoop_value); }
 113   void set_callee_saved()     { set_value((value() & register_mask_in_place) | callee_saved_value); }
 114   void set_derived_oop()      { set_value((value() & register_mask_in_place) | derived_oop_value); }
 115   // void set_live()             { set_value((value() & register_mask_in_place) | live_value); }
 116 
 117   VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }
 118   oop_types type() const      { return (oop_types)mask_bits(value(), type_mask_in_place); }
 119 
 120   static bool legal_vm_reg_name(VMReg p) {
 121     return (p->value()  == (p->value() & register_mask));
 122   }
 123 
 124   void set_reg_type(VMReg p, oop_types t) {
 125     set_value((p->value() << register_shift) | t);
 126     assert(reg() == p, "sanity check" );
 127     assert(type() == t, "sanity check" );
 128   }
 129 
 130 
 131   VMReg content_reg() const       { return VMRegImpl::as_VMReg(_content_reg, true); }
 132   void set_content_reg(VMReg r)   { _content_reg = r->value(); }
 133 
 134   // Physical location queries
 135   bool is_register_loc()      { return reg()->is_reg(); }
 136   bool is_stack_loc()         { return reg()->is_stack(); }
 137 
 138   // Returns offset from sp.
 139   int stack_offset() {
 140     assert(is_stack_loc(), "must be stack location");
 141     return reg()->reg2stack();
 142   }
 143 
 144   void print_on(outputStream* st) const;
 145   void print() const;
 146 };
 147 
 148 
 149 class OopMap: public ResourceObj {
 150   friend class OopMapStream;
 151   friend class VMStructs;
 152   friend class OopMapSet;
 153   friend class OopMapSort;
 154  private:
 155   int  _pc_offset; // offset in the code that this OopMap corresponds to
 156   int  _omv_count; // number of OopMapValues in the stream
 157   int  _num_oops;  // number of oops
 158   int  _index;     // index in OopMapSet
 159   CompressedWriteStream* _write_stream;
 160 
 161   debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
 162 
 163   // Accessors
 164   int omv_count() const                       { return _omv_count; }
 165   void set_omv_count(int value)               { _omv_count = value; }
 166   void increment_count()                      { _omv_count++; }
 167   void increment_num_oops()                   { _num_oops++; }
 168   CompressedWriteStream* write_stream() const { return _write_stream; }
 169   void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
 170 
 171  private:
 172   enum DeepCopyToken { _deep_copy_token };
 173   OopMap(DeepCopyToken, OopMap* source);  // used only by deep_copy
 174 
 175  public:
 176   OopMap(int frame_size, int arg_count);
 177 
 178   // pc-offset handling
 179   int offset() const     { return _pc_offset; }
 180   void set_offset(int o) { _pc_offset = o; }
 181   int count() const { return _omv_count; }
 182   int data_size() const  { return write_stream()->position(); }
 183   address data() const { return write_stream()->buffer(); }
 184   int num_oops() const { return _num_oops; }
 185   int index() const { return _index; }
 186 
 187   // Check to avoid double insertion
 188   debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })
 189 
 190   // Construction
 191   // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
 192   // slots to hold 4-byte values like ints and floats in the LP64 build.
 193   void set_oop  ( VMReg local);
 194   void set_value( VMReg local);
 195   void set_narrowoop(VMReg local);
 196   void set_dead ( VMReg local);
 197   void set_callee_saved( VMReg local, VMReg caller_machine_register );
 198   void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
 199   void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
 200 
 201   int heap_size() const;
 202   void copy_data_to(address addr) const;
 203   void copy_and_sort_data_to(address addr) const;
 204   OopMap* deep_copy();
 205 
 206   bool has_derived_pointer() const PRODUCT_RETURN0;
 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   int _om_count;
 224   int _om_size;
 225   OopMap** _om_data;
 226 
 227   int om_count() const              { return _om_count; }
 228   void set_om_count(int value)      { _om_count = value; }
 229   void increment_count()            { _om_count++; }
 230   int om_size() const               { return _om_size; }
 231   void set_om_size(int value)       { _om_size = value; }
 232   OopMap** om_data() const          { return _om_data; }
 233   void set_om_data(OopMap** value)  { _om_data = value; }
 234   void grow_om_data();
 235   void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }
 236 
 237  public:
 238   OopMapSet();
 239 
 240   // returns the number of OopMaps in this OopMapSet
 241   int size() const            { return _om_count; }
 242   // returns the OopMap at a given index
 243   OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }
 244 
 245   // Collect OopMaps.
 246   int add_gc_map(int pc, OopMap* map);
 247 
 248   // Returns the only oop map. Used for reconstructing
 249   // Adapter frames during deoptimization
 250   OopMap* singular_oop_map();
 251 
 252   // returns OopMap in that is anchored to the pc
 253   OopMap* find_map_at_offset(int pc_offset) const;
 254 
 255   int heap_size() const;
 256 
 257   // Methods oops_do() and all_do() filter out NULL oops and
 258   // oop == CompressedOops::base() before passing oops
 259   // to closures.
 260 
 261   static const ImmutableOopMap* find_map(const CodeBlob* cb, address pc);
 262   static const ImmutableOopMap* find_map(const frame *fr);
 263 
 264   // Iterates through frame for a compiled method
 265   static void oops_do            (const frame* fr, const RegisterMap* reg_map,
 266                                   OopClosure* f, DerivedOopClosure* df);
 267   static void oops_do            (const frame* fr,
 268                                   const RegisterMap* reg_map, OopClosure* f) { oops_do(fr, reg_map, f, NULL); }
 269   static void update_register_map(const frame* fr, RegisterMap *reg_map);
 270 
 271 #ifndef PRODUCT
 272   static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map);
 273 #endif
 274 
 275   // // Iterates through frame for a compiled method for dead ones and values, too
 276   // static void all_do(const frame* fr, const RegisterMap* reg_map,
 277   //                    OopClosure* oop_fn,
 278   //                    DerivedOopClosure* derived_oop_fn,
 279   //                    OopClosure* value_fn);
 280 
 281   // Printing
 282   void print_on(outputStream* st) const;
 283   void print() const;
 284 };
 285 
 286 class ImmutableOopMapBuilder;
 287 
 288 class ExplodedOopMap : public CHeapObj<mtCode> {
 289 private:
 290   OopMapValue* _oopValues;
 291   OopMapValue* _calleeSavedValues;
 292   OopMapValue* _derivedValues;
 293 
 294   int _nrOopValues;
 295   int _nrCalleeSavedValuesCount;
 296   int _nrDerivedValues;
 297 
 298   OopMapValue* copyOopMapValues(const ImmutableOopMap* oopMap, int mask, int* nr);
 299 public:
 300   ExplodedOopMap(const ImmutableOopMap* oopMap);
 301   OopMapValue* values(int mask);
 302   int count(int mask);
 303 
 304   bool has_derived() const { return _nrDerivedValues > 0; }
 305 };
 306 
 307 class ExplodedOopMapStream;
 308 
 309 class OopMapClosure : public Closure {
 310  public:
 311   virtual void do_value(VMReg reg, OopMapValue::oop_types type) = 0;
 312 };
 313 
 314 template <typename OopFnT, typename DerivedOopFnT, typename ValueFilterT>
 315 class OopMapDo;
 316 
 317 class ImmutableOopMap {
 318   friend class OopMapStream;
 319   friend class VMStructs;
 320   friend class ExplodedOopMapStream;
 321   template <typename OopFnT, typename DerivedOopFnT, typename ValueFilterT>
 322   friend class OopMapDo;
 323 #ifdef ASSERT
 324   friend class ImmutableOopMapBuilder;
 325 #endif
 326 private:
 327   ExplodedOopMap* _exploded;
 328   mutable address _freeze_stub;
 329   mutable address _thaw_stub;
 330   int _count; // contains the number of entries in this OopMap
 331   int _num_oops;
 332 
 333   address data_addr() const { return (address) this + sizeof(ImmutableOopMap); }
 334 public:
 335   ImmutableOopMap(const OopMap* oopmap);
 336 
 337   void set_exploded(ExplodedOopMap* exploded) { _exploded = exploded; }
 338   bool has_exploded() const { return _exploded != NULL; }
 339   bool has_derived_pointer() const PRODUCT_RETURN0;
 340   bool has_derived() const { return _exploded->has_derived(); } // DEBUG rbackman
 341   int count() const { return _count; }
 342   int num_oops() const { return _num_oops; }
 343 #ifdef ASSERT
 344   int nr_of_bytes() const; // this is an expensive operation, only used in debug builds
 345 #endif
 346 
 347   void oops_do(const frame* fr, const RegisterMap* reg_map, OopClosure* f, DerivedOopClosure* df) const;
 348   void all_do(const frame *fr, int mask, OopMapClosure* fn) const;
 349   void update_register_map(const frame* fr, RegisterMap *reg_map) const;
 350 
 351   // Printing
 352   void print_on(outputStream* st) const;
 353   void print() const;
 354 
 355   void generate_stub(const CodeBlob* cb) const;
 356   address freeze_stub() const { return _freeze_stub; }
 357   address thaw_stub() const { return _thaw_stub; }
 358 };
 359 
 360 class ImmutableOopMapSet;
 361 class ImmutableOopMap;
 362 class OopMapSet;
 363 
 364 class ImmutableOopMapPair {
 365   friend class VMStructs;
 366 private:
 367   int _pc_offset; // program counter offset from the beginning of the method
 368   int _oopmap_offset; // offset in the data in the ImmutableOopMapSet where the ImmutableOopMap is located
 369 public:
 370   ImmutableOopMapPair(int pc_offset, int oopmap_offset) : _pc_offset(pc_offset), _oopmap_offset(oopmap_offset) {
 371     assert(pc_offset >= 0 && oopmap_offset >= 0, "check");
 372   }
 373   const ImmutableOopMap* get_from(const ImmutableOopMapSet* set) const;
 374 
 375   int pc_offset() const { return _pc_offset; }
 376   int oopmap_offset() const { return _oopmap_offset; }
 377 };


 380   friend class VMStructs;
 381 private:
 382   int _count; // nr of ImmutableOopMapPairs in the Set
 383   int _size; // nr of bytes including ImmutableOopMapSet itself
 384 
 385   address data() const { return (address) this + sizeof(*this) + sizeof(ImmutableOopMapPair) * _count; }
 386 
 387 public:
 388   ImmutableOopMapSet(const OopMapSet* oopmap_set, int size) : _count(oopmap_set->size()), _size(size) {}
 389 
 390   ImmutableOopMap* oopmap_at_offset(int offset) const {
 391     assert(offset >= 0 && offset < _size, "must be within boundaries");
 392     address addr = data() + offset;
 393     return (ImmutableOopMap*) addr;
 394   }
 395 
 396   ImmutableOopMapPair* get_pairs() const { return (ImmutableOopMapPair*) ((address) this + sizeof(*this)); }
 397 
 398   static ImmutableOopMapSet* build_from(const OopMapSet* oopmap_set);
 399 
 400   int find_slot_for_offset(int pc_offset) const;
 401   const ImmutableOopMap* find_map_at_offset(int pc_offset) const;
 402   const ImmutableOopMap* find_map_at_slot(int slot, int pc_offset) const;
 403 
 404   const ImmutableOopMapPair* pair_at(int index) const { assert(index >= 0 && index < _count, "check"); return &get_pairs()[index]; }
 405 
 406   int count() const { return _count; }
 407   int nr_of_bytes() const { return _size; }
 408 
 409   void print_on(outputStream* st) const;
 410   void print() const;
 411 };
 412 
 413 class OopMapStream : public StackObj {
 414  private:
 415   CompressedReadStream _stream;
 416   int _mask;
 417   int _size;
 418   int _position;
 419   bool _valid_omv;
 420   OopMapValue _omv;
 421   void find_next();
 422 
 423  public:
 424   OopMapStream(const OopMap* oop_map, int oop_types_mask = OopMapValue::type_mask_in_place);
 425   OopMapStream(const ImmutableOopMap* oop_map, int oop_types_mask = OopMapValue::type_mask_in_place);
 426   bool is_done()                        { if(!_valid_omv) { find_next(); } return !_valid_omv; }
 427   void next()                           { find_next(); }
 428   OopMapValue current()                 { return _omv; }
 429 #ifdef ASSERT
 430   int stream_position() const           { return _stream.position(); }
 431 #endif
 432 };
 433 
 434 class ExplodedOopMapStream : public StackObj {
 435 private:
 436   int _current;
 437   int _max;
 438   OopMapValue* _values;
 439 public:
 440   ExplodedOopMapStream(const ImmutableOopMap* oopMap, int mask) : _current(0), _max(oopMap->_exploded->count(mask)), _values(oopMap->_exploded->values(mask)) {}
 441   bool is_done() const { return _current >= _max; }
 442   void next() { ++_current; }
 443   OopMapValue current() { return _values[_current]; }
 444 };
 445 
 446 
 447 class ImmutableOopMapBuilder {
 448 private:
 449   class Mapping;
 450 
 451 private:
 452   const OopMapSet* _set;
 453   const OopMap* _empty;
 454   const OopMap* _last;
 455   int _empty_offset;
 456   int _last_offset;
 457   int _offset;
 458   int _required;
 459   Mapping* _mapping;
 460   ImmutableOopMapSet* _new_set;
 461 
 462   /* Used for bookkeeping when building ImmutableOopMaps */
 463   class Mapping : public ResourceObj {
 464   public:
 465     enum kind_t { OOPMAP_UNKNOWN = 0, OOPMAP_NEW = 1, OOPMAP_EMPTY = 2, OOPMAP_DUPLICATE = 3 };
 466 


 496     if (_last != NULL && _last->count() > 0 && _last->equals(map)) {
 497       return true;
 498     }
 499     return false;
 500   }
 501 
 502 #ifdef ASSERT
 503   void verify(address buffer, int size, const ImmutableOopMapSet* set);
 504 #endif
 505 
 506   bool has_empty() const {
 507     return _empty_offset != -1;
 508   }
 509 
 510   int size_for(const OopMap* map) const;
 511   void fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
 512   int fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
 513   void fill(ImmutableOopMapSet* set, int size);
 514 };
 515 
 516 class SkipNullValue {
 517 public:
 518   static inline bool should_skip(oop val);
 519 };
 520 
 521 class IncludeAllValues {
 522 public:
 523   static bool should_skip(oop value) { return false; }
 524 };
 525 
 526 template <typename OopFnT, typename DerivedOopFnT, typename ValueFilterT>
 527 class OopMapDo {
 528 private:
 529   OopFnT* _oop_fn;
 530   DerivedOopFnT* _derived_oop_fn;
 531 public:
 532   OopMapDo(OopFnT* oop_fn, DerivedOopFnT* derived_oop_fn) : _oop_fn(oop_fn), _derived_oop_fn(derived_oop_fn) {}
 533   template <typename RegisterMapT>
 534   void oops_do(const frame* fr, const RegisterMapT* reg_map, const ImmutableOopMap* oopmap);
 535 private:
 536   template <typename OopMapStreamT, typename RegisterMapT>
 537   void iterate_oops_do(const frame *fr, const RegisterMapT *reg_map, const ImmutableOopMap* oopmap);
 538   template <typename OopMapStreamT, typename RegisterMapT>
 539   void walk_derived_pointers(const frame *fr, const ImmutableOopMap* map, const RegisterMapT *reg_map);
 540   template <typename OopMapStreamT, typename RegisterMapT>
 541   void walk_derived_pointers1(OopMapStreamT& oms, const frame *fr, const RegisterMapT *reg_map);
 542 };
 543 
 544 // Derived pointer support. This table keeps track of all derived points on a
 545 // stack.  It is cleared before each scavenge/GC.  During the traversal of all
 546 // oops, it is filled in with references to all locations that contains a
 547 // derived oop (assumed to be very few).  When the GC is complete, the derived
 548 // pointers are updated based on their base pointers new value and an offset.
 549 #if COMPILER2_OR_JVMCI
 550 class DerivedPointerTable : public AllStatic {
 551   friend class VMStructs;
 552  private:
 553   class Entry;
 554   static bool _active;                      // do not record pointers for verify pass etc.
 555 
 556  public:
 557   static void clear();                       // Called before scavenge/GC
 558   static void add(oop *derived, oop *base);  // Called during scavenge/GC
 559   static void update_pointers();             // Called after  scavenge/GC
 560   static bool is_empty();
 561   static bool is_active()                    { return _active; }
 562   static void set_active(bool value)         { _active = value; }


< prev index next >