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