1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. 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 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_VM_OOPS_GENERATEOOPMAP_HPP
  26 #define SHARE_VM_OOPS_GENERATEOOPMAP_HPP
  27 
  28 #include "interpreter/bytecodeStream.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/universe.inline.hpp"
  31 #include "oops/method.hpp"
  32 #include "oops/oopsHierarchy.hpp"
  33 #include "runtime/signature.hpp"
  34 
  35 // Forward definition
  36 class GenerateOopMap;
  37 class BasicBlock;
  38 class CellTypeState;
  39 class StackMap;
  40 
  41 // These two should be removed. But requires som code to be cleaned up
  42 #define MAXARGSIZE      256      // This should be enough
  43 #define MAX_LOCAL_VARS  65536    // 16-bit entry
  44 
  45 typedef void (*jmpFct_t)(GenerateOopMap *c, int bcpDelta, int* data);
  46 
  47 
  48 //  RetTable
  49 //
  50 // Contains maping between jsr targets and there return addresses. One-to-many mapping
  51 //
  52 class RetTableEntry : public ResourceObj {
  53  private:
  54   static int _init_nof_jsrs;                      // Default size of jsrs list
  55   int _target_bci;                                // Target PC address of jump (bytecode index)
  56   GrowableArray<intptr_t> * _jsrs;                     // List of return addresses  (bytecode index)
  57   RetTableEntry *_next;                           // Link to next entry
  58  public:
  59    RetTableEntry(int target, RetTableEntry *next)  { _target_bci=target; _jsrs = new GrowableArray<intptr_t>(_init_nof_jsrs); _next = next;  }
  60 
  61   // Query
  62   int target_bci() const                      { return _target_bci; }
  63   int nof_jsrs() const                        { return _jsrs->length(); }
  64   int jsrs(int i) const                       { assert(i>=0 && i<nof_jsrs(), "Index out of bounds"); return _jsrs->at(i); }
  65 
  66   // Update entry
  67   void add_jsr    (int return_bci)            { _jsrs->append(return_bci); }
  68   void add_delta  (int bci, int delta);
  69   RetTableEntry * next()  const               { return _next; }
  70 };
  71 
  72 
  73 class RetTable VALUE_OBJ_CLASS_SPEC {
  74  private:
  75   RetTableEntry *_first;
  76   static int _init_nof_entries;
  77 
  78   void add_jsr(int return_bci, int target_bci);   // Adds entry to list
  79  public:
  80   RetTable()                                                  { _first = NULL; }
  81   void compute_ret_table(const methodHandle& method);
  82   void update_ret_table(int bci, int delta);
  83   RetTableEntry* find_jsrs_for_target(int targBci);
  84 };
  85 
  86 //
  87 // CellTypeState
  88 //
  89 class CellTypeState VALUE_OBJ_CLASS_SPEC {
  90  private:
  91   unsigned int _state;
  92 
  93   // Masks for separating the BITS and INFO portions of a CellTypeState
  94   enum { info_mask            = right_n_bits(27),
  95          bits_mask            = (int)(~info_mask) };
  96 
  97   // These constant are used for manipulating the BITS portion of a
  98   // CellTypeState
  99   enum { uninit_bit           = (int)(nth_bit(31)),
 100          ref_bit              = nth_bit(30),
 101          val_bit              = nth_bit(29),
 102          addr_bit             = nth_bit(28),
 103          valuetype_bit        = nth_bit(27),
 104          live_bits_mask       = (int)(bits_mask & ~uninit_bit) };
 105 
 106   // These constants are used for manipulating the INFO portion of a
 107   // CellTypeState
 108   enum { top_info_bit         = nth_bit(26),
 109          not_bottom_info_bit  = nth_bit(25),
 110          info_data_mask       = right_n_bits(25),
 111          info_conflict        = info_mask };
 112 
 113   // Within the INFO data, these values are used to distinguish different
 114   // kinds of references.
 115   enum { ref_not_lock_bit     = nth_bit(24),  // 0 if this reference is locked as a monitor
 116          ref_slot_bit         = nth_bit(23),  // 1 if this reference is a "slot" reference,
 117                                               // 0 if it is a "line" reference.
 118          ref_data_mask        = right_n_bits(23) };
 119 
 120   // Within the INFO data, these values are used to distinguish different
 121   // kinds of value types.
 122   enum { valuetype_slot_bit   = nth_bit(24),  // 1 if this reference is a "slot" value type,
 123                                               // 0 if it is a "line" value type.
 124          valuetype_data_mask  = right_n_bits(24) };
 125 
 126   // These values are used to initialize commonly used CellTypeState
 127   // constants.
 128   enum { bottom_value         = 0,
 129          uninit_value         = (int)(uninit_bit | info_conflict),
 130          ref_value            = ref_bit,
 131          ref_conflict         = ref_bit | info_conflict,
 132          val_value            = val_bit | info_conflict,
 133          valuetype_conflict   = valuetype_bit | info_conflict,
 134          addr_value           = addr_bit,
 135          addr_conflict        = addr_bit | info_conflict };
 136 
 137  public:
 138 
 139   // Since some C++ constructors generate poor code for declarations of the
 140   // form...
 141   //
 142   //   CellTypeState vector[length];
 143   //
 144   // ...we avoid making a constructor for this class.  CellTypeState values
 145   // should be constructed using one of the make_* methods:
 146 
 147   static CellTypeState make_any(int state) {
 148     CellTypeState s;
 149     s._state = state;
 150     // Causes SS10 warning.
 151     // assert(s.is_valid_state(), "check to see if CellTypeState is valid");
 152     return s;
 153   }
 154 
 155   static CellTypeState make_bottom() {
 156     return make_any(0);
 157   }
 158 
 159   static CellTypeState make_top() {
 160     return make_any(AllBits);
 161   }
 162 
 163   static CellTypeState make_addr(int bci) {
 164     assert((bci >= 0) && (bci < info_data_mask), "check to see if ret addr is valid");
 165     return make_any(addr_bit | not_bottom_info_bit | (bci & info_data_mask));
 166   }
 167 
 168   static CellTypeState make_slot_ref(int slot_num) {
 169     assert(slot_num >= 0 && slot_num < ref_data_mask, "slot out of range");
 170     return make_any(ref_bit | not_bottom_info_bit | ref_not_lock_bit | ref_slot_bit |
 171                     (slot_num & ref_data_mask));
 172   }
 173 
 174   static CellTypeState make_line_ref(int bci) {
 175     assert(bci >= 0 && bci < ref_data_mask, "line out of range");
 176     return make_any(ref_bit | not_bottom_info_bit | ref_not_lock_bit |
 177                     (bci & ref_data_mask));
 178   }
 179 
 180   static CellTypeState make_lock_ref(int bci) {
 181     assert(bci >= 0 && bci < ref_data_mask, "line out of range");
 182     return make_any(ref_bit | not_bottom_info_bit | (bci & ref_data_mask));
 183   }
 184 
 185   static CellTypeState make_slot_valuetype(int slot_num) {
 186     assert(slot_num >= 0 && slot_num < valuetype_data_mask, "slot out of range");
 187     return make_any(valuetype_bit | not_bottom_info_bit | valuetype_slot_bit |
 188                         (slot_num & valuetype_data_mask));
 189   }
 190 
 191   static CellTypeState make_line_valuetype(int bci) {
 192       assert(bci >= 0 && bci < valuetype_data_mask, "line out of range");
 193       return make_any(valuetype_bit | not_bottom_info_bit |
 194                       (bci & valuetype_data_mask));
 195   }
 196 
 197   // Query methods:
 198   bool is_bottom() const                { return _state == 0; }
 199   bool is_live() const                  { return ((_state & live_bits_mask) != 0); }
 200   bool is_valid_state() const {
 201     // Uninitialized and value cells must contain no data in their info field:
 202     if ((can_be_uninit() || can_be_value()) && !is_info_top()) {
 203       return false;
 204     }
 205     // The top bit is only set when all info bits are set:
 206     if (is_info_top() && ((_state & info_mask) != info_mask)) {
 207       return false;
 208     }
 209     // The not_bottom_bit must be set when any other info bit is set:
 210     if (is_info_bottom() && ((_state & info_mask) != 0)) {
 211       return false;
 212     }
 213     return true;
 214   }
 215 
 216   bool is_address() const               { return ((_state & bits_mask) == addr_bit); }
 217   bool is_reference() const             { return ((_state & bits_mask) == ref_bit); }
 218   bool is_value() const                 { return ((_state & bits_mask) == val_bit); }
 219   bool is_valuetype() const             { return ((_state & bits_mask) == valuetype_bit); }
 220   bool is_uninit() const                { return ((_state & bits_mask) == (uint)uninit_bit); }
 221 
 222   bool can_be_address() const           { return ((_state & addr_bit) != 0); }
 223   bool can_be_reference() const         { return ((_state & ref_bit) != 0); }
 224   bool can_be_value() const             { return ((_state & val_bit) != 0); }
 225   bool can_be_valuetype() const         { return ((_state & valuetype_bit) != 0); }
 226   bool can_be_uninit() const            { return ((_state & uninit_bit) != 0); }
 227 
 228   bool is_info_bottom() const           { return ((_state & not_bottom_info_bit) == 0); }
 229   bool is_info_top() const              { return ((_state & top_info_bit) != 0); }
 230   int  get_info() const {
 231     assert((!is_info_top() && !is_info_bottom()),
 232            "check to make sure top/bottom info is not used");
 233     return (_state & info_data_mask);
 234   }
 235 
 236   bool is_good_address() const          { return is_address() && !is_info_top(); }
 237   bool is_lock_reference() const {
 238     return ((_state & (bits_mask | top_info_bit | ref_not_lock_bit)) == ref_bit);
 239   }
 240   bool is_nonlock_reference() const {
 241     return ((_state & (bits_mask | top_info_bit | ref_not_lock_bit)) == (ref_bit | ref_not_lock_bit));
 242   }
 243 
 244   bool equal(CellTypeState a) const     { return _state == a._state; }
 245   bool equal_kind(CellTypeState a) const {
 246     return (_state & bits_mask) == (a._state & bits_mask);
 247   }
 248 
 249   char to_char() const;
 250 
 251   // Merge
 252   CellTypeState merge (CellTypeState cts, int slot) const;
 253 
 254   // Debugging output
 255   void print(outputStream *os);
 256 
 257   // Default values of common values
 258   static CellTypeState bottom;
 259   static CellTypeState uninit;
 260   static CellTypeState ref;
 261   static CellTypeState value;
 262   static CellTypeState valuetype;
 263   static CellTypeState refUninit;
 264   static CellTypeState varUninit;
 265   static CellTypeState top;
 266   static CellTypeState addr;
 267 };
 268 
 269 
 270 //
 271 // BasicBlockStruct
 272 //
 273 class BasicBlock: ResourceObj {
 274  private:
 275   bool            _changed;                 // Reached a fixpoint or not
 276  public:
 277   enum Constants {
 278     _dead_basic_block = -2,
 279     _unreached        = -1                  // Alive but not yet reached by analysis
 280     // >=0                                  // Alive and has a merged state
 281   };
 282 
 283   int             _bci;                     // Start of basic block
 284   int             _end_bci;                 // Bci of last instruction in basicblock
 285   int             _max_locals;              // Determines split between vars and stack
 286   int             _max_stack;               // Determines split between stack and monitors
 287   CellTypeState*  _state;                   // State (vars, stack) at entry.
 288   int             _stack_top;               // -1 indicates bottom stack value.
 289   int             _monitor_top;             // -1 indicates bottom monitor stack value.
 290 
 291   CellTypeState* vars()                     { return _state; }
 292   CellTypeState* stack()                    { return _state + _max_locals; }
 293 
 294   bool changed()                            { return _changed; }
 295   void set_changed(bool s)                  { _changed = s; }
 296 
 297   bool is_reachable() const                 { return _stack_top >= 0; }  // Analysis has reached this basicblock
 298 
 299   // All basicblocks that are unreachable are going to have a _stack_top == _dead_basic_block.
 300   // This info. is setup in a pre-parse before the real abstract interpretation starts.
 301   bool is_dead() const                      { return _stack_top == _dead_basic_block; }
 302   bool is_alive() const                     { return _stack_top != _dead_basic_block; }
 303   void mark_as_alive()                      { assert(is_dead(), "must be dead"); _stack_top = _unreached; }
 304 };
 305 
 306 
 307 //
 308 //  GenerateOopMap
 309 //
 310 // Main class used to compute the pointer-maps in a Method
 311 //
 312 class GenerateOopMap VALUE_OBJ_CLASS_SPEC {
 313  protected:
 314 
 315   // _monitor_top is set to this constant to indicate that a monitor matching
 316   // problem was encountered prior to this point in control flow.
 317   enum { bad_monitors = -1 };
 318 
 319   // Main variables
 320   methodHandle _method;                     // The method we are examine
 321   RetTable     _rt;                         // Contains the return address mappings
 322   int          _max_locals;                 // Cached value of no. of locals
 323   int          _max_stack;                  // Cached value of max. stack depth
 324   int          _max_monitors;               // Cached value of max. monitor stack depth
 325   int          _has_exceptions;             // True, if exceptions exist for method
 326   bool         _got_error;                  // True, if an error occurred during interpretation.
 327   Handle       _exception;                  // Exception if got_error is true.
 328   bool         _did_rewriting;              // was bytecodes rewritten
 329   bool         _did_relocation;             // was relocation neccessary
 330   bool         _monitor_safe;               // The monitors in this method have been determined
 331                                             // to be safe.
 332 
 333   // Working Cell type state
 334   int            _state_len;                // Size of states
 335   CellTypeState *_state;                    // list of states
 336   char          *_state_vec_buf;            // Buffer used to print a readable version of a state
 337   int            _stack_top;
 338   int            _monitor_top;
 339 
 340   // Timing and statistics
 341   static elapsedTimer _total_oopmap_time;   // Holds cumulative oopmap generation time
 342   static long         _total_byte_count;    // Holds cumulative number of bytes inspected
 343 
 344   // Cell type methods
 345   void            init_state();
 346   void            make_context_uninitialized ();
 347   int             methodsig_to_effect        (Symbol* signature, bool isStatic, CellTypeState* effect);
 348   bool            merge_local_state_vectors  (CellTypeState* cts, CellTypeState* bbts);
 349   bool            merge_monitor_state_vectors(CellTypeState* cts, CellTypeState* bbts);
 350   void            copy_state                 (CellTypeState *dst, CellTypeState *src);
 351   void            merge_state_into_bb        (BasicBlock *bb);
 352   static void     merge_state                (GenerateOopMap *gom, int bcidelta, int* data);
 353   void            set_var                    (int localNo, CellTypeState cts);
 354   CellTypeState   get_var                    (int localNo);
 355   CellTypeState   pop                        ();
 356   void            push                       (CellTypeState cts);
 357   CellTypeState   monitor_pop                ();
 358   void            monitor_push               (CellTypeState cts);
 359   CellTypeState * vars                       ()                                             { return _state; }
 360   CellTypeState * stack                      ()                                             { return _state+_max_locals; }
 361   CellTypeState * monitors                   ()                                             { return _state+_max_locals+_max_stack; }
 362 
 363   void            replace_all_CTS_matches    (CellTypeState match,
 364                                               CellTypeState replace);
 365   void            print_states               (outputStream *os, CellTypeState *vector, int num);
 366   void            print_current_state        (outputStream   *os,
 367                                               BytecodeStream *itr,
 368                                               bool            detailed);
 369   void            report_monitor_mismatch    (const char *msg);
 370 
 371   // Basicblock info
 372   BasicBlock *    _basic_blocks;             // Array of basicblock info
 373   int             _gc_points;
 374   int             _bb_count;
 375   BitMap          _bb_hdr_bits;
 376 
 377   // Basicblocks methods
 378   void          initialize_bb               ();
 379   void          mark_bbheaders_and_count_gc_points();
 380   bool          is_bb_header                (int bci) const   {
 381     return _bb_hdr_bits.at(bci);
 382   }
 383   int           gc_points                   () const                          { return _gc_points; }
 384   int           bb_count                    () const                          { return _bb_count; }
 385   void          set_bbmark_bit              (int bci) {
 386     _bb_hdr_bits.at_put(bci, true);
 387   }
 388   void          clear_bbmark_bit            (int bci) {
 389     _bb_hdr_bits.at_put(bci, false);
 390   }
 391   BasicBlock *  get_basic_block_at          (int bci) const;
 392   BasicBlock *  get_basic_block_containing  (int bci) const;
 393   void          interp_bb                   (BasicBlock *bb);
 394   void          restore_state               (BasicBlock *bb);
 395   int           next_bb_start_pc            (BasicBlock *bb);
 396   void          update_basic_blocks         (int bci, int delta, int new_method_size);
 397   static void   bb_mark_fct                 (GenerateOopMap *c, int deltaBci, int *data);
 398 
 399   // Dead code detection
 400   void          mark_reachable_code();
 401   static void   reachable_basicblock        (GenerateOopMap *c, int deltaBci, int *data);
 402 
 403   // Interpretation methods (primary)
 404   void  do_interpretation                   ();
 405   void  init_basic_blocks                   ();
 406   void  setup_method_entry_state            ();
 407   void  interp_all                          ();
 408 
 409   // Interpretation methods (secondary)
 410   void  interp1                             (BytecodeStream *itr);
 411   void  do_exception_edge                   (BytecodeStream *itr);
 412   void  check_type                          (CellTypeState expected, CellTypeState actual);
 413   void  ppstore                             (CellTypeState *in,  int loc_no);
 414   void  ppload                              (CellTypeState *out, int loc_no);
 415   void  ppush1                              (CellTypeState in);
 416   void  ppush                               (CellTypeState *in);
 417   void  ppop1                               (CellTypeState out);
 418   void  ppop                                (CellTypeState *out);
 419   void  ppop_any                            (int poplen);
 420   void  pp                                  (CellTypeState *in, CellTypeState *out);
 421   void  pp_new_ref                          (CellTypeState *in, int bci);
 422   void  pp_new_valuetype                    (CellTypeState *in, int bci);
 423   void  ppdupswap                           (int poplen, const char *out);
 424   void  do_ldc                              (int bci);
 425   void  do_astore                           (int idx);
 426   void  do_vstore                           (int idx);
 427   void  do_jsr                              (int delta);
 428   void  do_field                            (int is_get, int is_static, int is_valuetype, int idx, int bci);
 429   void  do_method                           (int is_static, int is_value, int idx, int bci);
 430   void  do_vnew                             (int idx, int bci);
 431   void  do_vwithfield                       (int idx, int bci);
 432   void  do_multianewarray                   (int dims, int bci);
 433   void  do_monitorenter                     (int bci);
 434   void  do_monitorexit                      (int bci);
 435   void  do_return_monitor_check             ();
 436   void  do_checkcast                        ();
 437   CellTypeState *sigchar_to_effect          (char sigch, int bci, CellTypeState *out);
 438   int copy_cts                              (CellTypeState *dst, CellTypeState *src);
 439 
 440   // Error handling
 441   void  error_work                          (const char *format, va_list ap) ATTRIBUTE_PRINTF(2, 0);
 442   void  report_error                        (const char *format, ...) ATTRIBUTE_PRINTF(2, 3);
 443   void  verify_error                        (const char *format, ...) ATTRIBUTE_PRINTF(2, 3);
 444   bool  got_error()                         { return _got_error; }
 445 
 446   // Create result set
 447   bool  _report_result;
 448   bool  _report_result_for_send;            // Unfortunatly, stackmaps for sends are special, so we need some extra
 449   BytecodeStream *_itr_send;                // variables to handle them properly.
 450 
 451   void  report_result                       ();
 452 
 453   // Initvars
 454   GrowableArray<intptr_t> * _init_vars;
 455 
 456   void  initialize_vars                     ();
 457   void  add_to_ref_init_set                 (int localNo);
 458 
 459   // Conflicts rewrite logic
 460   bool      _conflict;                      // True, if a conflict occurred during interpretation
 461   int       _nof_refval_conflicts;          // No. of conflicts that require rewrites
 462   int *     _new_var_map;
 463 
 464   void record_refval_conflict               (int varNo);
 465   void rewrite_refval_conflicts             ();
 466   void rewrite_refval_conflict              (int from, int to);
 467   bool rewrite_refval_conflict_inst         (BytecodeStream *i, int from, int to);
 468   bool rewrite_load_or_store                (BytecodeStream *i, Bytecodes::Code bc, Bytecodes::Code bc0, unsigned int varNo);
 469 
 470   void expand_current_instr                 (int bci, int ilen, int newIlen, u_char inst_buffer[]);
 471   bool is_astore                            (BytecodeStream *itr, int *index);
 472   bool is_aload                             (BytecodeStream *itr, int *index);
 473 
 474   // List of bci's where a return address is on top of the stack
 475   GrowableArray<intptr_t> *_ret_adr_tos;
 476 
 477   bool stack_top_holds_ret_addr             (int bci);
 478   void compute_ret_adr_at_TOS               ();
 479   void update_ret_adr_at_TOS                (int bci, int delta);
 480 
 481   int  binsToHold                           (int no)                      { return  ((no+(BitsPerWord-1))/BitsPerWord); }
 482   char *state_vec_to_string                 (CellTypeState* vec, int len);
 483 
 484   // Helper method. Can be used in subclasses to fx. calculate gc_points. If the current instuction
 485   // is a control transfer, then calls the jmpFct all possible destinations.
 486   void  ret_jump_targets_do                 (BytecodeStream *bcs, jmpFct_t jmpFct, int varNo,int *data);
 487   bool  jump_targets_do                     (BytecodeStream *bcs, jmpFct_t jmpFct, int *data);
 488 
 489   friend class RelocCallback;
 490  public:
 491   GenerateOopMap(const methodHandle& method);
 492 
 493   // Compute the map.
 494   void compute_map(TRAPS);
 495   void result_for_basicblock(int bci);    // Do a callback on fill_stackmap_for_opcodes for basicblock containing bci
 496 
 497   // Query
 498   int max_locals() const                           { return _max_locals; }
 499   Method* method() const                           { return _method(); }
 500   methodHandle method_as_handle() const            { return _method; }
 501 
 502   bool did_rewriting()                             { return _did_rewriting; }
 503   bool did_relocation()                            { return _did_relocation; }
 504 
 505   static void print_time();
 506 
 507   // Monitor query
 508   bool monitor_safe()                              { return _monitor_safe; }
 509 
 510   // Specialization methods. Intended use:
 511   // - possible_gc_point must return true for every bci for which the stackmaps must be returned
 512   // - fill_stackmap_prolog is called just before the result is reported. The arguments tells the estimated
 513   //   number of gc points
 514   // - fill_stackmap_for_opcodes is called once for each bytecode index in order (0...code_length-1)
 515   // - fill_stackmap_epilog is called after all results has been reported. Note: Since the algorithm does not report
 516   //   stackmaps for deadcode, fewer gc_points might have been encounted than assumed during the epilog. It is the
 517   //   responsibility of the subclass to count the correct number.
 518   // - fill_init_vars are called once with the result of the init_vars computation
 519   //
 520   // All these methods are used during a call to: compute_map. Note: Non of the return results are valid
 521   // after compute_map returns, since all values are allocated as resource objects.
 522   //
 523   // All virtual method must be implemented in subclasses
 524   virtual bool allow_rewrites             () const                        { return false; }
 525   virtual bool report_results             () const                        { return true;  }
 526   virtual bool report_init_vars           () const                        { return true;  }
 527   virtual bool possible_gc_point          (BytecodeStream *bcs)           { ShouldNotReachHere(); return false; }
 528   virtual void fill_stackmap_prolog       (int nof_gc_points)             { ShouldNotReachHere(); }
 529   virtual void fill_stackmap_epilog       ()                              { ShouldNotReachHere(); }
 530   virtual void fill_stackmap_for_opcodes  (BytecodeStream *bcs,
 531                                            CellTypeState* vars,
 532                                            CellTypeState* stack,
 533                                            int stackTop)                  { ShouldNotReachHere(); }
 534   virtual void fill_init_vars             (GrowableArray<intptr_t> *init_vars) { ShouldNotReachHere();; }
 535 };
 536 
 537 //
 538 // Subclass of the GenerateOopMap Class that just do rewrites of the method, if needed.
 539 // It does not store any oopmaps.
 540 //
 541 class ResolveOopMapConflicts: public GenerateOopMap {
 542  private:
 543 
 544   bool _must_clear_locals;
 545 
 546   virtual bool report_results() const     { return false; }
 547   virtual bool report_init_vars() const   { return true;  }
 548   virtual bool allow_rewrites() const     { return true;  }
 549   virtual bool possible_gc_point          (BytecodeStream *bcs)           { return false; }
 550   virtual void fill_stackmap_prolog       (int nof_gc_points)             {}
 551   virtual void fill_stackmap_epilog       ()                              {}
 552   virtual void fill_stackmap_for_opcodes  (BytecodeStream *bcs,
 553                                            CellTypeState* vars,
 554                                            CellTypeState* stack,
 555                                            int stack_top)                 {}
 556   virtual void fill_init_vars             (GrowableArray<intptr_t> *init_vars) { _must_clear_locals = init_vars->length() > 0; }
 557 
 558 #ifndef PRODUCT
 559   // Statistics
 560   static int _nof_invocations;
 561   static int _nof_rewrites;
 562   static int _nof_relocations;
 563 #endif
 564 
 565  public:
 566   ResolveOopMapConflicts(const methodHandle& method) : GenerateOopMap(method) { _must_clear_locals = false; };
 567 
 568   methodHandle do_potential_rewrite(TRAPS);
 569   bool must_clear_locals() const { return _must_clear_locals; }
 570 };
 571 
 572 
 573 //
 574 // Subclass used by the compiler to generate pairing infomation
 575 //
 576 class GeneratePairingInfo: public GenerateOopMap {
 577  private:
 578 
 579   virtual bool report_results() const     { return false; }
 580   virtual bool report_init_vars() const   { return false; }
 581   virtual bool allow_rewrites() const     { return false;  }
 582   virtual bool possible_gc_point          (BytecodeStream *bcs)           { return false; }
 583   virtual void fill_stackmap_prolog       (int nof_gc_points)             {}
 584   virtual void fill_stackmap_epilog       ()                              {}
 585   virtual void fill_stackmap_for_opcodes  (BytecodeStream *bcs,
 586                                            CellTypeState* vars,
 587                                            CellTypeState* stack,
 588                                            int stack_top)                 {}
 589   virtual void fill_init_vars             (GrowableArray<intptr_t> *init_vars) {}
 590  public:
 591   GeneratePairingInfo(const methodHandle& method) : GenerateOopMap(method)       {};
 592 
 593   // Call compute_map(CHECK) to generate info.
 594 };
 595 
 596 #endif // SHARE_VM_OOPS_GENERATEOOPMAP_HPP