src/share/vm/c1/c1_IR.hpp

Tue, 22 Sep 2009 14:06:10 -0700

author
xdono
date
Tue, 22 Sep 2009 14:06:10 -0700
changeset 1383
89e0543e1737
parent 1335
9987d9d5eb0e
child 1570
e66fd840cb6b
permissions
-rw-r--r--

6884624: Update copyright year
Summary: Update copyright for files that have been modified in 2009 through Septermber
Reviewed-by: tbell, ohair

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

mercurial