src/share/vm/c1/c1_IR.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_C1_C1_IR_HPP
aoqi@0 26 #define SHARE_VM_C1_C1_IR_HPP
aoqi@0 27
aoqi@0 28 #include "c1/c1_Instruction.hpp"
aoqi@0 29 #include "ci/ciExceptionHandler.hpp"
aoqi@0 30 #include "ci/ciMethod.hpp"
aoqi@0 31 #include "ci/ciStreams.hpp"
aoqi@0 32 #include "memory/allocation.hpp"
aoqi@0 33
aoqi@0 34 // An XHandler is a C1 internal description for an exception handler
aoqi@0 35
aoqi@0 36 class XHandler: public CompilationResourceObj {
aoqi@0 37 private:
aoqi@0 38 ciExceptionHandler* _desc;
aoqi@0 39
aoqi@0 40 BlockBegin* _entry_block; // Entry block of xhandler
aoqi@0 41 LIR_List* _entry_code; // LIR-operations that must be executed before jumping to entry_block
aoqi@0 42 int _entry_pco; // pco where entry_code (or entry_block if no entry_code) starts
aoqi@0 43 int _phi_operand; // For resolving of phi functions at begin of entry_block
aoqi@0 44 int _scope_count; // for filling ExceptionRangeEntry::scope_count
aoqi@0 45
aoqi@0 46 #ifdef ASSERT
aoqi@0 47 int _lir_op_id; // op_id of the LIR-operation throwing to this handler
aoqi@0 48 #endif
aoqi@0 49
aoqi@0 50 public:
aoqi@0 51 // creation
aoqi@0 52 XHandler(ciExceptionHandler* desc)
aoqi@0 53 : _desc(desc)
aoqi@0 54 , _entry_block(NULL)
aoqi@0 55 , _entry_code(NULL)
aoqi@0 56 , _entry_pco(-1)
aoqi@0 57 , _phi_operand(-1)
aoqi@0 58 , _scope_count(-1)
aoqi@0 59 #ifdef ASSERT
aoqi@0 60 , _lir_op_id(-1)
aoqi@0 61 #endif
aoqi@0 62 { }
aoqi@0 63
aoqi@0 64 XHandler(XHandler* other)
aoqi@0 65 : _desc(other->_desc)
aoqi@0 66 , _entry_block(other->_entry_block)
aoqi@0 67 , _entry_code(other->_entry_code)
aoqi@0 68 , _entry_pco(other->_entry_pco)
aoqi@0 69 , _phi_operand(other->_phi_operand)
aoqi@0 70 , _scope_count(other->_scope_count)
aoqi@0 71 #ifdef ASSERT
aoqi@0 72 , _lir_op_id(other->_lir_op_id)
aoqi@0 73 #endif
aoqi@0 74 { }
aoqi@0 75
aoqi@0 76 // accessors for data of ciExceptionHandler
aoqi@0 77 int beg_bci() const { return _desc->start(); }
aoqi@0 78 int end_bci() const { return _desc->limit(); }
aoqi@0 79 int handler_bci() const { return _desc->handler_bci(); }
aoqi@0 80 bool is_catch_all() const { return _desc->is_catch_all(); }
aoqi@0 81 int catch_type() const { return _desc->catch_klass_index(); }
aoqi@0 82 ciInstanceKlass* catch_klass() const { return _desc->catch_klass(); }
aoqi@0 83 bool covers(int bci) const { return beg_bci() <= bci && bci < end_bci(); }
aoqi@0 84
aoqi@0 85 // accessors for additional fields
aoqi@0 86 BlockBegin* entry_block() const { return _entry_block; }
aoqi@0 87 LIR_List* entry_code() const { return _entry_code; }
aoqi@0 88 int entry_pco() const { return _entry_pco; }
aoqi@0 89 int phi_operand() const { assert(_phi_operand != -1, "not set"); return _phi_operand; }
aoqi@0 90 int scope_count() const { assert(_scope_count != -1, "not set"); return _scope_count; }
aoqi@0 91 DEBUG_ONLY(int lir_op_id() const { return _lir_op_id; });
aoqi@0 92
aoqi@0 93 void set_entry_block(BlockBegin* entry_block) {
aoqi@0 94 assert(entry_block->is_set(BlockBegin::exception_entry_flag), "must be an exception handler entry");
aoqi@0 95 assert(entry_block->bci() == handler_bci(), "bci's must correspond");
aoqi@0 96 _entry_block = entry_block;
aoqi@0 97 }
aoqi@0 98 void set_entry_code(LIR_List* entry_code) { _entry_code = entry_code; }
aoqi@0 99 void set_entry_pco(int entry_pco) { _entry_pco = entry_pco; }
aoqi@0 100 void set_phi_operand(int phi_operand) { _phi_operand = phi_operand; }
aoqi@0 101 void set_scope_count(int scope_count) { _scope_count = scope_count; }
aoqi@0 102 DEBUG_ONLY(void set_lir_op_id(int lir_op_id) { _lir_op_id = lir_op_id; });
aoqi@0 103
aoqi@0 104 bool equals(XHandler* other) const;
aoqi@0 105 };
aoqi@0 106
aoqi@0 107 define_array(_XHandlerArray, XHandler*)
aoqi@0 108 define_stack(_XHandlerList, _XHandlerArray)
aoqi@0 109
aoqi@0 110
aoqi@0 111 // XHandlers is the C1 internal list of exception handlers for a method
aoqi@0 112 class XHandlers: public CompilationResourceObj {
aoqi@0 113 private:
aoqi@0 114 _XHandlerList _list;
aoqi@0 115
aoqi@0 116 public:
aoqi@0 117 // creation
aoqi@0 118 XHandlers() : _list() { }
aoqi@0 119 XHandlers(ciMethod* method);
aoqi@0 120 XHandlers(XHandlers* other);
aoqi@0 121
aoqi@0 122 // accessors
aoqi@0 123 int length() const { return _list.length(); }
aoqi@0 124 XHandler* handler_at(int i) const { return _list.at(i); }
aoqi@0 125 bool has_handlers() const { return _list.length() > 0; }
aoqi@0 126 void append(XHandler* h) { _list.append(h); }
aoqi@0 127 XHandler* remove_last() { return _list.pop(); }
aoqi@0 128
aoqi@0 129 bool could_catch(ciInstanceKlass* klass, bool type_is_exact) const;
aoqi@0 130 bool equals(XHandlers* others) const;
aoqi@0 131 };
aoqi@0 132
aoqi@0 133
aoqi@0 134 class IRScope;
aoqi@0 135 define_array(IRScopeArray, IRScope*)
aoqi@0 136 define_stack(IRScopeList, IRScopeArray)
aoqi@0 137
aoqi@0 138 class Compilation;
aoqi@0 139 class IRScope: public CompilationResourceObj {
aoqi@0 140 private:
aoqi@0 141 // hierarchy
aoqi@0 142 Compilation* _compilation; // the current compilation
aoqi@0 143 IRScope* _caller; // the caller scope, or NULL
aoqi@0 144 int _level; // the inlining level
aoqi@0 145 ciMethod* _method; // the corresponding method
aoqi@0 146 IRScopeList _callees; // the inlined method scopes
aoqi@0 147
aoqi@0 148 // graph
aoqi@0 149 XHandlers* _xhandlers; // the exception handlers
aoqi@0 150 int _number_of_locks; // the number of monitor lock slots needed
aoqi@0 151 bool _monitor_pairing_ok; // the monitor pairing info
aoqi@0 152 bool _wrote_final; // has written final field
aoqi@0 153 BlockBegin* _start; // the start block, successsors are method entries
aoqi@0 154
aoqi@0 155 BitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable
aoqi@0 156
aoqi@0 157 // helper functions
aoqi@0 158 BlockBegin* build_graph(Compilation* compilation, int osr_bci);
aoqi@0 159
aoqi@0 160 public:
aoqi@0 161 // creation
aoqi@0 162 IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph = false);
aoqi@0 163
aoqi@0 164 // accessors
aoqi@0 165 Compilation* compilation() const { return _compilation; }
aoqi@0 166 IRScope* caller() const { return _caller; }
aoqi@0 167 int level() const { return _level; }
aoqi@0 168 ciMethod* method() const { return _method; }
aoqi@0 169 int max_stack() const; // NOTE: expensive
aoqi@0 170 BitMap& requires_phi_function() { return _requires_phi_function; }
aoqi@0 171
aoqi@0 172 // hierarchy
aoqi@0 173 bool is_top_scope() const { return _caller == NULL; }
aoqi@0 174 void add_callee(IRScope* callee) { _callees.append(callee); }
aoqi@0 175 int number_of_callees() const { return _callees.length(); }
aoqi@0 176 IRScope* callee_no(int i) const { return _callees.at(i); }
aoqi@0 177
aoqi@0 178 // accessors, graph
aoqi@0 179 bool is_valid() const { return start() != NULL; }
aoqi@0 180 XHandlers* xhandlers() const { return _xhandlers; }
aoqi@0 181 int number_of_locks() const { return _number_of_locks; }
aoqi@0 182 void set_min_number_of_locks(int n) { if (n > _number_of_locks) _number_of_locks = n; }
aoqi@0 183 bool monitor_pairing_ok() const { return _monitor_pairing_ok; }
aoqi@0 184 BlockBegin* start() const { return _start; }
aoqi@0 185 void set_wrote_final() { _wrote_final = true; }
aoqi@0 186 bool wrote_final () const { return _wrote_final; }
aoqi@0 187 };
aoqi@0 188
aoqi@0 189
aoqi@0 190 //
aoqi@0 191 // IRScopeDebugInfo records the debug information for a particular IRScope
aoqi@0 192 // in a particular CodeEmitInfo. This allows the information to be computed
aoqi@0 193 // once early enough for the OopMap to be available to the LIR and also to be
aoqi@0 194 // reemited for different pcs using the same CodeEmitInfo without recomputing
aoqi@0 195 // everything.
aoqi@0 196 //
aoqi@0 197
aoqi@0 198 class IRScopeDebugInfo: public CompilationResourceObj {
aoqi@0 199 private:
aoqi@0 200 IRScope* _scope;
aoqi@0 201 int _bci;
aoqi@0 202 GrowableArray<ScopeValue*>* _locals;
aoqi@0 203 GrowableArray<ScopeValue*>* _expressions;
aoqi@0 204 GrowableArray<MonitorValue*>* _monitors;
aoqi@0 205 IRScopeDebugInfo* _caller;
aoqi@0 206
aoqi@0 207 public:
aoqi@0 208 IRScopeDebugInfo(IRScope* scope,
aoqi@0 209 int bci,
aoqi@0 210 GrowableArray<ScopeValue*>* locals,
aoqi@0 211 GrowableArray<ScopeValue*>* expressions,
aoqi@0 212 GrowableArray<MonitorValue*>* monitors,
aoqi@0 213 IRScopeDebugInfo* caller):
aoqi@0 214 _scope(scope)
aoqi@0 215 , _locals(locals)
aoqi@0 216 , _bci(bci)
aoqi@0 217 , _expressions(expressions)
aoqi@0 218 , _monitors(monitors)
aoqi@0 219 , _caller(caller) {}
aoqi@0 220
aoqi@0 221
aoqi@0 222 IRScope* scope() { return _scope; }
aoqi@0 223 int bci() { return _bci; }
aoqi@0 224 GrowableArray<ScopeValue*>* locals() { return _locals; }
aoqi@0 225 GrowableArray<ScopeValue*>* expressions() { return _expressions; }
aoqi@0 226 GrowableArray<MonitorValue*>* monitors() { return _monitors; }
aoqi@0 227 IRScopeDebugInfo* caller() { return _caller; }
aoqi@0 228
aoqi@0 229 //Whether we should reexecute this bytecode for deopt
aoqi@0 230 bool should_reexecute();
aoqi@0 231
aoqi@0 232 void record_debug_info(DebugInformationRecorder* recorder, int pc_offset, bool topmost, bool is_method_handle_invoke = false) {
aoqi@0 233 if (caller() != NULL) {
aoqi@0 234 // Order is significant: Must record caller first.
aoqi@0 235 caller()->record_debug_info(recorder, pc_offset, false/*topmost*/);
aoqi@0 236 }
aoqi@0 237 DebugToken* locvals = recorder->create_scope_values(locals());
aoqi@0 238 DebugToken* expvals = recorder->create_scope_values(expressions());
aoqi@0 239 DebugToken* monvals = recorder->create_monitor_values(monitors());
aoqi@0 240 // reexecute allowed only for the topmost frame
aoqi@0 241 bool reexecute = topmost ? should_reexecute() : false;
aoqi@0 242 bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis.
aoqi@0 243 recorder->describe_scope(pc_offset, scope()->method(), bci(), reexecute, is_method_handle_invoke, return_oop, locvals, expvals, monvals);
aoqi@0 244 }
aoqi@0 245 };
aoqi@0 246
aoqi@0 247
aoqi@0 248 class CodeEmitInfo: public CompilationResourceObj {
aoqi@0 249 friend class LinearScan;
aoqi@0 250 private:
aoqi@0 251 IRScopeDebugInfo* _scope_debug_info;
aoqi@0 252 IRScope* _scope;
aoqi@0 253 XHandlers* _exception_handlers;
aoqi@0 254 OopMap* _oop_map;
aoqi@0 255 ValueStack* _stack; // used by deoptimization (contains also monitors
aoqi@0 256 bool _is_method_handle_invoke; // true if the associated call site is a MethodHandle call site.
aoqi@0 257 bool _deoptimize_on_exception;
aoqi@0 258
aoqi@0 259 FrameMap* frame_map() const { return scope()->compilation()->frame_map(); }
aoqi@0 260 Compilation* compilation() const { return scope()->compilation(); }
aoqi@0 261
aoqi@0 262 public:
aoqi@0 263
aoqi@0 264 // use scope from ValueStack
aoqi@0 265 CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers, bool deoptimize_on_exception = false);
aoqi@0 266
aoqi@0 267 // make a copy
aoqi@0 268 CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack = NULL);
aoqi@0 269
aoqi@0 270 // accessors
aoqi@0 271 OopMap* oop_map() { return _oop_map; }
aoqi@0 272 ciMethod* method() const { return _scope->method(); }
aoqi@0 273 IRScope* scope() const { return _scope; }
aoqi@0 274 XHandlers* exception_handlers() const { return _exception_handlers; }
aoqi@0 275 ValueStack* stack() const { return _stack; }
aoqi@0 276 bool deoptimize_on_exception() const { return _deoptimize_on_exception; }
aoqi@0 277
aoqi@0 278 void add_register_oop(LIR_Opr opr);
aoqi@0 279 void record_debug_info(DebugInformationRecorder* recorder, int pc_offset);
aoqi@0 280
aoqi@0 281 bool is_method_handle_invoke() const { return _is_method_handle_invoke; }
aoqi@0 282 void set_is_method_handle_invoke(bool x) { _is_method_handle_invoke = x; }
aoqi@0 283
aoqi@0 284 int interpreter_frame_size() const;
aoqi@0 285 };
aoqi@0 286
aoqi@0 287
aoqi@0 288 class IR: public CompilationResourceObj {
aoqi@0 289 private:
aoqi@0 290 Compilation* _compilation; // the current compilation
aoqi@0 291 IRScope* _top_scope; // the root of the scope hierarchy
aoqi@0 292 WordSize _locals_size; // the space required for all locals
aoqi@0 293 int _num_loops; // Total number of loops
aoqi@0 294 BlockList* _code; // the blocks in code generation order w/ use counts
aoqi@0 295
aoqi@0 296 public:
aoqi@0 297 // creation
aoqi@0 298 IR(Compilation* compilation, ciMethod* method, int osr_bci);
aoqi@0 299
aoqi@0 300 // accessors
aoqi@0 301 bool is_valid() const { return top_scope()->is_valid(); }
aoqi@0 302 Compilation* compilation() const { return _compilation; }
aoqi@0 303 IRScope* top_scope() const { return _top_scope; }
aoqi@0 304 int number_of_locks() const { return top_scope()->number_of_locks(); }
aoqi@0 305 ciMethod* method() const { return top_scope()->method(); }
aoqi@0 306 BlockBegin* start() const { return top_scope()->start(); }
aoqi@0 307 BlockBegin* std_entry() const { return start()->end()->as_Base()->std_entry(); }
aoqi@0 308 BlockBegin* osr_entry() const { return start()->end()->as_Base()->osr_entry(); }
aoqi@0 309 WordSize locals_size() const { return _locals_size; }
aoqi@0 310 int locals_size_in_words() const { return in_words(_locals_size); }
aoqi@0 311 BlockList* code() const { return _code; }
aoqi@0 312 int num_loops() const { return _num_loops; }
aoqi@0 313 int max_stack() const { return top_scope()->max_stack(); } // expensive
aoqi@0 314
aoqi@0 315 // ir manipulation
aoqi@0 316 void optimize_blocks();
aoqi@0 317 void eliminate_null_checks();
aoqi@0 318 void compute_predecessors();
aoqi@0 319 void split_critical_edges();
aoqi@0 320 void compute_code();
aoqi@0 321 void compute_use_counts();
aoqi@0 322
aoqi@0 323 // The linear-scan order and the code emission order are equal, but
aoqi@0 324 // this may change in future
aoqi@0 325 BlockList* linear_scan_order() { assert(_code != NULL, "not computed"); return _code; }
aoqi@0 326
aoqi@0 327 // iteration
aoqi@0 328 void iterate_preorder (BlockClosure* closure);
aoqi@0 329 void iterate_postorder (BlockClosure* closure);
aoqi@0 330 void iterate_linear_scan_order(BlockClosure* closure);
aoqi@0 331
aoqi@0 332 // debugging
aoqi@0 333 static void print(BlockBegin* start, bool cfg_only, bool live_only = false) PRODUCT_RETURN;
aoqi@0 334 void print(bool cfg_only, bool live_only = false) PRODUCT_RETURN;
aoqi@0 335 void verify() PRODUCT_RETURN;
aoqi@0 336 };
aoqi@0 337
aoqi@0 338
aoqi@0 339 // Globally do instruction substitution and remove substituted
aoqi@0 340 // instructions from the instruction list.
aoqi@0 341 //
aoqi@0 342
aoqi@0 343 class SubstitutionResolver: public BlockClosure, ValueVisitor {
aoqi@0 344 virtual void visit(Value* v);
aoqi@0 345
aoqi@0 346 public:
aoqi@0 347 SubstitutionResolver(IR* hir) {
aoqi@0 348 hir->iterate_preorder(this);
aoqi@0 349 }
aoqi@0 350
aoqi@0 351 SubstitutionResolver(BlockBegin* block) {
aoqi@0 352 block->iterate_preorder(this);
aoqi@0 353 }
aoqi@0 354
aoqi@0 355 virtual void block_do(BlockBegin* block);
aoqi@0 356 };
aoqi@0 357
aoqi@0 358 #endif // SHARE_VM_C1_C1_IR_HPP

mercurial