annotate src/share/vm/c1/c1_IR.hpp @ 900:9987d9d5eb0e

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