1 /*
   2  * Copyright (c) 1997, 2011, 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_OPTO_COMPILE_HPP
  26 #define SHARE_VM_OPTO_COMPILE_HPP
  27 
  28 #include "asm/codeBuffer.hpp"
  29 #include "ci/compilerInterface.hpp"
  30 #include "code/debugInfoRec.hpp"
  31 #include "code/exceptionHandlerTable.hpp"
  32 #include "compiler/compilerOracle.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "libadt/dict.hpp"
  35 #include "libadt/port.hpp"
  36 #include "libadt/vectset.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "opto/idealGraphPrinter.hpp"
  39 #include "opto/phasetype.hpp"
  40 #include "opto/phase.hpp"
  41 #include "opto/regmask.hpp"
  42 #include "runtime/deoptimization.hpp"
  43 #include "runtime/vmThread.hpp"
  44 #include "trace/tracing.hpp"
  45 
  46 class Block;
  47 class Bundle;
  48 class C2Compiler;
  49 class CallGenerator;
  50 class ConnectionGraph;
  51 class InlineTree;
  52 class Int_Array;
  53 class Matcher;
  54 class MachConstantNode;
  55 class MachConstantBaseNode;
  56 class MachNode;
  57 class MachOper;
  58 class MachSafePointNode;
  59 class Node;
  60 class Node_Array;
  61 class Node_Notes;
  62 class OptoReg;
  63 class PhaseCFG;
  64 class PhaseGVN;
  65 class PhaseIterGVN;
  66 class PhaseRegAlloc;
  67 class PhaseCCP;
  68 class PhaseCCP_DCE;
  69 class RootNode;
  70 class relocInfo;
  71 class Scope;
  72 class StartNode;
  73 class SafePointNode;
  74 class JVMState;
  75 class TypeData;
  76 class TypePtr;
  77 class TypeOopPtr;
  78 class TypeFunc;
  79 class Unique_Node_List;
  80 class nmethod;
  81 class WarmCallInfo;
  82 class Node_Stack;
  83 struct Final_Reshape_Counts;
  84 
  85 //------------------------------Compile----------------------------------------
  86 // This class defines a top-level Compiler invocation.
  87 
  88 class Compile : public Phase {
  89   friend class VMStructs;
  90 
  91  public:
  92   // Fixed alias indexes.  (See also MergeMemNode.)
  93   enum {
  94     AliasIdxTop = 1,  // pseudo-index, aliases to nothing (used as sentinel value)
  95     AliasIdxBot = 2,  // pseudo-index, aliases to everything
  96     AliasIdxRaw = 3   // hard-wired index for TypeRawPtr::BOTTOM
  97   };
  98 
  99   // Variant of TraceTime(NULL, &_t_accumulator, TimeCompiler);
 100   // Integrated with logging.  If logging is turned on, and dolog is true,
 101   // then brackets are put into the log, with time stamps and node counts.
 102   // (The time collection itself is always conditionalized on TimeCompiler.)
 103   class TracePhase : public TraceTime {
 104    private:
 105     Compile*    C;
 106     CompileLog* _log;
 107     const char* _phase_name;
 108     bool _dolog;
 109    public:
 110     TracePhase(const char* name, elapsedTimer* accumulator, bool dolog);
 111     ~TracePhase();
 112   };
 113 
 114   // Information per category of alias (memory slice)
 115   class AliasType {
 116    private:
 117     friend class Compile;
 118 
 119     int             _index;         // unique index, used with MergeMemNode
 120     const TypePtr*  _adr_type;      // normalized address type
 121     ciField*        _field;         // relevant instance field, or null if none
 122     bool            _is_rewritable; // false if the memory is write-once only
 123     int             _general_index; // if this is type is an instance, the general
 124                                     // type that this is an instance of
 125 
 126     void Init(int i, const TypePtr* at);
 127 
 128    public:
 129     int             index()         const { return _index; }
 130     const TypePtr*  adr_type()      const { return _adr_type; }
 131     ciField*        field()         const { return _field; }
 132     bool            is_rewritable() const { return _is_rewritable; }
 133     bool            is_volatile()   const { return (_field ? _field->is_volatile() : false); }
 134     int             general_index() const { return (_general_index != 0) ? _general_index : _index; }
 135 
 136     void set_rewritable(bool z) { _is_rewritable = z; }
 137     void set_field(ciField* f) {
 138       assert(!_field,"");
 139       _field = f;
 140       if (f->is_final())  _is_rewritable = false;
 141     }
 142 
 143     void print_on(outputStream* st) PRODUCT_RETURN;
 144   };
 145 
 146   enum {
 147     logAliasCacheSize = 6,
 148     AliasCacheSize = (1<<logAliasCacheSize)
 149   };
 150   struct AliasCacheEntry { const TypePtr* _adr_type; int _index; };  // simple duple type
 151   enum {
 152     trapHistLength = methodDataOopDesc::_trap_hist_limit
 153   };
 154 
 155   // Constant entry of the constant table.
 156   class Constant {
 157   private:
 158     BasicType _type;
 159     jvalue    _value;
 160     int       _offset;         // offset of this constant (in bytes) relative to the constant table base.
 161     float     _freq;
 162     bool      _can_be_reused;  // true (default) if the value can be shared with other users.
 163 
 164   public:
 165     Constant() : _type(T_ILLEGAL), _offset(-1), _freq(0.0f), _can_be_reused(true) { _value.l = 0; }
 166     Constant(BasicType type, jvalue value, float freq = 0.0f, bool can_be_reused = true) :
 167       _type(type),
 168       _value(value),
 169       _offset(-1),
 170       _freq(freq),
 171       _can_be_reused(can_be_reused)
 172     {}
 173 
 174     bool operator==(const Constant& other);
 175 
 176     BasicType type()      const    { return _type; }
 177 
 178     jlong   get_jlong()   const    { return _value.j; }
 179     jfloat  get_jfloat()  const    { return _value.f; }
 180     jdouble get_jdouble() const    { return _value.d; }
 181     jobject get_jobject() const    { return _value.l; }
 182 
 183     int         offset()  const    { return _offset; }
 184     void    set_offset(int offset) {        _offset = offset; }
 185 
 186     float       freq()    const    { return _freq;         }
 187     void    inc_freq(float freq)   {        _freq += freq; }
 188 
 189     bool    can_be_reused() const  { return _can_be_reused; }
 190   };
 191 
 192   // Constant table.
 193   class ConstantTable {
 194   private:
 195     GrowableArray<Constant> _constants;          // Constants of this table.
 196     int                     _size;               // Size in bytes the emitted constant table takes (including padding).
 197     int                     _table_base_offset;  // Offset of the table base that gets added to the constant offsets.
 198     int                     _nof_jump_tables;    // Number of jump-tables in this constant table.
 199 
 200     static int qsort_comparator(Constant* a, Constant* b);
 201 
 202     // We use negative frequencies to keep the order of the
 203     // jump-tables in which they were added.  Otherwise we get into
 204     // trouble with relocation.
 205     float next_jump_table_freq() { return -1.0f * (++_nof_jump_tables); }
 206 
 207   public:
 208     ConstantTable() :
 209       _size(-1),
 210       _table_base_offset(-1),  // We can use -1 here since the constant table is always bigger than 2 bytes (-(size / 2), see MachConstantBaseNode::emit).
 211       _nof_jump_tables(0)
 212     {}
 213 
 214     int size() const { assert(_size != -1, "not calculated yet"); return _size; }
 215 
 216     int calculate_table_base_offset() const;  // AD specific
 217     void set_table_base_offset(int x)  { assert(_table_base_offset == -1 || x == _table_base_offset, "can't change"); _table_base_offset = x; }
 218     int      table_base_offset() const { assert(_table_base_offset != -1, "not set yet");                      return _table_base_offset; }
 219 
 220     void emit(CodeBuffer& cb);
 221 
 222     // Returns the offset of the last entry (the top) of the constant table.
 223     int  top_offset() const { assert(_constants.top().offset() != -1, "not bound yet"); return _constants.top().offset(); }
 224 
 225     void calculate_offsets_and_size();
 226     int  find_offset(Constant& con) const;
 227 
 228     void     add(Constant& con);
 229     Constant add(MachConstantNode* n, BasicType type, jvalue value);
 230     Constant add(MachConstantNode* n, MachOper* oper);
 231     Constant add(MachConstantNode* n, jfloat f) {
 232       jvalue value; value.f = f;
 233       return add(n, T_FLOAT, value);
 234     }
 235     Constant add(MachConstantNode* n, jdouble d) {
 236       jvalue value; value.d = d;
 237       return add(n, T_DOUBLE, value);
 238     }
 239 
 240     // Jump-table
 241     Constant  add_jump_table(MachConstantNode* n);
 242     void     fill_jump_table(CodeBuffer& cb, MachConstantNode* n, GrowableArray<Label*> labels) const;
 243   };
 244 
 245  private:
 246   // Fixed parameters to this compilation.
 247   const int             _compile_id;
 248   const bool            _save_argument_registers; // save/restore arg regs for trampolines
 249   const bool            _subsume_loads;         // Load can be matched as part of a larger op.
 250   const bool            _do_escape_analysis;    // Do escape analysis.
 251   ciMethod*             _method;                // The method being compiled.
 252   int                   _entry_bci;             // entry bci for osr methods.
 253   const TypeFunc*       _tf;                    // My kind of signature
 254   InlineTree*           _ilt;                   // Ditto (temporary).
 255   address               _stub_function;         // VM entry for stub being compiled, or NULL
 256   const char*           _stub_name;             // Name of stub or adapter being compiled, or NULL
 257   address               _stub_entry_point;      // Compile code entry for generated stub, or NULL
 258 
 259   // Control of this compilation.
 260   int                   _num_loop_opts;         // Number of iterations for doing loop optimiztions
 261   int                   _max_inline_size;       // Max inline size for this compilation
 262   int                   _freq_inline_size;      // Max hot method inline size for this compilation
 263   int                   _fixed_slots;           // count of frame slots not allocated by the register
 264                                                 // allocator i.e. locks, original deopt pc, etc.
 265   // For deopt
 266   int                   _orig_pc_slot;
 267   int                   _orig_pc_slot_offset_in_bytes;
 268 
 269   int                   _major_progress;        // Count of something big happening
 270   bool                  _inlining_progress;     // progress doing incremental inlining?
 271   bool                  _inlining_incrementally;// Are we doing incremental inlining (post parse)
 272   bool                  _has_loops;             // True if the method _may_ have some loops
 273   bool                  _has_split_ifs;         // True if the method _may_ have some split-if
 274   bool                  _has_unsafe_access;     // True if the method _may_ produce faults in unsafe loads or stores.
 275   bool                  _has_stringbuilder;     // True StringBuffers or StringBuilders are allocated
 276   int                   _max_vector_size;       // Maximum size of generated vectors
 277   uint                  _trap_hist[trapHistLength];  // Cumulative traps
 278   bool                  _trap_can_recompile;    // Have we emitted a recompiling trap?
 279   uint                  _decompile_count;       // Cumulative decompilation counts.
 280   bool                  _do_inlining;           // True if we intend to do inlining
 281   bool                  _do_scheduling;         // True if we intend to do scheduling
 282   bool                  _do_freq_based_layout;  // True if we intend to do frequency based block layout
 283   bool                  _do_count_invocations;  // True if we generate code to count invocations
 284   bool                  _do_method_data_update; // True if we generate code to update methodDataOops
 285   int                   _AliasLevel;            // Locally-adjusted version of AliasLevel flag.
 286   bool                  _print_assembly;        // True if we should dump assembly code for this compilation
 287 #ifndef PRODUCT
 288   bool                  _trace_opto_output;
 289   bool                  _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
 290 #endif
 291 
 292   // JSR 292
 293   bool                  _has_method_handle_invokes; // True if this method has MethodHandle invokes.
 294 
 295   // Compilation environment.
 296   Arena                 _comp_arena;            // Arena with lifetime equivalent to Compile
 297   ciEnv*                _env;                   // CI interface
 298   CompileLog*           _log;                   // from CompilerThread
 299   const char*           _failure_reason;        // for record_failure/failing pattern
 300   GrowableArray<CallGenerator*>* _intrinsics;   // List of intrinsics.
 301   GrowableArray<Node*>* _macro_nodes;           // List of nodes which need to be expanded before matching.
 302   GrowableArray<Node*>* _predicate_opaqs;       // List of Opaque1 nodes for the loop predicates.
 303   ConnectionGraph*      _congraph;
 304 #ifndef PRODUCT
 305   IdealGraphPrinter*    _printer;
 306 #endif
 307 
 308 
 309   // Node management
 310   uint                  _unique;                // Counter for unique Node indices
 311   VectorSet             _dead_node_list;        // Set of dead nodes
 312   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
 313                                                 // So use this to keep count and make the call O(1).
 314   debug_only(static int _debug_idx;)            // Monotonic counter (not reset), use -XX:BreakAtNode=<idx>
 315   Arena                 _node_arena;            // Arena for new-space Nodes
 316   Arena                 _old_arena;             // Arena for old-space Nodes, lifetime during xform
 317   RootNode*             _root;                  // Unique root of compilation, or NULL after bail-out.
 318   Node*                 _top;                   // Unique top node.  (Reset by various phases.)
 319 
 320   Node*                 _immutable_memory;      // Initial memory state
 321 
 322   Node*                 _recent_alloc_obj;
 323   Node*                 _recent_alloc_ctl;
 324 
 325   // Constant table
 326   ConstantTable         _constant_table;        // The constant table for this compile.
 327   MachConstantBaseNode* _mach_constant_base_node;  // Constant table base node singleton.
 328 
 329 
 330   // Blocked array of debugging and profiling information,
 331   // tracked per node.
 332   enum { _log2_node_notes_block_size = 8,
 333          _node_notes_block_size = (1<<_log2_node_notes_block_size)
 334   };
 335   GrowableArray<Node_Notes*>* _node_note_array;
 336   Node_Notes*           _default_node_notes;  // default notes for new nodes
 337 
 338   // After parsing and every bulk phase we hang onto the Root instruction.
 339   // The RootNode instruction is where the whole program begins.  It produces
 340   // the initial Control and BOTTOM for everybody else.
 341 
 342   // Type management
 343   Arena                 _Compile_types;         // Arena for all types
 344   Arena*                _type_arena;            // Alias for _Compile_types except in Initialize_shared()
 345   Dict*                 _type_dict;             // Intern table
 346   void*                 _type_hwm;              // Last allocation (see Type::operator new/delete)
 347   size_t                _type_last_size;        // Last allocation size (see Type::operator new/delete)
 348   ciMethod*             _last_tf_m;             // Cache for
 349   const TypeFunc*       _last_tf;               //  TypeFunc::make
 350   AliasType**           _alias_types;           // List of alias types seen so far.
 351   int                   _num_alias_types;       // Logical length of _alias_types
 352   int                   _max_alias_types;       // Physical length of _alias_types
 353   AliasCacheEntry       _alias_cache[AliasCacheSize]; // Gets aliases w/o data structure walking
 354 
 355   // Parsing, optimization
 356   PhaseGVN*             _initial_gvn;           // Results of parse-time PhaseGVN
 357   Unique_Node_List*     _for_igvn;              // Initial work-list for next round of Iterative GVN
 358   WarmCallInfo*         _warm_calls;            // Sorted work-list for heat-based inlining.
 359 
 360   GrowableArray<CallGenerator*> _late_inlines;        // List of CallGenerators to be revisited after
 361                                                       // main parsing has finished.
 362   GrowableArray<CallGenerator*> _string_late_inlines; // same but for string operations
 363 
 364   int                           _late_inlines_pos;    // Where in the queue should the next late inlining candidate go (emulate depth first inlining)
 365   uint                          _number_of_mh_late_inlines; // number of method handle late inlining still pending
 366 
 367 
 368   // Inlining may not happen in parse order which would make
 369   // PrintInlining output confusing. Keep track of PrintInlining
 370   // pieces in order.
 371   class PrintInliningBuffer : public ResourceObj {
 372    private:
 373     CallGenerator* _cg;
 374     stringStream* _ss;
 375 
 376    public:
 377     PrintInliningBuffer()
 378       : _cg(NULL) { _ss = new stringStream(); }
 379 
 380     stringStream* ss() const { return _ss; }
 381     CallGenerator* cg() const { return _cg; }
 382     void set_cg(CallGenerator* cg) { _cg = cg; }
 383   };
 384 
 385   GrowableArray<PrintInliningBuffer>* _print_inlining_list;
 386   int _print_inlining;
 387 
 388  public:
 389 
 390   outputStream* print_inlining_stream() const {
 391     return _print_inlining_list->at(_print_inlining).ss();
 392   }
 393 
 394   void print_inlining_skip(CallGenerator* cg) {
 395     if (PrintInlining) {
 396       _print_inlining_list->at(_print_inlining).set_cg(cg);
 397       _print_inlining++;
 398       _print_inlining_list->insert_before(_print_inlining, PrintInliningBuffer());
 399     }
 400   }
 401 
 402   void print_inlining_insert(CallGenerator* cg) {
 403     if (PrintInlining) {
 404       for (int i = 0; i < _print_inlining_list->length(); i++) {
 405         if (_print_inlining_list->at(i).cg() == cg) {
 406           _print_inlining_list->insert_before(i+1, PrintInliningBuffer());
 407           _print_inlining = i+1;
 408           _print_inlining_list->at(i).set_cg(NULL);
 409           return;
 410         }
 411       }
 412       ShouldNotReachHere();
 413     }
 414   }
 415 
 416   void print_inlining(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
 417     stringStream ss;
 418     CompileTask::print_inlining(&ss, method, inline_level, bci, msg);
 419     print_inlining_stream()->print(ss.as_string());
 420   }
 421 
 422  private:
 423   // Matching, CFG layout, allocation, code generation
 424   PhaseCFG*             _cfg;                   // Results of CFG finding
 425   bool                  _select_24_bit_instr;   // We selected an instruction with a 24-bit result
 426   bool                  _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
 427   int                   _java_calls;            // Number of java calls in the method
 428   int                   _inner_loops;           // Number of inner loops in the method
 429   Matcher*              _matcher;               // Engine to map ideal to machine instructions
 430   PhaseRegAlloc*        _regalloc;              // Results of register allocation.
 431   int                   _frame_slots;           // Size of total frame in stack slots
 432   CodeOffsets           _code_offsets;          // Offsets into the code for various interesting entries
 433   RegMask               _FIRST_STACK_mask;      // All stack slots usable for spills (depends on frame layout)
 434   Arena*                _indexSet_arena;        // control IndexSet allocation within PhaseChaitin
 435   void*                 _indexSet_free_block_list; // free list of IndexSet bit blocks
 436 
 437   uint                  _node_bundling_limit;
 438   Bundle*               _node_bundling_base;    // Information for instruction bundling
 439 
 440   // Instruction bits passed off to the VM
 441   int                   _method_size;           // Size of nmethod code segment in bytes
 442   CodeBuffer            _code_buffer;           // Where the code is assembled
 443   int                   _first_block_size;      // Size of unvalidated entry point code / OSR poison code
 444   ExceptionHandlerTable _handler_table;         // Table of native-code exception handlers
 445   ImplicitExceptionTable _inc_table;            // Table of implicit null checks in native code
 446   OopMapSet*            _oop_map_set;           // Table of oop maps (one for each safepoint location)
 447   static int            _CompiledZap_count;     // counter compared against CompileZap[First/Last]
 448   BufferBlob*           _scratch_buffer_blob;   // For temporary code buffers.
 449   relocInfo*            _scratch_locs_memory;   // For temporary code buffers.
 450   int                   _scratch_const_size;    // For temporary code buffers.
 451   bool                  _in_scratch_emit_size;  // true when in scratch_emit_size.
 452 
 453  public:
 454   // Accessors
 455 
 456   // The Compile instance currently active in this (compiler) thread.
 457   static Compile* current() {
 458     return (Compile*) ciEnv::current()->compiler_data();
 459   }
 460 
 461   // ID for this compilation.  Useful for setting breakpoints in the debugger.
 462   int               compile_id() const          { return _compile_id; }
 463 
 464   // Does this compilation allow instructions to subsume loads?  User
 465   // instructions that subsume a load may result in an unschedulable
 466   // instruction sequence.
 467   bool              subsume_loads() const       { return _subsume_loads; }
 468   // Do escape analysis.
 469   bool              do_escape_analysis() const  { return _do_escape_analysis; }
 470   bool              save_argument_registers() const { return _save_argument_registers; }
 471 
 472 
 473   // Other fixed compilation parameters.
 474   ciMethod*         method() const              { return _method; }
 475   int               entry_bci() const           { return _entry_bci; }
 476   bool              is_osr_compilation() const  { return _entry_bci != InvocationEntryBci; }
 477   bool              is_method_compilation() const { return (_method != NULL && !_method->flags().is_native()); }
 478   const TypeFunc*   tf() const                  { assert(_tf!=NULL, ""); return _tf; }
 479   void         init_tf(const TypeFunc* tf)      { assert(_tf==NULL, ""); _tf = tf; }
 480   InlineTree*       ilt() const                 { return _ilt; }
 481   address           stub_function() const       { return _stub_function; }
 482   const char*       stub_name() const           { return _stub_name; }
 483   address           stub_entry_point() const    { return _stub_entry_point; }
 484 
 485   // Control of this compilation.
 486   int               fixed_slots() const         { assert(_fixed_slots >= 0, "");         return _fixed_slots; }
 487   void          set_fixed_slots(int n)          { _fixed_slots = n; }
 488   int               major_progress() const      { return _major_progress; }
 489   void          set_inlining_progress(bool z)   { _inlining_progress = z; }
 490   int               inlining_progress() const   { return _inlining_progress; }
 491   void          set_inlining_incrementally(bool z) { _inlining_incrementally = z; }
 492   int               inlining_incrementally() const { return _inlining_incrementally; }
 493   void          set_major_progress()            { _major_progress++; }
 494   void        clear_major_progress()            { _major_progress = 0; }
 495   int               num_loop_opts() const       { return _num_loop_opts; }
 496   void          set_num_loop_opts(int n)        { _num_loop_opts = n; }
 497   int               max_inline_size() const     { return _max_inline_size; }
 498   void          set_freq_inline_size(int n)     { _freq_inline_size = n; }
 499   int               freq_inline_size() const    { return _freq_inline_size; }
 500   void          set_max_inline_size(int n)      { _max_inline_size = n; }
 501   bool              has_loops() const           { return _has_loops; }
 502   void          set_has_loops(bool z)           { _has_loops = z; }
 503   bool              has_split_ifs() const       { return _has_split_ifs; }
 504   void          set_has_split_ifs(bool z)       { _has_split_ifs = z; }
 505   bool              has_unsafe_access() const   { return _has_unsafe_access; }
 506   void          set_has_unsafe_access(bool z)   { _has_unsafe_access = z; }
 507   bool              has_stringbuilder() const   { return _has_stringbuilder; }
 508   void          set_has_stringbuilder(bool z)   { _has_stringbuilder = z; }
 509   int               max_vector_size() const     { return _max_vector_size; }
 510   void          set_max_vector_size(int s)      { _max_vector_size = s; }
 511   void          set_trap_count(uint r, uint c)  { assert(r < trapHistLength, "oob");        _trap_hist[r] = c; }
 512   uint              trap_count(uint r) const    { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
 513   bool              trap_can_recompile() const  { return _trap_can_recompile; }
 514   void          set_trap_can_recompile(bool z)  { _trap_can_recompile = z; }
 515   uint              decompile_count() const     { return _decompile_count; }
 516   void          set_decompile_count(uint c)     { _decompile_count = c; }
 517   bool              allow_range_check_smearing() const;
 518   bool              do_inlining() const         { return _do_inlining; }
 519   void          set_do_inlining(bool z)         { _do_inlining = z; }
 520   bool              do_scheduling() const       { return _do_scheduling; }
 521   void          set_do_scheduling(bool z)       { _do_scheduling = z; }
 522   bool              do_freq_based_layout() const{ return _do_freq_based_layout; }
 523   void          set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
 524   bool              do_count_invocations() const{ return _do_count_invocations; }
 525   void          set_do_count_invocations(bool z){ _do_count_invocations = z; }
 526   bool              do_method_data_update() const { return _do_method_data_update; }
 527   void          set_do_method_data_update(bool z) { _do_method_data_update = z; }
 528   int               AliasLevel() const          { return _AliasLevel; }
 529   bool              print_assembly() const       { return _print_assembly; }
 530   void          set_print_assembly(bool z)       { _print_assembly = z; }
 531   // check the CompilerOracle for special behaviours for this compile
 532   bool          method_has_option(const char * option) {
 533     return method() != NULL && method()->has_option(option);
 534   }
 535 #ifndef PRODUCT
 536   bool          trace_opto_output() const       { return _trace_opto_output; }
 537   bool              parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
 538   void          set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
 539 #endif
 540 
 541   // JSR 292
 542   bool              has_method_handle_invokes() const { return _has_method_handle_invokes;     }
 543   void          set_has_method_handle_invokes(bool z) {        _has_method_handle_invokes = z; }
 544 
 545   long _latest_stage_start_counter;
 546 
 547   void begin_method() {
 548 #ifndef PRODUCT
 549     if (_printer) _printer->begin_method(this);
 550 #endif
 551     C->_latest_stage_start_counter = os::elapsed_counter();
 552   }
 553 
 554   void print_method(CompilerPhaseType cpt, int level = 1) {
 555     EventCompilerPhase event(UNTIMED);
 556     if (event.should_commit()) {
 557       event.set_starttime(C->_latest_stage_start_counter);
 558       event.set_endtime(os::elapsed_counter());
 559       event.set_phase((u1) cpt);
 560       event.set_compileID(C->_compile_id);
 561       event.set_phaseLevel(level);
 562       event.commit();
 563     }
 564 
 565 
 566 #ifndef PRODUCT
 567     if (_printer) _printer->print_method(this, CompilerPhaseTypeHelper::to_string(cpt), level);
 568 #endif
 569     C->_latest_stage_start_counter = os::elapsed_counter();
 570   }
 571 
 572   void end_method(int level = 1) {
 573     EventCompilerPhase event(UNTIMED);
 574     if (event.should_commit()) {
 575       event.set_starttime(C->_latest_stage_start_counter);
 576       event.set_endtime(os::elapsed_counter());
 577       event.set_phase((u1) PHASE_END);
 578       event.set_compileID(C->_compile_id);
 579       event.set_phaseLevel(level);
 580       event.commit();
 581     }
 582 #ifndef PRODUCT
 583     if (_printer) _printer->end_method();
 584 #endif
 585   }
 586 
 587   int           macro_count()                   { return _macro_nodes->length(); }
 588   int           predicate_count()               { return _predicate_opaqs->length();}
 589   Node*         macro_node(int idx)             { return _macro_nodes->at(idx); }
 590   Node*         predicate_opaque1_node(int idx) { return _predicate_opaqs->at(idx);}
 591   ConnectionGraph* congraph()                   { return _congraph;}
 592   void set_congraph(ConnectionGraph* congraph)  { _congraph = congraph;}
 593   void add_macro_node(Node * n) {
 594     //assert(n->is_macro(), "must be a macro node");
 595     assert(!_macro_nodes->contains(n), " duplicate entry in expand list");
 596     _macro_nodes->append(n);
 597   }
 598   void remove_macro_node(Node * n) {
 599     // this function may be called twice for a node so check
 600     // that the node is in the array before attempting to remove it
 601     if (_macro_nodes->contains(n))
 602       _macro_nodes->remove(n);
 603     // remove from _predicate_opaqs list also if it is there
 604     if (predicate_count() > 0 && _predicate_opaqs->contains(n)){
 605       _predicate_opaqs->remove(n);
 606     }
 607   }
 608   void add_predicate_opaq(Node * n) {
 609     assert(!_predicate_opaqs->contains(n), " duplicate entry in predicate opaque1");
 610     assert(_macro_nodes->contains(n), "should have already been in macro list");
 611     _predicate_opaqs->append(n);
 612   }
 613   // remove the opaque nodes that protect the predicates so that the unused checks and
 614   // uncommon traps will be eliminated from the graph.
 615   void cleanup_loop_predicates(PhaseIterGVN &igvn);
 616   bool is_predicate_opaq(Node * n) {
 617     return _predicate_opaqs->contains(n);
 618   }
 619 
 620   // Compilation environment.
 621   Arena*            comp_arena()                { return &_comp_arena; }
 622   ciEnv*            env() const                 { return _env; }
 623   CompileLog*       log() const                 { return _log; }
 624   bool              failing() const             { return _env->failing() || _failure_reason != NULL; }
 625   const char*       failure_reason() { return _failure_reason; }
 626   bool              failure_reason_is(const char* r) { return (r==_failure_reason) || (r!=NULL && _failure_reason!=NULL && strcmp(r, _failure_reason)==0); }
 627 
 628   void record_failure(const char* reason);
 629   void record_method_not_compilable(const char* reason, bool all_tiers = false) {
 630     // All bailouts cover "all_tiers" when TieredCompilation is off.
 631     if (!TieredCompilation) all_tiers = true;
 632     env()->record_method_not_compilable(reason, all_tiers);
 633     // Record failure reason.
 634     record_failure(reason);
 635   }
 636   void record_method_not_compilable_all_tiers(const char* reason) {
 637     record_method_not_compilable(reason, true);
 638   }
 639   bool check_node_count(uint margin, const char* reason) {
 640     if (live_nodes() + margin > (uint)MaxNodeLimit) {
 641       record_method_not_compilable(reason);
 642       return true;
 643     } else {
 644       return false;
 645     }
 646   }
 647 
 648   // Node management
 649   uint         unique() const              { return _unique; }
 650   uint         next_unique()               { return _unique++; }
 651   void         set_unique(uint i)          { _unique = i; }
 652   static int   debug_idx()                 { return debug_only(_debug_idx)+0; }
 653   static void  set_debug_idx(int i)        { debug_only(_debug_idx = i); }
 654   Arena*       node_arena()                { return &_node_arena; }
 655   Arena*       old_arena()                 { return &_old_arena; }
 656   RootNode*    root() const                { return _root; }
 657   void         set_root(RootNode* r)       { _root = r; }
 658   StartNode*   start() const;              // (Derived from root.)
 659   void         init_start(StartNode* s);
 660   Node*        immutable_memory();
 661 
 662   Node*        recent_alloc_ctl() const    { return _recent_alloc_ctl; }
 663   Node*        recent_alloc_obj() const    { return _recent_alloc_obj; }
 664   void         set_recent_alloc(Node* ctl, Node* obj) {
 665                                                   _recent_alloc_ctl = ctl;
 666                                                   _recent_alloc_obj = obj;
 667                                            }
 668   void         record_dead_node(uint idx)  { if (_dead_node_list.test_set(idx)) return;
 669                                              _dead_node_count++;
 670                                            }
 671   uint         dead_node_count()           { return _dead_node_count; }
 672   void         reset_dead_node_list()      { _dead_node_list.Reset();
 673                                              _dead_node_count = 0;
 674                                            }
 675   uint          live_nodes() const         {
 676     int  val = _unique - _dead_node_count;
 677     assert (val >= 0, err_msg_res("number of tracked dead nodes %d more than created nodes %d", _unique, _dead_node_count));
 678             return (uint) val;
 679                                            }
 680 #ifdef ASSERT
 681   uint         count_live_nodes_by_graph_walk();
 682   void         print_missing_nodes();
 683 #endif
 684 
 685   // Constant table
 686   ConstantTable&   constant_table() { return _constant_table; }
 687 
 688   MachConstantBaseNode*     mach_constant_base_node();
 689   bool                  has_mach_constant_base_node() const { return _mach_constant_base_node != NULL; }
 690 
 691   // Handy undefined Node
 692   Node*             top() const                 { return _top; }
 693 
 694   // these are used by guys who need to know about creation and transformation of top:
 695   Node*             cached_top_node()           { return _top; }
 696   void          set_cached_top_node(Node* tn);
 697 
 698   GrowableArray<Node_Notes*>* node_note_array() const { return _node_note_array; }
 699   void set_node_note_array(GrowableArray<Node_Notes*>* arr) { _node_note_array = arr; }
 700   Node_Notes* default_node_notes() const        { return _default_node_notes; }
 701   void    set_default_node_notes(Node_Notes* n) { _default_node_notes = n; }
 702 
 703   Node_Notes*       node_notes_at(int idx) {
 704     return locate_node_notes(_node_note_array, idx, false);
 705   }
 706   inline bool   set_node_notes_at(int idx, Node_Notes* value);
 707 
 708   // Copy notes from source to dest, if they exist.
 709   // Overwrite dest only if source provides something.
 710   // Return true if information was moved.
 711   bool copy_node_notes_to(Node* dest, Node* source);
 712 
 713   // Workhorse function to sort out the blocked Node_Notes array:
 714   inline Node_Notes* locate_node_notes(GrowableArray<Node_Notes*>* arr,
 715                                        int idx, bool can_grow = false);
 716 
 717   void grow_node_notes(GrowableArray<Node_Notes*>* arr, int grow_by);
 718 
 719   // Type management
 720   Arena*            type_arena()                { return _type_arena; }
 721   Dict*             type_dict()                 { return _type_dict; }
 722   void*             type_hwm()                  { return _type_hwm; }
 723   size_t            type_last_size()            { return _type_last_size; }
 724   int               num_alias_types()           { return _num_alias_types; }
 725 
 726   void          init_type_arena()                       { _type_arena = &_Compile_types; }
 727   void          set_type_arena(Arena* a)                { _type_arena = a; }
 728   void          set_type_dict(Dict* d)                  { _type_dict = d; }
 729   void          set_type_hwm(void* p)                   { _type_hwm = p; }
 730   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
 731 
 732   const TypeFunc* last_tf(ciMethod* m) {
 733     return (m == _last_tf_m) ? _last_tf : NULL;
 734   }
 735   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
 736     assert(m != NULL || tf == NULL, "");
 737     _last_tf_m = m;
 738     _last_tf = tf;
 739   }
 740 
 741   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
 742   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = NULL) { return find_alias_type(adr_type, false, field); }
 743   bool         have_alias_type(const TypePtr* adr_type);
 744   AliasType*        alias_type(ciField*         field);
 745 
 746   int               get_alias_index(const TypePtr* at)  { return alias_type(at)->index(); }
 747   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
 748   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
 749 
 750   // Building nodes
 751   void              rethrow_exceptions(JVMState* jvms);
 752   void              return_values(JVMState* jvms);
 753   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
 754 
 755   // Decide how to build a call.
 756   // The profile factor is a discount to apply to this site's interp. profile.
 757   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch, JVMState* jvms, bool allow_inline, float profile_factor, bool allow_intrinsics = true, bool delayed_forbidden = false);
 758   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms);
 759 
 760   // Helper functions to identify inlining potential at call-site
 761   ciMethod* optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
 762                                   ciMethod* callee, const TypeOopPtr* receiver_type,
 763                                   bool is_virtual,
 764                                   bool &call_does_dispatch, int &vtable_index);
 765   ciMethod* optimize_inlining(ciMethod* caller, int bci, ciInstanceKlass* klass,
 766                               ciMethod* callee, const TypeOopPtr* receiver_type);
 767 
 768   // Report if there were too many traps at a current method and bci.
 769   // Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.
 770   // If there is no MDO at all, report no trap unless told to assume it.
 771   bool too_many_traps(ciMethod* method, int bci, Deoptimization::DeoptReason reason);
 772   // This version, unspecific to a particular bci, asks if
 773   // PerMethodTrapLimit was exceeded for all inlined methods seen so far.
 774   bool too_many_traps(Deoptimization::DeoptReason reason,
 775                       // Privately used parameter for logging:
 776                       ciMethodData* logmd = NULL);
 777   // Report if there were too many recompiles at a method and bci.
 778   bool too_many_recompiles(ciMethod* method, int bci, Deoptimization::DeoptReason reason);
 779 
 780   // Parsing, optimization
 781   PhaseGVN*         initial_gvn()               { return _initial_gvn; }
 782   Unique_Node_List* for_igvn()                  { return _for_igvn; }
 783   inline void       record_for_igvn(Node* n);   // Body is after class Unique_Node_List.
 784   void          set_initial_gvn(PhaseGVN *gvn)           { _initial_gvn = gvn; }
 785   void          set_for_igvn(Unique_Node_List *for_igvn) { _for_igvn = for_igvn; }
 786 
 787   // Replace n by nn using initial_gvn, calling hash_delete and
 788   // record_for_igvn as needed.
 789   void gvn_replace_by(Node* n, Node* nn);
 790 
 791 
 792   void              identify_useful_nodes(Unique_Node_List &useful);
 793   void              update_dead_node_list(Unique_Node_List &useful);
 794   void              remove_useless_nodes (Unique_Node_List &useful);
 795 
 796   WarmCallInfo*     warm_calls() const          { return _warm_calls; }
 797   void          set_warm_calls(WarmCallInfo* l) { _warm_calls = l; }
 798   WarmCallInfo* pop_warm_call();
 799 
 800   // Record this CallGenerator for inlining at the end of parsing.
 801   void              add_late_inline(CallGenerator* cg)        {
 802     _late_inlines.insert_before(_late_inlines_pos, cg);
 803     _late_inlines_pos++;
 804   }
 805 
 806   void              prepend_late_inline(CallGenerator* cg)    {
 807     _late_inlines.insert_before(0, cg);
 808   }
 809 
 810   void              add_string_late_inline(CallGenerator* cg) {
 811     _string_late_inlines.push(cg);
 812   }
 813 
 814   void remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Unique_Node_List &useful);
 815 
 816   void dump_inlining();
 817 
 818   bool over_inlining_cutoff() const {
 819     if (!inlining_incrementally()) {
 820       return unique() > (uint)NodeCountInliningCutoff;
 821     } else {
 822       return live_nodes() > (uint)LiveNodeCountInliningCutoff;
 823     }
 824   }
 825 
 826   void inc_number_of_mh_late_inlines() { _number_of_mh_late_inlines++; }
 827   void dec_number_of_mh_late_inlines() { assert(_number_of_mh_late_inlines > 0, "_number_of_mh_late_inlines < 0 !"); _number_of_mh_late_inlines--; }
 828   bool has_mh_late_inlines() const     { return _number_of_mh_late_inlines > 0; }
 829 
 830   void inline_incrementally_one(PhaseIterGVN& igvn);
 831   void inline_incrementally(PhaseIterGVN& igvn);
 832   void inline_string_calls(bool parse_time);
 833 
 834   // Matching, CFG layout, allocation, code generation
 835   PhaseCFG*         cfg()                       { return _cfg; }
 836   bool              select_24_bit_instr() const { return _select_24_bit_instr; }
 837   bool              in_24_bit_fp_mode() const   { return _in_24_bit_fp_mode; }
 838   bool              has_java_calls() const      { return _java_calls > 0; }
 839   int               java_calls() const          { return _java_calls; }
 840   int               inner_loops() const         { return _inner_loops; }
 841   Matcher*          matcher()                   { return _matcher; }
 842   PhaseRegAlloc*    regalloc()                  { return _regalloc; }
 843   int               frame_slots() const         { return _frame_slots; }
 844   int               frame_size_in_words() const; // frame_slots in units of the polymorphic 'words'
 845   RegMask&          FIRST_STACK_mask()          { return _FIRST_STACK_mask; }
 846   Arena*            indexSet_arena()            { return _indexSet_arena; }
 847   void*             indexSet_free_block_list()  { return _indexSet_free_block_list; }
 848   uint              node_bundling_limit()       { return _node_bundling_limit; }
 849   Bundle*           node_bundling_base()        { return _node_bundling_base; }
 850   void          set_node_bundling_limit(uint n) { _node_bundling_limit = n; }
 851   void          set_node_bundling_base(Bundle* b) { _node_bundling_base = b; }
 852   bool          starts_bundle(const Node *n) const;
 853   bool          need_stack_bang(int frame_size_in_bytes) const;
 854   bool          need_register_stack_bang() const;
 855 
 856   void          set_matcher(Matcher* m)                 { _matcher = m; }
 857 //void          set_regalloc(PhaseRegAlloc* ra)           { _regalloc = ra; }
 858   void          set_indexSet_arena(Arena* a)            { _indexSet_arena = a; }
 859   void          set_indexSet_free_block_list(void* p)   { _indexSet_free_block_list = p; }
 860 
 861   // Remember if this compilation changes hardware mode to 24-bit precision
 862   void set_24_bit_selection_and_mode(bool selection, bool mode) {
 863     _select_24_bit_instr = selection;
 864     _in_24_bit_fp_mode   = mode;
 865   }
 866 
 867   void  set_java_calls(int z) { _java_calls  = z; }
 868   void set_inner_loops(int z) { _inner_loops = z; }
 869 
 870   // Instruction bits passed off to the VM
 871   int               code_size()                 { return _method_size; }
 872   CodeBuffer*       code_buffer()               { return &_code_buffer; }
 873   int               first_block_size()          { return _first_block_size; }
 874   void              set_frame_complete(int off) { _code_offsets.set_value(CodeOffsets::Frame_Complete, off); }
 875   ExceptionHandlerTable*  handler_table()       { return &_handler_table; }
 876   ImplicitExceptionTable* inc_table()           { return &_inc_table; }
 877   OopMapSet*        oop_map_set()               { return _oop_map_set; }
 878   DebugInformationRecorder* debug_info()        { return env()->debug_info(); }
 879   Dependencies*     dependencies()              { return env()->dependencies(); }
 880   static int        CompiledZap_count()         { return _CompiledZap_count; }
 881   BufferBlob*       scratch_buffer_blob()       { return _scratch_buffer_blob; }
 882   void         init_scratch_buffer_blob(int const_size);
 883   void        clear_scratch_buffer_blob();
 884   void          set_scratch_buffer_blob(BufferBlob* b) { _scratch_buffer_blob = b; }
 885   relocInfo*        scratch_locs_memory()       { return _scratch_locs_memory; }
 886   void          set_scratch_locs_memory(relocInfo* b)  { _scratch_locs_memory = b; }
 887 
 888   // emit to scratch blob, report resulting size
 889   uint              scratch_emit_size(const Node* n);
 890   void       set_in_scratch_emit_size(bool x)   {        _in_scratch_emit_size = x; }
 891   bool           in_scratch_emit_size() const   { return _in_scratch_emit_size;     }
 892 
 893   enum ScratchBufferBlob {
 894     MAX_inst_size       = 1024,
 895     MAX_locs_size       = 128, // number of relocInfo elements
 896     MAX_const_size      = 128,
 897     MAX_stubs_size      = 128
 898   };
 899 
 900   // Major entry point.  Given a Scope, compile the associated method.
 901   // For normal compilations, entry_bci is InvocationEntryBci.  For on stack
 902   // replacement, entry_bci indicates the bytecode for which to compile a
 903   // continuation.
 904   Compile(ciEnv* ci_env, C2Compiler* compiler, ciMethod* target,
 905           int entry_bci, bool subsume_loads, bool do_escape_analysis);
 906 
 907   // Second major entry point.  From the TypeFunc signature, generate code
 908   // to pass arguments from the Java calling convention to the C calling
 909   // convention.
 910   Compile(ciEnv* ci_env, const TypeFunc *(*gen)(),
 911           address stub_function, const char *stub_name,
 912           int is_fancy_jump, bool pass_tls,
 913           bool save_arg_registers, bool return_pc);
 914 
 915   // From the TypeFunc signature, generate code to pass arguments
 916   // from Compiled calling convention to Interpreter's calling convention
 917   void Generate_Compiled_To_Interpreter_Graph(const TypeFunc *tf, address interpreter_entry);
 918 
 919   // From the TypeFunc signature, generate code to pass arguments
 920   // from Interpreter's calling convention to Compiler's calling convention
 921   void Generate_Interpreter_To_Compiled_Graph(const TypeFunc *tf);
 922 
 923   // Are we compiling a method?
 924   bool has_method() { return method() != NULL; }
 925 
 926   // Maybe print some information about this compile.
 927   void print_compile_messages();
 928 
 929   // Final graph reshaping, a post-pass after the regular optimizer is done.
 930   bool final_graph_reshaping();
 931 
 932   // returns true if adr is completely contained in the given alias category
 933   bool must_alias(const TypePtr* adr, int alias_idx);
 934 
 935   // returns true if adr overlaps with the given alias category
 936   bool can_alias(const TypePtr* adr, int alias_idx);
 937 
 938   // Driver for converting compiler's IR into machine code bits
 939   void Output();
 940 
 941   // Accessors for node bundling info.
 942   Bundle* node_bundling(const Node *n);
 943   bool valid_bundle_info(const Node *n);
 944 
 945   // Schedule and Bundle the instructions
 946   void ScheduleAndBundle();
 947 
 948   // Build OopMaps for each GC point
 949   void BuildOopMaps();
 950 
 951   // Append debug info for the node "local" at safepoint node "sfpt" to the
 952   // "array",   May also consult and add to "objs", which describes the
 953   // scalar-replaced objects.
 954   void FillLocArray( int idx, MachSafePointNode* sfpt,
 955                      Node *local, GrowableArray<ScopeValue*> *array,
 956                      GrowableArray<ScopeValue*> *objs );
 957 
 958   // If "objs" contains an ObjectValue whose id is "id", returns it, else NULL.
 959   static ObjectValue* sv_for_node_id(GrowableArray<ScopeValue*> *objs, int id);
 960   // Requres that "objs" does not contains an ObjectValue whose id matches
 961   // that of "sv.  Appends "sv".
 962   static void set_sv_for_object_node(GrowableArray<ScopeValue*> *objs,
 963                                      ObjectValue* sv );
 964 
 965   // Process an OopMap Element while emitting nodes
 966   void Process_OopMap_Node(MachNode *mach, int code_offset);
 967 
 968   // Initialize code buffer
 969   CodeBuffer* init_buffer(uint* blk_starts);
 970 
 971   // Write out basic block data to code buffer
 972   void fill_buffer(CodeBuffer* cb, uint* blk_starts);
 973 
 974   // Determine which variable sized branches can be shortened
 975   void shorten_branches(uint* blk_starts, int& code_size, int& reloc_size, int& stub_size);
 976 
 977   // Compute the size of first NumberOfLoopInstrToAlign instructions
 978   // at the head of a loop.
 979   void compute_loop_first_inst_sizes();
 980 
 981   // Compute the information for the exception tables
 982   void FillExceptionTables(uint cnt, uint *call_returns, uint *inct_starts, Label *blk_labels);
 983 
 984   // Stack slots that may be unused by the calling convention but must
 985   // otherwise be preserved.  On Intel this includes the return address.
 986   // On PowerPC it includes the 4 words holding the old TOC & LR glue.
 987   uint in_preserve_stack_slots();
 988 
 989   // "Top of Stack" slots that may be unused by the calling convention but must
 990   // otherwise be preserved.
 991   // On Intel these are not necessary and the value can be zero.
 992   // On Sparc this describes the words reserved for storing a register window
 993   // when an interrupt occurs.
 994   static uint out_preserve_stack_slots();
 995 
 996   // Number of outgoing stack slots killed above the out_preserve_stack_slots
 997   // for calls to C.  Supports the var-args backing area for register parms.
 998   uint varargs_C_out_slots_killed() const;
 999 
1000   // Number of Stack Slots consumed by a synchronization entry
1001   int sync_stack_slots() const;
1002 
1003   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1004   OptoReg::Name compute_old_SP();
1005 
1006 #ifdef ENABLE_ZAP_DEAD_LOCALS
1007   static bool is_node_getting_a_safepoint(Node*);
1008   void Insert_zap_nodes();
1009   Node* call_zap_node(MachSafePointNode* n, int block_no);
1010 #endif
1011 
1012  private:
1013   // Phase control:
1014   void Init(int aliaslevel);                     // Prepare for a single compilation
1015   int  Inline_Warm();                            // Find more inlining work.
1016   void Finish_Warm();                            // Give up on further inlines.
1017   void Optimize();                               // Given a graph, optimize it
1018   void Code_Gen();                               // Generate code from a graph
1019 
1020   // Management of the AliasType table.
1021   void grow_alias_types();
1022   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1023   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1024   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1025 
1026   void verify_top(Node*) const PRODUCT_RETURN;
1027 
1028   // Intrinsic setup.
1029   void           register_library_intrinsics();                            // initializer
1030   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1031   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual);  // helper
1032   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1033   void           register_intrinsic(CallGenerator* cg);                    // update fn
1034 
1035 #ifndef PRODUCT
1036   static juint  _intrinsic_hist_count[vmIntrinsics::ID_LIMIT];
1037   static jubyte _intrinsic_hist_flags[vmIntrinsics::ID_LIMIT];
1038 #endif
1039   // Function calls made by the public function final_graph_reshaping.
1040   // No need to be made public as they are not called elsewhere.
1041   void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc);
1042   void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc );
1043   void eliminate_redundant_card_marks(Node* n);
1044 
1045  public:
1046 
1047   // Note:  Histogram array size is about 1 Kb.
1048   enum {                        // flag bits:
1049     _intrinsic_worked = 1,      // succeeded at least once
1050     _intrinsic_failed = 2,      // tried it but it failed
1051     _intrinsic_disabled = 4,    // was requested but disabled (e.g., -XX:-InlineUnsafeOps)
1052     _intrinsic_virtual = 8,     // was seen in the virtual form (rare)
1053     _intrinsic_both = 16        // was seen in the non-virtual form (usual)
1054   };
1055   // Update histogram.  Return boolean if this is a first-time occurrence.
1056   static bool gather_intrinsic_statistics(vmIntrinsics::ID id,
1057                                           bool is_virtual, int flags) PRODUCT_RETURN0;
1058   static void print_intrinsic_statistics() PRODUCT_RETURN;
1059 
1060   // Graph verification code
1061   // Walk the node list, verifying that there is a one-to-one
1062   // correspondence between Use-Def edges and Def-Use edges
1063   // The option no_dead_code enables stronger checks that the
1064   // graph is strongly connected from root in both directions.
1065   void verify_graph_edges(bool no_dead_code = false) PRODUCT_RETURN;
1066 
1067   // Print bytecodes, including the scope inlining tree
1068   void print_codes();
1069 
1070   // End-of-run dumps.
1071   static void print_statistics() PRODUCT_RETURN;
1072 
1073   // Dump formatted assembly
1074   void dump_asm(int *pcs = NULL, uint pc_limit = 0) PRODUCT_RETURN;
1075   void dump_pc(int *pcs, int pc_limit, Node *n);
1076 
1077   // Verify ADLC assumptions during startup
1078   static void adlc_verification() PRODUCT_RETURN;
1079 
1080   // Definitions of pd methods
1081   static void pd_compiler2_init();
1082 };
1083 
1084 #endif // SHARE_VM_OPTO_COMPILE_HPP