src/share/vm/compiler/oopMap.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/compiler/oopMap.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,327 @@
     1.4 +/*
     1.5 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_COMPILER_OOPMAP_HPP
    1.29 +#define SHARE_VM_COMPILER_OOPMAP_HPP
    1.30 +
    1.31 +#include "code/compressedStream.hpp"
    1.32 +#include "code/vmreg.hpp"
    1.33 +#include "memory/allocation.hpp"
    1.34 +#include "utilities/growableArray.hpp"
    1.35 +
    1.36 +// Interface for generating the frame map for compiled code.  A frame map
    1.37 +// describes for a specific pc whether each register and frame stack slot is:
    1.38 +//   Oop         - A GC root for current frame
    1.39 +//   Value       - Live non-oop, non-float value: int, either half of double
    1.40 +//   Dead        - Dead; can be Zapped for debugging
    1.41 +//   CalleeXX    - Callee saved; also describes which caller register is saved
    1.42 +//   DerivedXX   - A derived oop; original oop is described.
    1.43 +//
    1.44 +// OopMapValue describes a single OopMap entry
    1.45 +
    1.46 +class frame;
    1.47 +class RegisterMap;
    1.48 +class DerivedPointerEntry;
    1.49 +
    1.50 +class OopMapValue: public StackObj {
    1.51 +  friend class VMStructs;
    1.52 +private:
    1.53 +  short _value;
    1.54 +  int value() const                                 { return _value; }
    1.55 +  void set_value(int value)                         { _value = value; }
    1.56 +  short _content_reg;
    1.57 +
    1.58 +public:
    1.59 +  // Constants
    1.60 +  enum { type_bits                = 5,
    1.61 +         register_bits            = BitsPerShort - type_bits };
    1.62 +
    1.63 +  enum { type_shift               = 0,
    1.64 +         register_shift           = type_bits };
    1.65 +
    1.66 +  enum { type_mask                = right_n_bits(type_bits),
    1.67 +         type_mask_in_place       = type_mask << type_shift,
    1.68 +         register_mask            = right_n_bits(register_bits),
    1.69 +         register_mask_in_place   = register_mask << register_shift };
    1.70 +
    1.71 +  enum oop_types {              // must fit in type_bits
    1.72 +         unused_value =0,       // powers of 2, for masking OopMapStream
    1.73 +         oop_value = 1,
    1.74 +         value_value = 2,
    1.75 +         narrowoop_value = 4,
    1.76 +         callee_saved_value = 8,
    1.77 +         derived_oop_value= 16 };
    1.78 +
    1.79 +  // Constructors
    1.80 +  OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }
    1.81 +  OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg,t); }
    1.82 +  OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg,t); set_content_reg(reg2); }
    1.83 +  OopMapValue (CompressedReadStream* stream) { read_from(stream); }
    1.84 +
    1.85 +  // Archiving
    1.86 +  void write_on(CompressedWriteStream* stream) {
    1.87 +    stream->write_int(value());
    1.88 +    if(is_callee_saved() || is_derived_oop()) {
    1.89 +      stream->write_int(content_reg()->value());
    1.90 +    }
    1.91 +  }
    1.92 +
    1.93 +  void read_from(CompressedReadStream* stream) {
    1.94 +    set_value(stream->read_int());
    1.95 +    if(is_callee_saved() || is_derived_oop()) {
    1.96 +      set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));
    1.97 +    }
    1.98 +  }
    1.99 +
   1.100 +  // Querying
   1.101 +  bool is_oop()               { return mask_bits(value(), type_mask_in_place) == oop_value; }
   1.102 +  bool is_value()             { return mask_bits(value(), type_mask_in_place) == value_value; }
   1.103 +  bool is_narrowoop()           { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }
   1.104 +  bool is_callee_saved()      { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }
   1.105 +  bool is_derived_oop()       { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }
   1.106 +
   1.107 +  void set_oop()              { set_value((value() & register_mask_in_place) | oop_value); }
   1.108 +  void set_value()            { set_value((value() & register_mask_in_place) | value_value); }
   1.109 +  void set_narrowoop()          { set_value((value() & register_mask_in_place) | narrowoop_value); }
   1.110 +  void set_callee_saved()     { set_value((value() & register_mask_in_place) | callee_saved_value); }
   1.111 +  void set_derived_oop()      { set_value((value() & register_mask_in_place) | derived_oop_value); }
   1.112 +
   1.113 +  VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }
   1.114 +  oop_types type() const      { return (oop_types)mask_bits(value(), type_mask_in_place); }
   1.115 +
   1.116 +  static bool legal_vm_reg_name(VMReg p) {
   1.117 +    return (p->value()  == (p->value() & register_mask));
   1.118 +  }
   1.119 +
   1.120 +  void set_reg_type(VMReg p, oop_types t) {
   1.121 +    set_value((p->value() << register_shift) | t);
   1.122 +    assert(reg() == p, "sanity check" );
   1.123 +    assert(type() == t, "sanity check" );
   1.124 +  }
   1.125 +
   1.126 +
   1.127 +  VMReg content_reg() const       { return VMRegImpl::as_VMReg(_content_reg, true); }
   1.128 +  void set_content_reg(VMReg r)   { _content_reg = r->value(); }
   1.129 +
   1.130 +  // Physical location queries
   1.131 +  bool is_register_loc()      { return reg()->is_reg(); }
   1.132 +  bool is_stack_loc()         { return reg()->is_stack(); }
   1.133 +
   1.134 +  // Returns offset from sp.
   1.135 +  int stack_offset() {
   1.136 +    assert(is_stack_loc(), "must be stack location");
   1.137 +    return reg()->reg2stack();
   1.138 +  }
   1.139 +
   1.140 +  void print_on(outputStream* st) const;
   1.141 +  void print() const { print_on(tty); }
   1.142 +};
   1.143 +
   1.144 +
   1.145 +class OopMap: public ResourceObj {
   1.146 +  friend class OopMapStream;
   1.147 +  friend class VMStructs;
   1.148 + private:
   1.149 +  int  _pc_offset;
   1.150 +  int  _omv_count;
   1.151 +  int  _omv_data_size;
   1.152 +  unsigned char* _omv_data;
   1.153 +  CompressedWriteStream* _write_stream;
   1.154 +
   1.155 +  debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
   1.156 +
   1.157 +  // Accessors
   1.158 +  unsigned char* omv_data() const             { return _omv_data; }
   1.159 +  void set_omv_data(unsigned char* value)     { _omv_data = value; }
   1.160 +  int omv_data_size() const                   { return _omv_data_size; }
   1.161 +  void set_omv_data_size(int value)           { _omv_data_size = value; }
   1.162 +  int omv_count() const                       { return _omv_count; }
   1.163 +  void set_omv_count(int value)               { _omv_count = value; }
   1.164 +  void increment_count()                      { _omv_count++; }
   1.165 +  CompressedWriteStream* write_stream() const { return _write_stream; }
   1.166 +  void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
   1.167 +
   1.168 + private:
   1.169 +  enum DeepCopyToken { _deep_copy_token };
   1.170 +  OopMap(DeepCopyToken, OopMap* source);  // used only by deep_copy
   1.171 +
   1.172 + public:
   1.173 +  OopMap(int frame_size, int arg_count);
   1.174 +
   1.175 +  // pc-offset handling
   1.176 +  int offset() const     { return _pc_offset; }
   1.177 +  void set_offset(int o) { _pc_offset = o; }
   1.178 +
   1.179 +  // Check to avoid double insertion
   1.180 +  debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })
   1.181 +
   1.182 +  // Construction
   1.183 +  // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
   1.184 +  // slots to hold 4-byte values like ints and floats in the LP64 build.
   1.185 +  void set_oop  ( VMReg local);
   1.186 +  void set_value( VMReg local);
   1.187 +  void set_narrowoop(VMReg local);
   1.188 +  void set_dead ( VMReg local);
   1.189 +  void set_callee_saved( VMReg local, VMReg caller_machine_register );
   1.190 +  void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
   1.191 +  void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
   1.192 +
   1.193 +  int heap_size() const;
   1.194 +  void copy_to(address addr);
   1.195 +  OopMap* deep_copy();
   1.196 +
   1.197 +  bool has_derived_pointer() const PRODUCT_RETURN0;
   1.198 +
   1.199 +  bool legal_vm_reg_name(VMReg local) {
   1.200 +     return OopMapValue::legal_vm_reg_name(local);
   1.201 +  }
   1.202 +
   1.203 +  // Printing
   1.204 +  void print_on(outputStream* st) const;
   1.205 +  void print() const { print_on(tty); }
   1.206 +};
   1.207 +
   1.208 +
   1.209 +class OopMapSet : public ResourceObj {
   1.210 +  friend class VMStructs;
   1.211 + private:
   1.212 +  int _om_count;
   1.213 +  int _om_size;
   1.214 +  OopMap** _om_data;
   1.215 +
   1.216 +  int om_count() const              { return _om_count; }
   1.217 +  void set_om_count(int value)      { _om_count = value; }
   1.218 +  void increment_count()            { _om_count++; }
   1.219 +  int om_size() const               { return _om_size; }
   1.220 +  void set_om_size(int value)       { _om_size = value; }
   1.221 +  OopMap** om_data() const          { return _om_data; }
   1.222 +  void set_om_data(OopMap** value)  { _om_data = value; }
   1.223 +  void grow_om_data();
   1.224 +  void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }
   1.225 +
   1.226 + public:
   1.227 +  OopMapSet();
   1.228 +
   1.229 +  // returns the number of OopMaps in this OopMapSet
   1.230 +  int size() const            { return _om_count; }
   1.231 +  // returns the OopMap at a given index
   1.232 +  OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }
   1.233 +
   1.234 +  // Collect OopMaps.
   1.235 +  void add_gc_map(int pc, OopMap* map);
   1.236 +
   1.237 +  // Returns the only oop map. Used for reconstructing
   1.238 +  // Adapter frames during deoptimization
   1.239 +  OopMap* singular_oop_map();
   1.240 +
   1.241 +  // returns OopMap in that is anchored to the pc
   1.242 +  OopMap* find_map_at_offset(int pc_offset) const;
   1.243 +
   1.244 +  int heap_size() const;
   1.245 +  void copy_to(address addr);
   1.246 +
   1.247 +  // Methods oops_do() and all_do() filter out NULL oops and
   1.248 +  // oop == Universe::narrow_oop_base() before passing oops
   1.249 +  // to closures.
   1.250 +
   1.251 +  // Iterates through frame for a compiled method
   1.252 +  static void oops_do            (const frame* fr,
   1.253 +                                  const RegisterMap* reg_map, OopClosure* f);
   1.254 +  static void update_register_map(const frame* fr, RegisterMap *reg_map);
   1.255 +
   1.256 +  // Iterates through frame for a compiled method for dead ones and values, too
   1.257 +  static void all_do(const frame* fr, const RegisterMap* reg_map,
   1.258 +                     OopClosure* oop_fn,
   1.259 +                     void derived_oop_fn(oop* base, oop* derived),
   1.260 +                     OopClosure* value_fn);
   1.261 +
   1.262 +  // Printing
   1.263 +  void print_on(outputStream* st) const;
   1.264 +  void print() const { print_on(tty); }
   1.265 +};
   1.266 +
   1.267 +
   1.268 +class OopMapStream : public StackObj {
   1.269 + private:
   1.270 +  CompressedReadStream* _stream;
   1.271 +  int _mask;
   1.272 +  int _size;
   1.273 +  int _position;
   1.274 +  bool _valid_omv;
   1.275 +  OopMapValue _omv;
   1.276 +  void find_next();
   1.277 +
   1.278 + public:
   1.279 +  OopMapStream(OopMap* oop_map);
   1.280 +  OopMapStream(OopMap* oop_map, int oop_types_mask);
   1.281 +  bool is_done()                        { if(!_valid_omv) { find_next(); } return !_valid_omv; }
   1.282 +  void next()                           { find_next(); }
   1.283 +  OopMapValue current()                 { return _omv; }
   1.284 +};
   1.285 +
   1.286 +
   1.287 +// Derived pointer support. This table keeps track of all derived points on a
   1.288 +// stack.  It is cleared before each scavenge/GC.  During the traversal of all
   1.289 +// oops, it is filled in with references to all locations that contains a
   1.290 +// derived oop (assumed to be very few).  When the GC is complete, the derived
   1.291 +// pointers are updated based on their base pointers new value and an offset.
   1.292 +#ifdef COMPILER2
   1.293 +class DerivedPointerTable : public AllStatic {
   1.294 +  friend class VMStructs;
   1.295 + private:
   1.296 +   static GrowableArray<DerivedPointerEntry*>* _list;
   1.297 +   static bool _active;                      // do not record pointers for verify pass etc.
   1.298 + public:
   1.299 +  static void clear();                       // Called before scavenge/GC
   1.300 +  static void add(oop *derived, oop *base);  // Called during scavenge/GC
   1.301 +  static void update_pointers();             // Called after  scavenge/GC
   1.302 +  static bool is_empty()                     { return _list == NULL || _list->is_empty(); }
   1.303 +  static bool is_active()                    { return _active; }
   1.304 +  static void set_active(bool value)         { _active = value; }
   1.305 +};
   1.306 +
   1.307 +// A utility class to temporarily "deactivate" the DerivedPointerTable.
   1.308 +// (Note: clients are responsible for any MT-safety issues)
   1.309 +class DerivedPointerTableDeactivate: public StackObj {
   1.310 + private:
   1.311 +  bool _active;
   1.312 + public:
   1.313 +  DerivedPointerTableDeactivate() {
   1.314 +    _active = DerivedPointerTable::is_active();
   1.315 +    if (_active) {
   1.316 +      DerivedPointerTable::set_active(false);
   1.317 +    }
   1.318 +  }
   1.319 +
   1.320 +  ~DerivedPointerTableDeactivate() {
   1.321 +    assert(!DerivedPointerTable::is_active(),
   1.322 +           "Inconsistency: not MT-safe");
   1.323 +    if (_active) {
   1.324 +      DerivedPointerTable::set_active(true);
   1.325 +    }
   1.326 +  }
   1.327 +};
   1.328 +#endif // COMPILER2
   1.329 +
   1.330 +#endif // SHARE_VM_COMPILER_OOPMAP_HPP

mercurial