1 /*
2  * Copyright (c) 1997, 2020, 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_OPTO_COMPILE_HPP
26 #define SHARE_OPTO_COMPILE_HPP
27 
28 #include "asm/codeBuffer.hpp"
29 #include "ci/compilerInterface.hpp"
30 #include "code/debugInfoRec.hpp"
31 #include "compiler/compilerOracle.hpp"
32 #include "compiler/compileBroker.hpp"
33 #include "compiler/compilerEvent.hpp"
34 #include "libadt/dict.hpp"
35 #include "libadt/vectset.hpp"
36 #include "memory/resourceArea.hpp"
37 #include "oops/methodData.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/sharedRuntime.hpp"
44 #include "runtime/timerTrace.hpp"
45 #include "runtime/vmThread.hpp"
46 #include "utilities/ticks.hpp"
47 
48 class AddPNode;
49 class Block;
50 class Bundle;
51 class CallGenerator;
52 class CloneMap;
53 class ConnectionGraph;
54 class IdealGraphPrinter;
55 class InlineTree;
56 class Int_Array;
57 class Matcher;
58 class MachConstantNode;
59 class MachConstantBaseNode;
60 class MachNode;
61 class MachOper;
62 class MachSafePointNode;
63 class Node;
64 class Node_Array;
65 class Node_Notes;
66 class NodeCloneInfo;
67 class OptoReg;
68 class PhaseCFG;
69 class PhaseGVN;
70 class PhaseIterGVN;
71 class PhaseRegAlloc;
72 class PhaseCCP;
73 class PhaseOutput;
74 class RootNode;
75 class relocInfo;
76 class Scope;
77 class StartNode;
78 class SafePointNode;
79 class JVMState;
80 class Type;
81 class TypeData;
82 class TypeInt;
83 class TypeInteger;
84 class TypePtr;
85 class TypeOopPtr;
86 class TypeFunc;
87 class TypeVect;
88 class Unique_Node_List;
89 class nmethod;
90 class WarmCallInfo;
91 class Node_Stack;
92 struct Final_Reshape_Counts;
93 
94 enum LoopOptsMode {
95   LoopOptsDefault,
96   LoopOptsNone,
97   LoopOptsMaxUnroll,
98   LoopOptsShenandoahExpand,
99   LoopOptsShenandoahPostExpand,
100   LoopOptsSkipSplitIf,
101   LoopOptsVerify
102 };
103 
104 typedef unsigned int node_idx_t;
105 class NodeCloneInfo {
106  private:
107   uint64_t _idx_clone_orig;
108  public:
109 
set_idx(node_idx_t idx)110   void set_idx(node_idx_t idx) {
111     _idx_clone_orig = (_idx_clone_orig & CONST64(0xFFFFFFFF00000000)) | idx;
112   }
idx() const113   node_idx_t idx() const { return (node_idx_t)(_idx_clone_orig & 0xFFFFFFFF); }
114 
set_gen(int generation)115   void set_gen(int generation) {
116     uint64_t g = (uint64_t)generation << 32;
117     _idx_clone_orig = (_idx_clone_orig & 0xFFFFFFFF) | g;
118   }
gen() const119   int gen() const { return (int)(_idx_clone_orig >> 32); }
120 
set(uint64_t x)121   void set(uint64_t x) { _idx_clone_orig = x; }
set(node_idx_t x,int g)122   void set(node_idx_t x, int g) { set_idx(x); set_gen(g); }
get() const123   uint64_t get() const { return _idx_clone_orig; }
124 
NodeCloneInfo(uint64_t idx_clone_orig)125   NodeCloneInfo(uint64_t idx_clone_orig) : _idx_clone_orig(idx_clone_orig) {}
NodeCloneInfo(node_idx_t x,int g)126   NodeCloneInfo(node_idx_t x, int g) : _idx_clone_orig(0) { set(x, g); }
127 
128   void dump() const;
129 };
130 
131 class CloneMap {
132   friend class Compile;
133  private:
134   bool      _debug;
135   Dict*     _dict;
136   int       _clone_idx;   // current cloning iteration/generation in loop unroll
137  public:
_2p(node_idx_t key) const138   void*     _2p(node_idx_t key)   const          { return (void*)(intptr_t)key; } // 2 conversion functions to make gcc happy
_2_node_idx_t(const void * k) const139   node_idx_t _2_node_idx_t(const void* k) const  { return (node_idx_t)(intptr_t)k; }
dict() const140   Dict*     dict()                const          { return _dict; }
insert(node_idx_t key,uint64_t val)141   void insert(node_idx_t key, uint64_t val)      { assert(_dict->operator[](_2p(key)) == NULL, "key existed"); _dict->Insert(_2p(key), (void*)val); }
insert(node_idx_t key,NodeCloneInfo & ci)142   void insert(node_idx_t key, NodeCloneInfo& ci) { insert(key, ci.get()); }
remove(node_idx_t key)143   void remove(node_idx_t key)                    { _dict->Delete(_2p(key)); }
value(node_idx_t key) const144   uint64_t value(node_idx_t key)  const          { return (uint64_t)_dict->operator[](_2p(key)); }
idx(node_idx_t key) const145   node_idx_t idx(node_idx_t key)  const          { return NodeCloneInfo(value(key)).idx(); }
gen(node_idx_t key) const146   int gen(node_idx_t key)         const          { return NodeCloneInfo(value(key)).gen(); }
gen(const void * k) const147   int gen(const void* k)          const          { return gen(_2_node_idx_t(k)); }
148   int max_gen()                   const;
149   void clone(Node* old, Node* nnn, int gen);
150   void verify_insert_and_clone(Node* old, Node* nnn, int gen);
151   void dump(node_idx_t key)       const;
152 
clone_idx() const153   int  clone_idx() const                         { return _clone_idx; }
set_clone_idx(int x)154   void set_clone_idx(int x)                      { _clone_idx = x; }
is_debug() const155   bool is_debug()                 const          { return _debug; }
set_debug(bool debug)156   void set_debug(bool debug)                     { _debug = debug; }
157   static const char* debug_option_name;
158 
same_idx(node_idx_t k1,node_idx_t k2) const159   bool same_idx(node_idx_t k1, node_idx_t k2)  const { return idx(k1) == idx(k2); }
same_gen(node_idx_t k1,node_idx_t k2) const160   bool same_gen(node_idx_t k1, node_idx_t k2)  const { return gen(k1) == gen(k2); }
161 };
162 
163 //------------------------------Compile----------------------------------------
164 // This class defines a top-level Compiler invocation.
165 
166 class Compile : public Phase {
167   friend class VMStructs;
168 
169  public:
170   // Fixed alias indexes.  (See also MergeMemNode.)
171   enum {
172     AliasIdxTop = 1,  // pseudo-index, aliases to nothing (used as sentinel value)
173     AliasIdxBot = 2,  // pseudo-index, aliases to everything
174     AliasIdxRaw = 3   // hard-wired index for TypeRawPtr::BOTTOM
175   };
176 
177   // Variant of TraceTime(NULL, &_t_accumulator, CITime);
178   // Integrated with logging.  If logging is turned on, and CITimeVerbose is true,
179   // then brackets are put into the log, with time stamps and node counts.
180   // (The time collection itself is always conditionalized on CITime.)
181   class TracePhase : public TraceTime {
182    private:
183     Compile*    C;
184     CompileLog* _log;
185     const char* _phase_name;
186     bool _dolog;
187    public:
188     TracePhase(const char* name, elapsedTimer* accumulator);
189     ~TracePhase();
190   };
191 
192   // Information per category of alias (memory slice)
193   class AliasType {
194    private:
195     friend class Compile;
196 
197     int             _index;         // unique index, used with MergeMemNode
198     const TypePtr*  _adr_type;      // normalized address type
199     ciField*        _field;         // relevant instance field, or null if none
200     const Type*     _element;       // relevant array element type, or null if none
201     bool            _is_rewritable; // false if the memory is write-once only
202     int             _general_index; // if this is type is an instance, the general
203                                     // type that this is an instance of
204 
205     void Init(int i, const TypePtr* at);
206 
207    public:
index() const208     int             index()         const { return _index; }
adr_type() const209     const TypePtr*  adr_type()      const { return _adr_type; }
field() const210     ciField*        field()         const { return _field; }
element() const211     const Type*     element()       const { return _element; }
is_rewritable() const212     bool            is_rewritable() const { return _is_rewritable; }
is_volatile() const213     bool            is_volatile()   const { return (_field ? _field->is_volatile() : false); }
general_index() const214     int             general_index() const { return (_general_index != 0) ? _general_index : _index; }
215 
set_rewritable(bool z)216     void set_rewritable(bool z) { _is_rewritable = z; }
set_field(ciField * f)217     void set_field(ciField* f) {
218       assert(!_field,"");
219       _field = f;
220       if (f->is_final() || f->is_stable()) {
221         // In the case of @Stable, multiple writes are possible but may be assumed to be no-ops.
222         _is_rewritable = false;
223       }
224     }
set_element(const Type * e)225     void set_element(const Type* e) {
226       assert(_element == NULL, "");
227       _element = e;
228     }
229 
230     BasicType basic_type() const;
231 
232     void print_on(outputStream* st) PRODUCT_RETURN;
233   };
234 
235   enum {
236     logAliasCacheSize = 6,
237     AliasCacheSize = (1<<logAliasCacheSize)
238   };
239   struct AliasCacheEntry { const TypePtr* _adr_type; int _index; };  // simple duple type
240   enum {
241     trapHistLength = MethodData::_trap_hist_limit
242   };
243 
244  private:
245   // Fixed parameters to this compilation.
246   const int             _compile_id;
247   const bool            _save_argument_registers; // save/restore arg regs for trampolines
248   const bool            _subsume_loads;         // Load can be matched as part of a larger op.
249   const bool            _do_escape_analysis;    // Do escape analysis.
250   const bool            _install_code;          // Install the code that was compiled
251   const bool            _eliminate_boxing;      // Do boxing elimination.
252   ciMethod*             _method;                // The method being compiled.
253   int                   _entry_bci;             // entry bci for osr methods.
254   const TypeFunc*       _tf;                    // My kind of signature
255   InlineTree*           _ilt;                   // Ditto (temporary).
256   address               _stub_function;         // VM entry for stub being compiled, or NULL
257   const char*           _stub_name;             // Name of stub or adapter being compiled, or NULL
258   address               _stub_entry_point;      // Compile code entry for generated stub, or NULL
259 
260   // Control of this compilation.
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   uintx                 _max_node_limit;        // Max unique node count during a single compilation.
266 
267   bool                  _post_loop_opts_phase;  // Loop opts are finished.
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                  _do_cleanup;            // Cleanup is needed before proceeding with incremental inlining
273   bool                  _has_loops;             // True if the method _may_ have some loops
274   bool                  _has_split_ifs;         // True if the method _may_ have some split-if
275   bool                  _has_unsafe_access;     // True if the method _may_ produce faults in unsafe loads or stores.
276   bool                  _has_stringbuilder;     // True StringBuffers or StringBuilders are allocated
277   bool                  _has_boxed_value;       // True if a boxed object is allocated
278   bool                  _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
279   uint                  _max_vector_size;       // Maximum size of generated vectors
280   bool                  _clear_upper_avx;       // Clear upper bits of ymm registers using vzeroupper
281   uint                  _trap_hist[trapHistLength];  // Cumulative traps
282   bool                  _trap_can_recompile;    // Have we emitted a recompiling trap?
283   uint                  _decompile_count;       // Cumulative decompilation counts.
284   bool                  _do_inlining;           // True if we intend to do inlining
285   bool                  _do_scheduling;         // True if we intend to do scheduling
286   bool                  _do_freq_based_layout;  // True if we intend to do frequency based block layout
287   bool                  _do_vector_loop;        // True if allowed to execute loop in parallel iterations
288   bool                  _use_cmove;             // True if CMove should be used without profitability analysis
289   bool                  _age_code;              // True if we need to profile code age (decrement the aging counter)
290   int                   _AliasLevel;            // Locally-adjusted version of AliasLevel flag.
291   bool                  _print_assembly;        // True if we should dump assembly code for this compilation
292   bool                  _print_inlining;        // True if we should print inlining for this compilation
293   bool                  _print_intrinsics;      // True if we should print intrinsics for this compilation
294 #ifndef PRODUCT
295   bool                  _trace_opto_output;
296   bool                  _print_ideal;
297   bool                  _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
298 #endif
299   bool                  _has_irreducible_loop;  // Found irreducible loops
300   // JSR 292
301   bool                  _has_method_handle_invokes; // True if this method has MethodHandle invokes.
302   RTMState              _rtm_state;             // State of Restricted Transactional Memory usage
303   int                   _loop_opts_cnt;         // loop opts round
304   bool                  _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
305   uint                  _stress_seed;           // Seed for stress testing
306 
307   // Compilation environment.
308   Arena                 _comp_arena;            // Arena with lifetime equivalent to Compile
309   void*                 _barrier_set_state;     // Potential GC barrier state for Compile
310   ciEnv*                _env;                   // CI interface
311   DirectiveSet*         _directive;             // Compiler directive
312   CompileLog*           _log;                   // from CompilerThread
313   const char*           _failure_reason;        // for record_failure/failing pattern
314   GrowableArray<CallGenerator*> _intrinsics;    // List of intrinsics.
315   GrowableArray<Node*>  _macro_nodes;           // List of nodes which need to be expanded before matching.
316   GrowableArray<Node*>  _predicate_opaqs;       // List of Opaque1 nodes for the loop predicates.
317   GrowableArray<Node*>  _expensive_nodes;       // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
318   GrowableArray<Node*>  _for_post_loop_igvn;    // List of nodes for IGVN after loop opts are over
319   ConnectionGraph*      _congraph;
320 #ifndef PRODUCT
321   IdealGraphPrinter*    _printer;
322   static IdealGraphPrinter* _debug_file_printer;
323   static IdealGraphPrinter* _debug_network_printer;
324 #endif
325 
326 
327   // Node management
328   uint                  _unique;                // Counter for unique Node indices
329   VectorSet             _dead_node_list;        // Set of dead nodes
330   uint                  _dead_node_count;       // Number of dead nodes; VectorSet::Size() is O(N).
331                                                 // So use this to keep count and make the call O(1).
332   DEBUG_ONLY(Unique_Node_List* _modified_nodes;)   // List of nodes which inputs were modified
333   DEBUG_ONLY(bool       _phase_optimize_finished;) // Used for live node verification while creating new nodes
334 
335   debug_only(static int _debug_idx;)            // Monotonic counter (not reset), use -XX:BreakAtNode=<idx>
336   Arena                 _node_arena;            // Arena for new-space Nodes
337   Arena                 _old_arena;             // Arena for old-space Nodes, lifetime during xform
338   RootNode*             _root;                  // Unique root of compilation, or NULL after bail-out.
339   Node*                 _top;                   // Unique top node.  (Reset by various phases.)
340 
341   Node*                 _immutable_memory;      // Initial memory state
342 
343   Node*                 _recent_alloc_obj;
344   Node*                 _recent_alloc_ctl;
345 
346   // Constant table
347   MachConstantBaseNode* _mach_constant_base_node;  // Constant table base node singleton.
348 
349 
350   // Blocked array of debugging and profiling information,
351   // tracked per node.
352   enum { _log2_node_notes_block_size = 8,
353          _node_notes_block_size = (1<<_log2_node_notes_block_size)
354   };
355   GrowableArray<Node_Notes*>* _node_note_array;
356   Node_Notes*           _default_node_notes;  // default notes for new nodes
357 
358   // After parsing and every bulk phase we hang onto the Root instruction.
359   // The RootNode instruction is where the whole program begins.  It produces
360   // the initial Control and BOTTOM for everybody else.
361 
362   // Type management
363   Arena                 _Compile_types;         // Arena for all types
364   Arena*                _type_arena;            // Alias for _Compile_types except in Initialize_shared()
365   Dict*                 _type_dict;             // Intern table
366   CloneMap              _clone_map;             // used for recording history of cloned nodes
367   size_t                _type_last_size;        // Last allocation size (see Type::operator new/delete)
368   ciMethod*             _last_tf_m;             // Cache for
369   const TypeFunc*       _last_tf;               //  TypeFunc::make
370   AliasType**           _alias_types;           // List of alias types seen so far.
371   int                   _num_alias_types;       // Logical length of _alias_types
372   int                   _max_alias_types;       // Physical length of _alias_types
373   AliasCacheEntry       _alias_cache[AliasCacheSize]; // Gets aliases w/o data structure walking
374 
375   // Parsing, optimization
376   PhaseGVN*             _initial_gvn;           // Results of parse-time PhaseGVN
377   Unique_Node_List*     _for_igvn;              // Initial work-list for next round of Iterative GVN
378   WarmCallInfo*         _warm_calls;            // Sorted work-list for heat-based inlining.
379 
380   GrowableArray<CallGenerator*> _late_inlines;        // List of CallGenerators to be revisited after main parsing has finished.
381   GrowableArray<CallGenerator*> _string_late_inlines; // same but for string operations
382   GrowableArray<CallGenerator*> _boxing_late_inlines; // same but for boxing operations
383 
384   GrowableArray<CallGenerator*> _vector_reboxing_late_inlines; // same but for vector reboxing operations
385 
386   int                           _late_inlines_pos;    // Where in the queue should the next late inlining candidate go (emulate depth first inlining)
387   uint                          _number_of_mh_late_inlines; // number of method handle late inlining still pending
388 
389   GrowableArray<BufferBlob*>    _native_invokers;
390 
391   // Inlining may not happen in parse order which would make
392   // PrintInlining output confusing. Keep track of PrintInlining
393   // pieces in order.
394   class PrintInliningBuffer : public ResourceObj {
395    private:
396     CallGenerator* _cg;
397     stringStream* _ss;
398 
399    public:
PrintInliningBuffer()400     PrintInliningBuffer()
401       : _cg(NULL) { _ss = new stringStream(); }
402 
freeStream()403     void freeStream() { _ss->~stringStream(); _ss = NULL; }
404 
ss() const405     stringStream* ss() const { return _ss; }
cg() const406     CallGenerator* cg() const { return _cg; }
set_cg(CallGenerator * cg)407     void set_cg(CallGenerator* cg) { _cg = cg; }
408   };
409 
410   stringStream* _print_inlining_stream;
411   GrowableArray<PrintInliningBuffer>* _print_inlining_list;
412   int _print_inlining_idx;
413   char* _print_inlining_output;
414 
415   // Only keep nodes in the expensive node list that need to be optimized
416   void cleanup_expensive_nodes(PhaseIterGVN &igvn);
417   // Use for sorting expensive nodes to bring similar nodes together
418   static int cmp_expensive_nodes(Node** n1, Node** n2);
419   // Expensive nodes list already sorted?
420   bool expensive_nodes_sorted() const;
421   // Remove the speculative part of types and clean up the graph
422   void remove_speculative_types(PhaseIterGVN &igvn);
423 
424   void* _replay_inline_data; // Pointer to data loaded from file
425 
426   void print_inlining_stream_free();
427   void print_inlining_init();
428   void print_inlining_reinit();
429   void print_inlining_commit();
430   void print_inlining_push();
431   PrintInliningBuffer& print_inlining_current();
432 
433   void log_late_inline_failure(CallGenerator* cg, const char* msg);
434   DEBUG_ONLY(bool _exception_backedge;)
435 
436  public:
437 
barrier_set_state() const438   void* barrier_set_state() const { return _barrier_set_state; }
439 
print_inlining_stream() const440   outputStream* print_inlining_stream() const {
441     assert(print_inlining() || print_intrinsics(), "PrintInlining off?");
442     return _print_inlining_stream;
443   }
444 
445   void print_inlining_update(CallGenerator* cg);
446   void print_inlining_update_delayed(CallGenerator* cg);
447   void print_inlining_move_to(CallGenerator* cg);
448   void print_inlining_assert_ready();
449   void print_inlining_reset();
450 
print_inlining(ciMethod * method,int inline_level,int bci,const char * msg=NULL)451   void print_inlining(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
452     stringStream ss;
453     CompileTask::print_inlining_inner(&ss, method, inline_level, bci, msg);
454     print_inlining_stream()->print("%s", ss.as_string());
455   }
456 
457 #ifndef PRODUCT
printer()458   IdealGraphPrinter* printer() { return _printer; }
459 #endif
460 
461   void log_late_inline(CallGenerator* cg);
462   void log_inline_id(CallGenerator* cg);
463   void log_inline_failure(const char* msg);
464 
replay_inline_data() const465   void* replay_inline_data() const { return _replay_inline_data; }
466 
467   // Dump inlining replay data to the stream.
468   void dump_inline_data(outputStream* out);
469 
470  private:
471   // Matching, CFG layout, allocation, code generation
472   PhaseCFG*             _cfg;                   // Results of CFG finding
473   int                   _java_calls;            // Number of java calls in the method
474   int                   _inner_loops;           // Number of inner loops in the method
475   Matcher*              _matcher;               // Engine to map ideal to machine instructions
476   PhaseRegAlloc*        _regalloc;              // Results of register allocation.
477   RegMask               _FIRST_STACK_mask;      // All stack slots usable for spills (depends on frame layout)
478   Arena*                _indexSet_arena;        // control IndexSet allocation within PhaseChaitin
479   void*                 _indexSet_free_block_list; // free list of IndexSet bit blocks
480   int                   _interpreter_frame_size;
481 
482   PhaseOutput*          _output;
483 
484   void reshape_address(AddPNode* n);
485 
486  public:
487   // Accessors
488 
489   // The Compile instance currently active in this (compiler) thread.
current()490   static Compile* current() {
491     return (Compile*) ciEnv::current()->compiler_data();
492   }
493 
interpreter_frame_size() const494   int interpreter_frame_size() const            { return _interpreter_frame_size; }
495 
output() const496   PhaseOutput*      output() const              { return _output; }
set_output(PhaseOutput * o)497   void              set_output(PhaseOutput* o)  { _output = o; }
498 
499   // ID for this compilation.  Useful for setting breakpoints in the debugger.
compile_id() const500   int               compile_id() const          { return _compile_id; }
directive() const501   DirectiveSet*     directive() const           { return _directive; }
502 
503   // Does this compilation allow instructions to subsume loads?  User
504   // instructions that subsume a load may result in an unschedulable
505   // instruction sequence.
subsume_loads() const506   bool              subsume_loads() const       { return _subsume_loads; }
507   /** Do escape analysis. */
do_escape_analysis() const508   bool              do_escape_analysis() const  { return _do_escape_analysis; }
509   /** Do boxing elimination. */
eliminate_boxing() const510   bool              eliminate_boxing() const    { return _eliminate_boxing; }
511   /** Do aggressive boxing elimination. */
aggressive_unboxing() const512   bool              aggressive_unboxing() const { return _eliminate_boxing && AggressiveUnboxing; }
save_argument_registers() const513   bool              save_argument_registers() const { return _save_argument_registers; }
should_install_code() const514   bool              should_install_code() const { return _install_code; }
515 
516   // Other fixed compilation parameters.
method() const517   ciMethod*         method() const              { return _method; }
entry_bci() const518   int               entry_bci() const           { return _entry_bci; }
is_osr_compilation() const519   bool              is_osr_compilation() const  { return _entry_bci != InvocationEntryBci; }
is_method_compilation() const520   bool              is_method_compilation() const { return (_method != NULL && !_method->flags().is_native()); }
tf() const521   const TypeFunc*   tf() const                  { assert(_tf!=NULL, ""); return _tf; }
init_tf(const TypeFunc * tf)522   void         init_tf(const TypeFunc* tf)      { assert(_tf==NULL, ""); _tf = tf; }
ilt() const523   InlineTree*       ilt() const                 { return _ilt; }
stub_function() const524   address           stub_function() const       { return _stub_function; }
stub_name() const525   const char*       stub_name() const           { return _stub_name; }
stub_entry_point() const526   address           stub_entry_point() const    { return _stub_entry_point; }
set_stub_entry_point(address z)527   void          set_stub_entry_point(address z) { _stub_entry_point = z; }
528 
529   // Control of this compilation.
fixed_slots() const530   int               fixed_slots() const         { assert(_fixed_slots >= 0, "");         return _fixed_slots; }
set_fixed_slots(int n)531   void          set_fixed_slots(int n)          { _fixed_slots = n; }
major_progress() const532   int               major_progress() const      { return _major_progress; }
set_inlining_progress(bool z)533   void          set_inlining_progress(bool z)   { _inlining_progress = z; }
inlining_progress() const534   int               inlining_progress() const   { return _inlining_progress; }
set_inlining_incrementally(bool z)535   void          set_inlining_incrementally(bool z) { _inlining_incrementally = z; }
inlining_incrementally() const536   int               inlining_incrementally() const { return _inlining_incrementally; }
set_do_cleanup(bool z)537   void          set_do_cleanup(bool z)          { _do_cleanup = z; }
do_cleanup() const538   int               do_cleanup() const          { return _do_cleanup; }
set_major_progress()539   void          set_major_progress()            { _major_progress++; }
restore_major_progress(int progress)540   void          restore_major_progress(int progress) { _major_progress += progress; }
clear_major_progress()541   void        clear_major_progress()            { _major_progress = 0; }
max_inline_size() const542   int               max_inline_size() const     { return _max_inline_size; }
set_freq_inline_size(int n)543   void          set_freq_inline_size(int n)     { _freq_inline_size = n; }
freq_inline_size() const544   int               freq_inline_size() const    { return _freq_inline_size; }
set_max_inline_size(int n)545   void          set_max_inline_size(int n)      { _max_inline_size = n; }
has_loops() const546   bool              has_loops() const           { return _has_loops; }
set_has_loops(bool z)547   void          set_has_loops(bool z)           { _has_loops = z; }
has_split_ifs() const548   bool              has_split_ifs() const       { return _has_split_ifs; }
set_has_split_ifs(bool z)549   void          set_has_split_ifs(bool z)       { _has_split_ifs = z; }
has_unsafe_access() const550   bool              has_unsafe_access() const   { return _has_unsafe_access; }
set_has_unsafe_access(bool z)551   void          set_has_unsafe_access(bool z)   { _has_unsafe_access = z; }
has_stringbuilder() const552   bool              has_stringbuilder() const   { return _has_stringbuilder; }
set_has_stringbuilder(bool z)553   void          set_has_stringbuilder(bool z)   { _has_stringbuilder = z; }
has_boxed_value() const554   bool              has_boxed_value() const     { return _has_boxed_value; }
set_has_boxed_value(bool z)555   void          set_has_boxed_value(bool z)     { _has_boxed_value = z; }
has_reserved_stack_access() const556   bool              has_reserved_stack_access() const { return _has_reserved_stack_access; }
set_has_reserved_stack_access(bool z)557   void          set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
max_vector_size() const558   uint              max_vector_size() const     { return _max_vector_size; }
set_max_vector_size(uint s)559   void          set_max_vector_size(uint s)     { _max_vector_size = s; }
clear_upper_avx() const560   bool              clear_upper_avx() const     { return _clear_upper_avx; }
set_clear_upper_avx(bool s)561   void          set_clear_upper_avx(bool s)     { _clear_upper_avx = s; }
set_trap_count(uint r,uint c)562   void          set_trap_count(uint r, uint c)  { assert(r < trapHistLength, "oob");        _trap_hist[r] = c; }
trap_count(uint r) const563   uint              trap_count(uint r) const    { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
trap_can_recompile() const564   bool              trap_can_recompile() const  { return _trap_can_recompile; }
set_trap_can_recompile(bool z)565   void          set_trap_can_recompile(bool z)  { _trap_can_recompile = z; }
decompile_count() const566   uint              decompile_count() const     { return _decompile_count; }
set_decompile_count(uint c)567   void          set_decompile_count(uint c)     { _decompile_count = c; }
568   bool              allow_range_check_smearing() const;
do_inlining() const569   bool              do_inlining() const         { return _do_inlining; }
set_do_inlining(bool z)570   void          set_do_inlining(bool z)         { _do_inlining = z; }
do_scheduling() const571   bool              do_scheduling() const       { return _do_scheduling; }
set_do_scheduling(bool z)572   void          set_do_scheduling(bool z)       { _do_scheduling = z; }
do_freq_based_layout() const573   bool              do_freq_based_layout() const{ return _do_freq_based_layout; }
set_do_freq_based_layout(bool z)574   void          set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
do_vector_loop() const575   bool              do_vector_loop() const      { return _do_vector_loop; }
set_do_vector_loop(bool z)576   void          set_do_vector_loop(bool z)      { _do_vector_loop = z; }
use_cmove() const577   bool              use_cmove() const           { return _use_cmove; }
set_use_cmove(bool z)578   void          set_use_cmove(bool z)           { _use_cmove = z; }
age_code() const579   bool              age_code() const             { return _age_code; }
set_age_code(bool z)580   void          set_age_code(bool z)             { _age_code = z; }
AliasLevel() const581   int               AliasLevel() const           { return _AliasLevel; }
print_assembly() const582   bool              print_assembly() const       { return _print_assembly; }
set_print_assembly(bool z)583   void          set_print_assembly(bool z)       { _print_assembly = z; }
print_inlining() const584   bool              print_inlining() const       { return _print_inlining; }
set_print_inlining(bool z)585   void          set_print_inlining(bool z)       { _print_inlining = z; }
print_intrinsics() const586   bool              print_intrinsics() const     { return _print_intrinsics; }
set_print_intrinsics(bool z)587   void          set_print_intrinsics(bool z)     { _print_intrinsics = z; }
rtm_state() const588   RTMState          rtm_state()  const           { return _rtm_state; }
set_rtm_state(RTMState s)589   void          set_rtm_state(RTMState s)        { _rtm_state = s; }
use_rtm() const590   bool              use_rtm() const              { return (_rtm_state & NoRTM) == 0; }
profile_rtm() const591   bool          profile_rtm() const              { return _rtm_state == ProfileRTM; }
max_node_limit() const592   uint              max_node_limit() const       { return (uint)_max_node_limit; }
set_max_node_limit(uint n)593   void          set_max_node_limit(uint n)       { _max_node_limit = n; }
clinit_barrier_on_entry()594   bool              clinit_barrier_on_entry()       { return _clinit_barrier_on_entry; }
set_clinit_barrier_on_entry(bool z)595   void          set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
596 
597   // check the CompilerOracle for special behaviours for this compile
method_has_option(enum CompileCommand option)598   bool          method_has_option(enum CompileCommand option) {
599     return method() != NULL && method()->has_option(option);
600   }
601 
602 #ifndef PRODUCT
trace_opto_output() const603   bool          trace_opto_output() const       { return _trace_opto_output; }
print_ideal() const604   bool          print_ideal() const             { return _print_ideal; }
parsed_irreducible_loop() const605   bool              parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
set_parsed_irreducible_loop(bool z)606   void          set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
607   int _in_dump_cnt;  // Required for dumping ir nodes.
608 #endif
has_irreducible_loop() const609   bool              has_irreducible_loop() const { return _has_irreducible_loop; }
set_has_irreducible_loop(bool z)610   void          set_has_irreducible_loop(bool z) { _has_irreducible_loop = z; }
611 
612   // JSR 292
has_method_handle_invokes() const613   bool              has_method_handle_invokes() const { return _has_method_handle_invokes;     }
set_has_method_handle_invokes(bool z)614   void          set_has_method_handle_invokes(bool z) {        _has_method_handle_invokes = z; }
615 
616   Ticks _latest_stage_start_counter;
617 
begin_method(int level=1)618   void begin_method(int level = 1) {
619 #ifndef PRODUCT
620     if (_method != NULL && should_print(level)) {
621       _printer->begin_method();
622     }
623 #endif
624     C->_latest_stage_start_counter.stamp();
625   }
626 
should_print(int level=1)627   bool should_print(int level = 1) {
628 #ifndef PRODUCT
629     if (PrintIdealGraphLevel < 0) { // disabled by the user
630       return false;
631     }
632 
633     bool need = directive()->IGVPrintLevelOption >= level;
634     if (need && !_printer) {
635       _printer = IdealGraphPrinter::printer();
636       assert(_printer != NULL, "_printer is NULL when we need it!");
637       _printer->set_compile(this);
638     }
639     return need;
640 #else
641     return false;
642 #endif
643   }
644 
645   void print_method(CompilerPhaseType cpt, const char *name, int level = 1, int idx = 0);
646   void print_method(CompilerPhaseType cpt, int level = 1, int idx = 0);
647   void print_method(CompilerPhaseType cpt, Node* n, int level = 3);
648 
649 #ifndef PRODUCT
650   void igv_print_method_to_file(const char* phase_name = "Debug", bool append = false);
651   void igv_print_method_to_network(const char* phase_name = "Debug");
debug_file_printer()652   static IdealGraphPrinter* debug_file_printer() { return _debug_file_printer; }
debug_network_printer()653   static IdealGraphPrinter* debug_network_printer() { return _debug_network_printer; }
654 #endif
655 
656   void end_method(int level = 1);
657 
macro_count() const658   int           macro_count()             const { return _macro_nodes.length(); }
predicate_count() const659   int           predicate_count()         const { return _predicate_opaqs.length();}
expensive_count() const660   int           expensive_count()         const { return _expensive_nodes.length(); }
661 
macro_node(int idx) const662   Node*         macro_node(int idx)       const { return _macro_nodes.at(idx); }
predicate_opaque1_node(int idx) const663   Node*         predicate_opaque1_node(int idx) const { return _predicate_opaqs.at(idx);}
expensive_node(int idx) const664   Node*         expensive_node(int idx)   const { return _expensive_nodes.at(idx); }
665 
congraph()666   ConnectionGraph* congraph()                   { return _congraph;}
set_congraph(ConnectionGraph * congraph)667   void set_congraph(ConnectionGraph* congraph)  { _congraph = congraph;}
add_macro_node(Node * n)668   void add_macro_node(Node * n) {
669     //assert(n->is_macro(), "must be a macro node");
670     assert(!_macro_nodes.contains(n), "duplicate entry in expand list");
671     _macro_nodes.append(n);
672   }
remove_macro_node(Node * n)673   void remove_macro_node(Node* n) {
674     // this function may be called twice for a node so we can only remove it
675     // if it's still existing.
676     _macro_nodes.remove_if_existing(n);
677     // remove from _predicate_opaqs list also if it is there
678     if (predicate_count() > 0) {
679       _predicate_opaqs.remove_if_existing(n);
680     }
681   }
682   void add_expensive_node(Node* n);
remove_expensive_node(Node * n)683   void remove_expensive_node(Node* n) {
684     _expensive_nodes.remove_if_existing(n);
685   }
add_predicate_opaq(Node * n)686   void add_predicate_opaq(Node* n) {
687     assert(!_predicate_opaqs.contains(n), "duplicate entry in predicate opaque1");
688     assert(_macro_nodes.contains(n), "should have already been in macro list");
689     _predicate_opaqs.append(n);
690   }
691 
post_loop_opts_phase()692   bool       post_loop_opts_phase() { return _post_loop_opts_phase;  }
set_post_loop_opts_phase()693   void   set_post_loop_opts_phase() { _post_loop_opts_phase = true;  }
reset_post_loop_opts_phase()694   void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
695 
696   void record_for_post_loop_opts_igvn(Node* n);
697   void remove_from_post_loop_opts_igvn(Node* n);
698   void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
699 
700   void sort_macro_nodes();
701 
702   // remove the opaque nodes that protect the predicates so that the unused checks and
703   // uncommon traps will be eliminated from the graph.
704   void cleanup_loop_predicates(PhaseIterGVN &igvn);
is_predicate_opaq(Node * n)705   bool is_predicate_opaq(Node* n) {
706     return _predicate_opaqs.contains(n);
707   }
708 
709   // Are there candidate expensive nodes for optimization?
710   bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
711   // Check whether n1 and n2 are similar
712   static int cmp_expensive_nodes(Node* n1, Node* n2);
713   // Sort expensive nodes to locate similar expensive nodes
714   void sort_expensive_nodes();
715 
716   // Compilation environment.
comp_arena()717   Arena*      comp_arena()           { return &_comp_arena; }
env() const718   ciEnv*      env() const            { return _env; }
log() const719   CompileLog* log() const            { return _log; }
failing() const720   bool        failing() const        { return _env->failing() || _failure_reason != NULL; }
failure_reason() const721   const char* failure_reason() const { return (_env->failing()) ? _env->failure_reason() : _failure_reason; }
722 
failure_reason_is(const char * r) const723   bool failure_reason_is(const char* r) const {
724     return (r == _failure_reason) || (r != NULL && _failure_reason != NULL && strcmp(r, _failure_reason) == 0);
725   }
726 
727   void record_failure(const char* reason);
record_method_not_compilable(const char * reason)728   void record_method_not_compilable(const char* reason) {
729     // Bailouts cover "all_tiers" when TieredCompilation is off.
730     env()->record_method_not_compilable(reason, !TieredCompilation);
731     // Record failure reason.
732     record_failure(reason);
733   }
check_node_count(uint margin,const char * reason)734   bool check_node_count(uint margin, const char* reason) {
735     if (live_nodes() + margin > max_node_limit()) {
736       record_method_not_compilable(reason);
737       return true;
738     } else {
739       return false;
740     }
741   }
742 
743   // Node management
unique() const744   uint         unique() const              { return _unique; }
next_unique()745   uint         next_unique()               { return _unique++; }
set_unique(uint i)746   void         set_unique(uint i)          { _unique = i; }
debug_idx()747   static int   debug_idx()                 { return debug_only(_debug_idx)+0; }
set_debug_idx(int i)748   static void  set_debug_idx(int i)        { debug_only(_debug_idx = i); }
node_arena()749   Arena*       node_arena()                { return &_node_arena; }
old_arena()750   Arena*       old_arena()                 { return &_old_arena; }
root() const751   RootNode*    root() const                { return _root; }
set_root(RootNode * r)752   void         set_root(RootNode* r)       { _root = r; }
753   StartNode*   start() const;              // (Derived from root.)
754   void         init_start(StartNode* s);
755   Node*        immutable_memory();
756 
recent_alloc_ctl() const757   Node*        recent_alloc_ctl() const    { return _recent_alloc_ctl; }
recent_alloc_obj() const758   Node*        recent_alloc_obj() const    { return _recent_alloc_obj; }
set_recent_alloc(Node * ctl,Node * obj)759   void         set_recent_alloc(Node* ctl, Node* obj) {
760                                                   _recent_alloc_ctl = ctl;
761                                                   _recent_alloc_obj = obj;
762                                            }
record_dead_node(uint idx)763   void         record_dead_node(uint idx)  { if (_dead_node_list.test_set(idx)) return;
764                                              _dead_node_count++;
765                                            }
reset_dead_node_list()766   void         reset_dead_node_list()      { _dead_node_list.reset();
767                                              _dead_node_count = 0;
768                                            }
live_nodes() const769   uint          live_nodes() const         {
770     int  val = _unique - _dead_node_count;
771     assert (val >= 0, "number of tracked dead nodes %d more than created nodes %d", _unique, _dead_node_count);
772             return (uint) val;
773                                            }
774 #ifdef ASSERT
set_phase_optimize_finished()775   void         set_phase_optimize_finished() { _phase_optimize_finished = true; }
phase_optimize_finished() const776   bool         phase_optimize_finished() const { return _phase_optimize_finished; }
777   uint         count_live_nodes_by_graph_walk();
778   void         print_missing_nodes();
779 #endif
780 
781   // Record modified nodes to check that they are put on IGVN worklist
782   void         record_modified_node(Node* n) NOT_DEBUG_RETURN;
783   void         remove_modified_node(Node* n) NOT_DEBUG_RETURN;
784   DEBUG_ONLY( Unique_Node_List*   modified_nodes() const { return _modified_nodes; } )
785 
786   MachConstantBaseNode*     mach_constant_base_node();
has_mach_constant_base_node() const787   bool                  has_mach_constant_base_node() const { return _mach_constant_base_node != NULL; }
788   // Generated by adlc, true if CallNode requires MachConstantBase.
789   bool                      needs_clone_jvms();
790 
791   // Handy undefined Node
top() const792   Node*             top() const                 { return _top; }
793 
794   // these are used by guys who need to know about creation and transformation of top:
cached_top_node()795   Node*             cached_top_node()           { return _top; }
796   void          set_cached_top_node(Node* tn);
797 
node_note_array() const798   GrowableArray<Node_Notes*>* node_note_array() const { return _node_note_array; }
set_node_note_array(GrowableArray<Node_Notes * > * arr)799   void set_node_note_array(GrowableArray<Node_Notes*>* arr) { _node_note_array = arr; }
default_node_notes() const800   Node_Notes* default_node_notes() const        { return _default_node_notes; }
set_default_node_notes(Node_Notes * n)801   void    set_default_node_notes(Node_Notes* n) { _default_node_notes = n; }
802 
node_notes_at(int idx)803   Node_Notes*       node_notes_at(int idx) {
804     return locate_node_notes(_node_note_array, idx, false);
805   }
806   inline bool   set_node_notes_at(int idx, Node_Notes* value);
807 
808   // Copy notes from source to dest, if they exist.
809   // Overwrite dest only if source provides something.
810   // Return true if information was moved.
811   bool copy_node_notes_to(Node* dest, Node* source);
812 
813   // Workhorse function to sort out the blocked Node_Notes array:
814   inline Node_Notes* locate_node_notes(GrowableArray<Node_Notes*>* arr,
815                                        int idx, bool can_grow = false);
816 
817   void grow_node_notes(GrowableArray<Node_Notes*>* arr, int grow_by);
818 
819   // Type management
type_arena()820   Arena*            type_arena()                { return _type_arena; }
type_dict()821   Dict*             type_dict()                 { return _type_dict; }
type_last_size()822   size_t            type_last_size()            { return _type_last_size; }
num_alias_types()823   int               num_alias_types()           { return _num_alias_types; }
824 
init_type_arena()825   void          init_type_arena()                       { _type_arena = &_Compile_types; }
set_type_arena(Arena * a)826   void          set_type_arena(Arena* a)                { _type_arena = a; }
set_type_dict(Dict * d)827   void          set_type_dict(Dict* d)                  { _type_dict = d; }
set_type_last_size(size_t sz)828   void          set_type_last_size(size_t sz)           { _type_last_size = sz; }
829 
last_tf(ciMethod * m)830   const TypeFunc* last_tf(ciMethod* m) {
831     return (m == _last_tf_m) ? _last_tf : NULL;
832   }
set_last_tf(ciMethod * m,const TypeFunc * tf)833   void set_last_tf(ciMethod* m, const TypeFunc* tf) {
834     assert(m != NULL || tf == NULL, "");
835     _last_tf_m = m;
836     _last_tf = tf;
837   }
838 
alias_type(int idx)839   AliasType*        alias_type(int                idx)  { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
alias_type(const TypePtr * adr_type,ciField * field=NULL)840   AliasType*        alias_type(const TypePtr* adr_type, ciField* field = NULL) { return find_alias_type(adr_type, false, field); }
841   bool         have_alias_type(const TypePtr* adr_type);
842   AliasType*        alias_type(ciField*         field);
843 
get_alias_index(const TypePtr * at)844   int               get_alias_index(const TypePtr* at)  { return alias_type(at)->index(); }
get_adr_type(uint aidx)845   const TypePtr*    get_adr_type(uint aidx)             { return alias_type(aidx)->adr_type(); }
get_general_index(uint aidx)846   int               get_general_index(uint aidx)        { return alias_type(aidx)->general_index(); }
847 
848   // Building nodes
849   void              rethrow_exceptions(JVMState* jvms);
850   void              return_values(JVMState* jvms);
851   JVMState*         build_start_state(StartNode* start, const TypeFunc* tf);
852 
853   // Decide how to build a call.
854   // The profile factor is a discount to apply to this site's interp. profile.
855   CallGenerator*    call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
856                                    JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = NULL,
857                                    bool allow_intrinsics = true);
should_delay_inlining(ciMethod * call_method,JVMState * jvms)858   bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
859     return should_delay_string_inlining(call_method, jvms) ||
860            should_delay_boxing_inlining(call_method, jvms) ||
861            should_delay_vector_inlining(call_method, jvms);
862   }
863   bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
864   bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
865   bool should_delay_vector_inlining(ciMethod* call_method, JVMState* jvms);
866   bool should_delay_vector_reboxing_inlining(ciMethod* call_method, JVMState* jvms);
867 
868   // Helper functions to identify inlining potential at call-site
869   ciMethod* optimize_virtual_call(ciMethod* caller, ciInstanceKlass* klass,
870                                   ciKlass* holder, ciMethod* callee,
871                                   const TypeOopPtr* receiver_type, bool is_virtual,
872                                   bool &call_does_dispatch, int &vtable_index,
873                                   bool check_access = true);
874   ciMethod* optimize_inlining(ciMethod* caller, ciInstanceKlass* klass,
875                               ciMethod* callee, const TypeOopPtr* receiver_type,
876                               bool check_access = true);
877 
878   // Report if there were too many traps at a current method and bci.
879   // Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.
880   // If there is no MDO at all, report no trap unless told to assume it.
881   bool too_many_traps(ciMethod* method, int bci, Deoptimization::DeoptReason reason);
882   // This version, unspecific to a particular bci, asks if
883   // PerMethodTrapLimit was exceeded for all inlined methods seen so far.
884   bool too_many_traps(Deoptimization::DeoptReason reason,
885                       // Privately used parameter for logging:
886                       ciMethodData* logmd = NULL);
887   // Report if there were too many recompiles at a method and bci.
888   bool too_many_recompiles(ciMethod* method, int bci, Deoptimization::DeoptReason reason);
889   // Report if there were too many traps or recompiles at a method and bci.
too_many_traps_or_recompiles(ciMethod * method,int bci,Deoptimization::DeoptReason reason)890   bool too_many_traps_or_recompiles(ciMethod* method, int bci, Deoptimization::DeoptReason reason) {
891     return too_many_traps(method, bci, reason) ||
892            too_many_recompiles(method, bci, reason);
893   }
894   // Return a bitset with the reasons where deoptimization is allowed,
895   // i.e., where there were not too many uncommon traps.
896   int _allowed_reasons;
allowed_deopt_reasons()897   int      allowed_deopt_reasons() { return _allowed_reasons; }
898   void set_allowed_deopt_reasons();
899 
900   // Parsing, optimization
initial_gvn()901   PhaseGVN*         initial_gvn()               { return _initial_gvn; }
for_igvn()902   Unique_Node_List* for_igvn()                  { return _for_igvn; }
903   inline void       record_for_igvn(Node* n);   // Body is after class Unique_Node_List.
set_initial_gvn(PhaseGVN * gvn)904   void          set_initial_gvn(PhaseGVN *gvn)           { _initial_gvn = gvn; }
set_for_igvn(Unique_Node_List * for_igvn)905   void          set_for_igvn(Unique_Node_List *for_igvn) { _for_igvn = for_igvn; }
906 
907   // Replace n by nn using initial_gvn, calling hash_delete and
908   // record_for_igvn as needed.
909   void gvn_replace_by(Node* n, Node* nn);
910 
911 
912   void              identify_useful_nodes(Unique_Node_List &useful);
913   void              update_dead_node_list(Unique_Node_List &useful);
914   void              remove_useless_nodes (Unique_Node_List &useful);
915 
916   void              remove_useless_node(Node* dead);
917 
warm_calls() const918   WarmCallInfo*     warm_calls() const          { return _warm_calls; }
set_warm_calls(WarmCallInfo * l)919   void          set_warm_calls(WarmCallInfo* l) { _warm_calls = l; }
920   WarmCallInfo* pop_warm_call();
921 
922   // Record this CallGenerator for inlining at the end of parsing.
add_late_inline(CallGenerator * cg)923   void              add_late_inline(CallGenerator* cg)        {
924     _late_inlines.insert_before(_late_inlines_pos, cg);
925     _late_inlines_pos++;
926   }
927 
prepend_late_inline(CallGenerator * cg)928   void              prepend_late_inline(CallGenerator* cg)    {
929     _late_inlines.insert_before(0, cg);
930   }
931 
add_string_late_inline(CallGenerator * cg)932   void              add_string_late_inline(CallGenerator* cg) {
933     _string_late_inlines.push(cg);
934   }
935 
add_boxing_late_inline(CallGenerator * cg)936   void              add_boxing_late_inline(CallGenerator* cg) {
937     _boxing_late_inlines.push(cg);
938   }
939 
add_vector_reboxing_late_inline(CallGenerator * cg)940   void              add_vector_reboxing_late_inline(CallGenerator* cg) {
941     _vector_reboxing_late_inlines.push(cg);
942   }
943 
944   void add_native_invoker(BufferBlob* stub);
945 
native_invokers() const946   const GrowableArray<BufferBlob*>& native_invokers() const { return _native_invokers; }
947 
948   void remove_useless_nodes       (GrowableArray<Node*>&        node_list, Unique_Node_List &useful);
949 
950   void remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Unique_Node_List &useful);
951   void remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Node* dead);
952 
953   void process_print_inlining();
954   void dump_print_inlining();
955 
over_inlining_cutoff() const956   bool over_inlining_cutoff() const {
957     if (!inlining_incrementally()) {
958       return unique() > (uint)NodeCountInliningCutoff;
959     } else {
960       // Give some room for incremental inlining algorithm to "breathe"
961       // and avoid thrashing when live node count is close to the limit.
962       // Keep in mind that live_nodes() isn't accurate during inlining until
963       // dead node elimination step happens (see Compile::inline_incrementally).
964       return live_nodes() > (uint)LiveNodeCountInliningCutoff * 11 / 10;
965     }
966   }
967 
inc_number_of_mh_late_inlines()968   void inc_number_of_mh_late_inlines() { _number_of_mh_late_inlines++; }
dec_number_of_mh_late_inlines()969   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--; }
has_mh_late_inlines() const970   bool has_mh_late_inlines() const     { return _number_of_mh_late_inlines > 0; }
971 
972   bool inline_incrementally_one();
973   void inline_incrementally_cleanup(PhaseIterGVN& igvn);
974   void inline_incrementally(PhaseIterGVN& igvn);
975   void inline_string_calls(bool parse_time);
976   void inline_boxing_calls(PhaseIterGVN& igvn);
977   bool optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode);
978   void remove_root_to_sfpts_edges(PhaseIterGVN& igvn);
979 
980   void inline_vector_reboxing_calls();
981   bool has_vbox_nodes();
982 
983   void process_late_inline_calls_no_inline(PhaseIterGVN& igvn);
984 
985   // Matching, CFG layout, allocation, code generation
cfg()986   PhaseCFG*         cfg()                       { return _cfg; }
has_java_calls() const987   bool              has_java_calls() const      { return _java_calls > 0; }
java_calls() const988   int               java_calls() const          { return _java_calls; }
inner_loops() const989   int               inner_loops() const         { return _inner_loops; }
matcher()990   Matcher*          matcher()                   { return _matcher; }
regalloc()991   PhaseRegAlloc*    regalloc()                  { return _regalloc; }
FIRST_STACK_mask()992   RegMask&          FIRST_STACK_mask()          { return _FIRST_STACK_mask; }
indexSet_arena()993   Arena*            indexSet_arena()            { return _indexSet_arena; }
indexSet_free_block_list()994   void*             indexSet_free_block_list()  { return _indexSet_free_block_list; }
debug_info()995   DebugInformationRecorder* debug_info()        { return env()->debug_info(); }
996 
update_interpreter_frame_size(int size)997   void  update_interpreter_frame_size(int size) {
998     if (_interpreter_frame_size < size) {
999       _interpreter_frame_size = size;
1000     }
1001   }
1002 
set_matcher(Matcher * m)1003   void          set_matcher(Matcher* m)                 { _matcher = m; }
1004 //void          set_regalloc(PhaseRegAlloc* ra)           { _regalloc = ra; }
set_indexSet_arena(Arena * a)1005   void          set_indexSet_arena(Arena* a)            { _indexSet_arena = a; }
set_indexSet_free_block_list(void * p)1006   void          set_indexSet_free_block_list(void* p)   { _indexSet_free_block_list = p; }
1007 
set_java_calls(int z)1008   void  set_java_calls(int z) { _java_calls  = z; }
set_inner_loops(int z)1009   void set_inner_loops(int z) { _inner_loops = z; }
1010 
dependencies()1011   Dependencies* dependencies() { return env()->dependencies(); }
1012 
1013   // Major entry point.  Given a Scope, compile the associated method.
1014   // For normal compilations, entry_bci is InvocationEntryBci.  For on stack
1015   // replacement, entry_bci indicates the bytecode for which to compile a
1016   // continuation.
1017   Compile(ciEnv* ci_env, ciMethod* target,
1018           int entry_bci, bool subsume_loads, bool do_escape_analysis,
1019           bool eliminate_boxing, bool install_code, DirectiveSet* directive);
1020 
1021   // Second major entry point.  From the TypeFunc signature, generate code
1022   // to pass arguments from the Java calling convention to the C calling
1023   // convention.
1024   Compile(ciEnv* ci_env, const TypeFunc *(*gen)(),
1025           address stub_function, const char *stub_name,
1026           int is_fancy_jump, bool pass_tls,
1027           bool save_arg_registers, bool return_pc, DirectiveSet* directive);
1028 
1029   // Are we compiling a method?
has_method()1030   bool has_method() { return method() != NULL; }
1031 
1032   // Maybe print some information about this compile.
1033   void print_compile_messages();
1034 
1035   // Final graph reshaping, a post-pass after the regular optimizer is done.
1036   bool final_graph_reshaping();
1037 
1038   // returns true if adr is completely contained in the given alias category
1039   bool must_alias(const TypePtr* adr, int alias_idx);
1040 
1041   // returns true if adr overlaps with the given alias category
1042   bool can_alias(const TypePtr* adr, int alias_idx);
1043 
1044   // If "objs" contains an ObjectValue whose id is "id", returns it, else NULL.
1045   static ObjectValue* sv_for_node_id(GrowableArray<ScopeValue*> *objs, int id);
1046 
1047   // Stack slots that may be unused by the calling convention but must
1048   // otherwise be preserved.  On Intel this includes the return address.
1049   // On PowerPC it includes the 4 words holding the old TOC & LR glue.
in_preserve_stack_slots()1050   uint in_preserve_stack_slots() {
1051     return SharedRuntime::in_preserve_stack_slots();
1052   }
1053 
1054   // "Top of Stack" slots that may be unused by the calling convention but must
1055   // otherwise be preserved.
1056   // On Intel these are not necessary and the value can be zero.
out_preserve_stack_slots()1057   static uint out_preserve_stack_slots() {
1058     return SharedRuntime::out_preserve_stack_slots();
1059   }
1060 
1061   // Number of outgoing stack slots killed above the out_preserve_stack_slots
1062   // for calls to C.  Supports the var-args backing area for register parms.
1063   uint varargs_C_out_slots_killed() const;
1064 
1065   // Number of Stack Slots consumed by a synchronization entry
1066   int sync_stack_slots() const;
1067 
1068   // Compute the name of old_SP.  See <arch>.ad for frame layout.
1069   OptoReg::Name compute_old_SP();
1070 
1071  private:
1072   // Phase control:
1073   void Init(int aliaslevel);                     // Prepare for a single compilation
1074   int  Inline_Warm();                            // Find more inlining work.
1075   void Finish_Warm();                            // Give up on further inlines.
1076   void Optimize();                               // Given a graph, optimize it
1077   void Code_Gen();                               // Generate code from a graph
1078 
1079   // Management of the AliasType table.
1080   void grow_alias_types();
1081   AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1082   const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1083   AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1084 
1085   void verify_top(Node*) const PRODUCT_RETURN;
1086 
1087   // Intrinsic setup.
1088   CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual);          // constructor
1089   int            intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found);  // helper
1090   CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual);             // query fn
1091   void           register_intrinsic(CallGenerator* cg);                    // update fn
1092 
1093 #ifndef PRODUCT
1094   static juint  _intrinsic_hist_count[];
1095   static jubyte _intrinsic_hist_flags[];
1096 #endif
1097   // Function calls made by the public function final_graph_reshaping.
1098   // No need to be made public as they are not called elsewhere.
1099   void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc);
1100   void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop);
1101   void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc );
1102   void eliminate_redundant_card_marks(Node* n);
1103 
1104   // Logic cone optimization.
1105   void optimize_logic_cones(PhaseIterGVN &igvn);
1106   void collect_logic_cone_roots(Unique_Node_List& list);
1107   void process_logic_cone_root(PhaseIterGVN &igvn, Node* n, VectorSet& visited);
1108   bool compute_logic_cone(Node* n, Unique_Node_List& partition, Unique_Node_List& inputs);
1109   uint compute_truth_table(Unique_Node_List& partition, Unique_Node_List& inputs);
1110   uint eval_macro_logic_op(uint func, uint op1, uint op2, uint op3);
1111   Node* xform_to_MacroLogicV(PhaseIterGVN &igvn, const TypeVect* vt, Unique_Node_List& partitions, Unique_Node_List& inputs);
1112 
1113  public:
1114 
1115   // Note:  Histogram array size is about 1 Kb.
1116   enum {                        // flag bits:
1117     _intrinsic_worked = 1,      // succeeded at least once
1118     _intrinsic_failed = 2,      // tried it but it failed
1119     _intrinsic_disabled = 4,    // was requested but disabled (e.g., -XX:-InlineUnsafeOps)
1120     _intrinsic_virtual = 8,     // was seen in the virtual form (rare)
1121     _intrinsic_both = 16        // was seen in the non-virtual form (usual)
1122   };
1123   // Update histogram.  Return boolean if this is a first-time occurrence.
1124   static bool gather_intrinsic_statistics(vmIntrinsics::ID id,
1125                                           bool is_virtual, int flags) PRODUCT_RETURN0;
1126   static void print_intrinsic_statistics() PRODUCT_RETURN;
1127 
1128   // Graph verification code
1129   // Walk the node list, verifying that there is a one-to-one
1130   // correspondence between Use-Def edges and Def-Use edges
1131   // The option no_dead_code enables stronger checks that the
1132   // graph is strongly connected from root in both directions.
1133   void verify_graph_edges(bool no_dead_code = false) PRODUCT_RETURN;
1134 
1135   // End-of-run dumps.
1136   static void print_statistics() PRODUCT_RETURN;
1137 
1138   // Verify ADLC assumptions during startup
1139   static void adlc_verification() PRODUCT_RETURN;
1140 
1141   // Definitions of pd methods
1142   static void pd_compiler2_init();
1143 
1144   // Static parse-time type checking logic for gen_subtype_check:
1145   enum { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1146   int static_subtype_check(ciKlass* superk, ciKlass* subk);
1147 
1148   static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1149                               // Optional control dependency (for example, on range check)
1150                               Node* ctrl = NULL);
1151 
1152   // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1153   static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl);
1154 
1155   // Auxiliary methods for randomized fuzzing/stressing
1156   int random();
1157   bool randomized_select(int count);
1158 
1159   // supporting clone_map
1160   CloneMap&     clone_map();
1161   void          set_clone_map(Dict* d);
1162 
1163   bool needs_clinit_barrier(ciField* ik,         ciMethod* accessing_method);
1164   bool needs_clinit_barrier(ciMethod* ik,        ciMethod* accessing_method);
1165   bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1166 
1167 #ifdef IA32
1168  private:
1169   bool _select_24_bit_instr;   // We selected an instruction with a 24-bit result
1170   bool _in_24_bit_fp_mode;     // We are emitting instructions with 24-bit results
1171 
1172   // Remember if this compilation changes hardware mode to 24-bit precision.
set_24_bit_selection_and_mode(bool selection,bool mode)1173   void set_24_bit_selection_and_mode(bool selection, bool mode) {
1174     _select_24_bit_instr = selection;
1175     _in_24_bit_fp_mode   = mode;
1176   }
1177 
1178  public:
select_24_bit_instr() const1179   bool select_24_bit_instr() const { return _select_24_bit_instr; }
in_24_bit_fp_mode() const1180   bool in_24_bit_fp_mode() const   { return _in_24_bit_fp_mode; }
1181 #endif // IA32
1182 #ifdef ASSERT
1183   bool _type_verify_symmetry;
set_exception_backedge()1184   void set_exception_backedge() { _exception_backedge = true; }
has_exception_backedge() const1185   bool has_exception_backedge() const { return _exception_backedge; }
1186 #endif
1187 
1188   static bool
1189   push_thru_add(PhaseGVN* phase, Node* z, const TypeInteger* tz, const TypeInteger*& rx, const TypeInteger*& ry,
1190                 BasicType bt);
1191 };
1192 
1193 #endif // SHARE_OPTO_COMPILE_HPP
1194