src/share/vm/compiler/oopMap.hpp

Thu, 10 Apr 2008 15:49:16 -0400

author
sbohne
date
Thu, 10 Apr 2008 15:49:16 -0400
changeset 528
c6ff24ceec1c
parent 460
c5cbd367e4d1
child 535
c7c777385a15
permissions
-rw-r--r--

6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes

     1 /*
     2  * Copyright 1998-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // Interface for generating the frame map for compiled code.  A frame map
    26 // describes for a specific pc whether each register and frame stack slot is:
    27 //   Oop         - A GC root for current frame
    28 //   Value       - Live non-oop, non-float value: int, either half of double
    29 //   Dead        - Dead; can be Zapped for debugging
    30 //   CalleeXX    - Callee saved; also describes which caller register is saved
    31 //   DerivedXX   - A derived oop; original oop is described.
    32 //
    33 // OopMapValue describes a single OopMap entry
    35 class frame;
    36 class RegisterMap;
    37 class DerivedPointerEntry;
    39 class OopMapValue: public StackObj {
    40   friend class VMStructs;
    41 private:
    42   short _value;
    43   int value() const                                 { return _value; }
    44   void set_value(int value)                         { _value = value; }
    45   short _content_reg;
    47 public:
    48   // Constants
    49   enum { type_bits                = 6,
    50          register_bits            = BitsPerShort - type_bits };
    52   enum { type_shift               = 0,
    53          register_shift           = type_bits };
    55   enum { type_mask                = right_n_bits(type_bits),
    56          type_mask_in_place       = type_mask << type_shift,
    57          register_mask            = right_n_bits(register_bits),
    58          register_mask_in_place   = register_mask << register_shift };
    60   enum oop_types {              // must fit in type_bits
    61          unused_value =0,       // powers of 2, for masking OopMapStream
    62          oop_value = 1,
    63          value_value = 2,
    64          dead_value = 4,
    65          callee_saved_value = 8,
    66          derived_oop_value= 16,
    67          stack_obj = 32 };
    69   // Constructors
    70   OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }
    71   OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg,t); }
    72   OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg,t); set_content_reg(reg2); }
    73   OopMapValue (CompressedReadStream* stream) { read_from(stream); }
    75   // Archiving
    76   void write_on(CompressedWriteStream* stream) {
    77     stream->write_int(value());
    78     if(is_callee_saved() || is_derived_oop()) {
    79       stream->write_int(content_reg()->value());
    80     }
    81   }
    83   void read_from(CompressedReadStream* stream) {
    84     set_value(stream->read_int());
    85     if(is_callee_saved() || is_derived_oop()) {
    86       set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));
    87     }
    88   }
    90   // Querying
    91   bool is_oop()               { return mask_bits(value(), type_mask_in_place) == oop_value; }
    92   bool is_value()             { return mask_bits(value(), type_mask_in_place) == value_value; }
    93   bool is_dead()              { return mask_bits(value(), type_mask_in_place) == dead_value; }
    94   bool is_callee_saved()      { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }
    95   bool is_derived_oop()       { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }
    96   bool is_stack_obj()         { return mask_bits(value(), type_mask_in_place) == stack_obj; }
    98   void set_oop()              { set_value((value() & register_mask_in_place) | oop_value); }
    99   void set_value()            { set_value((value() & register_mask_in_place) | value_value); }
   100   void set_dead()             { set_value((value() & register_mask_in_place) | dead_value); }
   101   void set_callee_saved()     { set_value((value() & register_mask_in_place) | callee_saved_value); }
   102   void set_derived_oop()      { set_value((value() & register_mask_in_place) | derived_oop_value); }
   103   void set_stack_obj()        { set_value((value() & register_mask_in_place) | stack_obj); }
   105   VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }
   106   oop_types type() const      { return (oop_types)mask_bits(value(), type_mask_in_place); }
   108   static bool legal_vm_reg_name(VMReg p) {
   109     return (p->value()  == (p->value() & register_mask));
   110   }
   112   void set_reg_type(VMReg p, oop_types t) {
   113     set_value((p->value() << register_shift) | t);
   114     assert(reg() == p, "sanity check" );
   115     assert(type() == t, "sanity check" );
   116   }
   119   VMReg content_reg() const       { return VMRegImpl::as_VMReg(_content_reg, true); }
   120   void set_content_reg(VMReg r)   { _content_reg = r->value(); }
   122   // Physical location queries
   123   bool is_register_loc()      { return reg()->is_reg(); }
   124   bool is_stack_loc()         { return reg()->is_stack(); }
   126   // Returns offset from sp.
   127   int stack_offset() {
   128     assert(is_stack_loc(), "must be stack location");
   129     return reg()->reg2stack();
   130   }
   132   void print_on(outputStream* st) const PRODUCT_RETURN;
   133   void print() const { print_on(tty); }
   134 };
   137 class OopMap: public ResourceObj {
   138   friend class OopMapStream;
   139   friend class VMStructs;
   140  private:
   141   int  _pc_offset;
   142   int  _omv_count;
   143   int  _omv_data_size;
   144   unsigned char* _omv_data;
   145   CompressedWriteStream* _write_stream;
   147   debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
   149   // Accessors
   150   unsigned char* omv_data() const             { return _omv_data; }
   151   void set_omv_data(unsigned char* value)     { _omv_data = value; }
   152   int omv_data_size() const                   { return _omv_data_size; }
   153   void set_omv_data_size(int value)           { _omv_data_size = value; }
   154   int omv_count() const                       { return _omv_count; }
   155   void set_omv_count(int value)               { _omv_count = value; }
   156   void increment_count()                      { _omv_count++; }
   157   CompressedWriteStream* write_stream() const { return _write_stream; }
   158   void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
   160  private:
   161   enum DeepCopyToken { _deep_copy_token };
   162   OopMap(DeepCopyToken, OopMap* source);  // used only by deep_copy
   164  public:
   165   OopMap(int frame_size, int arg_count);
   167   // pc-offset handling
   168   int offset() const     { return _pc_offset; }
   169   void set_offset(int o) { _pc_offset = o; }
   171   // Check to avoid double insertion
   172   debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })
   174   // Construction
   175   // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
   176   // slots to hold 4-byte values like ints and floats in the LP64 build.
   177   void set_oop  ( VMReg local);
   178   void set_value( VMReg local);
   179   void set_dead ( VMReg local);
   180   void set_callee_saved( VMReg local, VMReg caller_machine_register );
   181   void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
   182   void set_stack_obj( VMReg local);
   183   void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
   185   int heap_size() const;
   186   void copy_to(address addr);
   187   OopMap* deep_copy();
   189   bool has_derived_pointer() const PRODUCT_RETURN0;
   191   bool legal_vm_reg_name(VMReg local) {
   192      return OopMapValue::legal_vm_reg_name(local);
   193   }
   195   // Printing
   196   void print_on(outputStream* st) const PRODUCT_RETURN;
   197   void print() const { print_on(tty); }
   198 };
   201 class OopMapSet : public ResourceObj {
   202   friend class VMStructs;
   203  private:
   204   int _om_count;
   205   int _om_size;
   206   OopMap** _om_data;
   208   int om_count() const              { return _om_count; }
   209   void set_om_count(int value)      { _om_count = value; }
   210   void increment_count()            { _om_count++; }
   211   int om_size() const               { return _om_size; }
   212   void set_om_size(int value)       { _om_size = value; }
   213   OopMap** om_data() const          { return _om_data; }
   214   void set_om_data(OopMap** value)  { _om_data = value; }
   215   void grow_om_data();
   216   void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }
   218  public:
   219   OopMapSet();
   221   // returns the number of OopMaps in this OopMapSet
   222   int size() const            { return _om_count; }
   223   // returns the OopMap at a given index
   224   OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }
   226   // Collect OopMaps.
   227   void add_gc_map(int pc, OopMap* map);
   229   // Returns the only oop map. Used for reconstructing
   230   // Adapter frames during deoptimization
   231   OopMap* singular_oop_map();
   233   // returns OopMap in that is anchored to the pc
   234   OopMap* find_map_at_offset(int pc_offset) const;
   236   int heap_size() const;
   237   void copy_to(address addr);
   239   // Iterates through frame for a compiled method
   240   static void oops_do            (const frame* fr,
   241                                   const RegisterMap* reg_map, OopClosure* f);
   242   static void update_register_map(const frame* fr, RegisterMap *reg_map);
   244   // Iterates through frame for a compiled method for dead ones and values, too
   245   static void all_do(const frame* fr, const RegisterMap* reg_map,
   246                      OopClosure* oop_fn,
   247                      void derived_oop_fn(oop* base, oop* derived),
   248                      OopClosure* value_fn, OopClosure* dead_fn);
   250   // Printing
   251   void print_on(outputStream* st) const PRODUCT_RETURN;
   252   void print() const { print_on(tty); }
   253 };
   256 class OopMapStream : public StackObj {
   257  private:
   258   CompressedReadStream* _stream;
   259   int _mask;
   260   int _size;
   261   int _position;
   262   bool _valid_omv;
   263   OopMapValue _omv;
   264   void find_next();
   266  public:
   267   OopMapStream(OopMap* oop_map);
   268   OopMapStream(OopMap* oop_map, int oop_types_mask);
   269   bool is_done()                        { if(!_valid_omv) { find_next(); } return !_valid_omv; }
   270   void next()                           { find_next(); }
   271   OopMapValue current()                 { return _omv; }
   272 };
   275 // Derived pointer support. This table keeps track of all derived points on a
   276 // stack.  It is cleared before each scavenge/GC.  During the traversal of all
   277 // oops, it is filled in with references to all locations that contains a
   278 // derived oop (assumed to be very few).  When the GC is complete, the derived
   279 // pointers are updated based on their base pointers new value and an offset.
   280 #ifdef COMPILER2
   281 class DerivedPointerTable : public AllStatic {
   282   friend class VMStructs;
   283  private:
   284    static GrowableArray<DerivedPointerEntry*>* _list;
   285    static bool _active;                      // do not record pointers for verify pass etc.
   286  public:
   287   static void clear();                       // Called before scavenge/GC
   288   static void add(oop *derived, oop *base);  // Called during scavenge/GC
   289   static void update_pointers();             // Called after  scavenge/GC
   290   static bool is_empty()                     { return _list == NULL || _list->is_empty(); }
   291   static bool is_active()                    { return _active; }
   292   static void set_active(bool value)         { _active = value; }
   293 };
   295 // A utility class to temporarily "deactivate" the DerivedPointerTable.
   296 // (Note: clients are responsible for any MT-safety issues)
   297 class DerivedPointerTableDeactivate: public StackObj {
   298  private:
   299   bool _active;
   300  public:
   301   DerivedPointerTableDeactivate() {
   302     _active = DerivedPointerTable::is_active();
   303     if (_active) {
   304       DerivedPointerTable::set_active(false);
   305     }
   306   }
   308   ~DerivedPointerTableDeactivate() {
   309     assert(!DerivedPointerTable::is_active(),
   310            "Inconsistency: not MT-safe");
   311     if (_active) {
   312       DerivedPointerTable::set_active(true);
   313     }
   314   }
   315 };
   316 #endif // COMPILER2

mercurial