annotate src/share/vm/c1/c1_GraphBuilder.hpp @ 1563:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents ad8c8ca4ab0f
children b812ff5abc73
rev   line source
duke@0 1 /*
trims@1563 2 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. 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 *
trims@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 class MemoryBuffer;
duke@0 26
duke@0 27 class GraphBuilder VALUE_OBJ_CLASS_SPEC {
duke@0 28 private:
duke@0 29 // Per-scope data. These are pushed and popped as we descend into
duke@0 30 // inlined methods. Currently in order to generate good code in the
duke@0 31 // inliner we have to attempt to inline methods directly into the
duke@0 32 // basic block we are parsing; this adds complexity.
duke@0 33 class ScopeData: public CompilationResourceObj {
duke@0 34 private:
duke@0 35 ScopeData* _parent;
duke@0 36 // bci-to-block mapping
duke@0 37 BlockList* _bci2block;
duke@0 38 // Scope
duke@0 39 IRScope* _scope;
duke@0 40 // Whether this scope or any parent scope has exception handlers
duke@0 41 bool _has_handler;
duke@0 42 // The bytecodes
duke@0 43 ciBytecodeStream* _stream;
duke@0 44
duke@0 45 // Work list
duke@0 46 BlockList* _work_list;
duke@0 47
duke@0 48 // Maximum inline size for this scope
duke@0 49 intx _max_inline_size;
duke@0 50 // Expression stack depth at point where inline occurred
duke@0 51 int _caller_stack_size;
duke@0 52
duke@0 53 // The continuation point for the inline. Currently only used in
duke@0 54 // multi-block inlines, but eventually would like to use this for
duke@0 55 // all inlines for uniformity and simplicity; in this case would
duke@0 56 // get the continuation point from the BlockList instead of
duke@0 57 // fabricating it anew because Invokes would be considered to be
duke@0 58 // BlockEnds.
duke@0 59 BlockBegin* _continuation;
duke@0 60
duke@0 61 // Without return value of inlined method on stack
duke@0 62 ValueStack* _continuation_state;
duke@0 63
duke@0 64 // Was this ScopeData created only for the parsing and inlining of
duke@0 65 // a jsr?
duke@0 66 bool _parsing_jsr;
duke@0 67 // We track the destination bci of the jsr only to determine
duke@0 68 // bailout conditions, since we only handle a subset of all of the
duke@0 69 // possible jsr-ret control structures. Recursive invocations of a
duke@0 70 // jsr are disallowed by the verifier.
duke@0 71 int _jsr_entry_bci;
duke@0 72 // We need to track the local variable in which the return address
duke@0 73 // was stored to ensure we can handle inlining the jsr, because we
duke@0 74 // don't handle arbitrary jsr/ret constructs.
duke@0 75 int _jsr_ret_addr_local;
duke@0 76 // If we are parsing a jsr, the continuation point for rets
duke@0 77 BlockBegin* _jsr_continuation;
duke@0 78 // Cloned XHandlers for jsr-related ScopeDatas
duke@0 79 XHandlers* _jsr_xhandlers;
duke@0 80
duke@0 81 // Number of returns seen in this scope
duke@0 82 int _num_returns;
duke@0 83
duke@0 84 // In order to generate profitable code for inlining, we currently
duke@0 85 // have to perform an optimization for single-block inlined
duke@0 86 // methods where we continue parsing into the same block. This
duke@0 87 // allows us to perform CSE across inlined scopes and to avoid
duke@0 88 // storing parameters to the stack. Having a global register
duke@0 89 // allocator and being able to perform global CSE would allow this
duke@0 90 // code to be removed and thereby simplify the inliner.
duke@0 91 BlockBegin* _cleanup_block; // The block to which the return was added
duke@0 92 Instruction* _cleanup_return_prev; // Instruction before return instruction
duke@0 93 ValueStack* _cleanup_state; // State of that block (not yet pinned)
duke@0 94
duke@0 95 public:
duke@0 96 ScopeData(ScopeData* parent);
duke@0 97
duke@0 98 ScopeData* parent() const { return _parent; }
duke@0 99
duke@0 100 BlockList* bci2block() const { return _bci2block; }
duke@0 101 void set_bci2block(BlockList* bci2block) { _bci2block = bci2block; }
duke@0 102
duke@0 103 // NOTE: this has a different effect when parsing jsrs
duke@0 104 BlockBegin* block_at(int bci);
duke@0 105
duke@0 106 IRScope* scope() const { return _scope; }
duke@0 107 // Has side-effect of setting has_handler flag
duke@0 108 void set_scope(IRScope* scope);
duke@0 109
duke@0 110 // Whether this or any parent scope has exception handlers
duke@0 111 bool has_handler() const { return _has_handler; }
duke@0 112 void set_has_handler() { _has_handler = true; }
duke@0 113
duke@0 114 // Exception handlers list to be used for this scope
duke@0 115 XHandlers* xhandlers() const;
duke@0 116
duke@0 117 // How to get a block to be parsed
duke@0 118 void add_to_work_list(BlockBegin* block);
duke@0 119 // How to remove the next block to be parsed; returns NULL if none left
duke@0 120 BlockBegin* remove_from_work_list();
duke@0 121 // Indicates parse is over
duke@0 122 bool is_work_list_empty() const;
duke@0 123
duke@0 124 ciBytecodeStream* stream() { return _stream; }
duke@0 125 void set_stream(ciBytecodeStream* stream) { _stream = stream; }
duke@0 126
duke@0 127 intx max_inline_size() const { return _max_inline_size; }
duke@0 128 int caller_stack_size() const;
duke@0 129
duke@0 130 BlockBegin* continuation() const { return _continuation; }
duke@0 131 void set_continuation(BlockBegin* cont) { _continuation = cont; }
duke@0 132
duke@0 133 ValueStack* continuation_state() const { return _continuation_state; }
duke@0 134 void set_continuation_state(ValueStack* s) { _continuation_state = s; }
duke@0 135
duke@0 136 // Indicates whether this ScopeData was pushed only for the
duke@0 137 // parsing and inlining of a jsr
duke@0 138 bool parsing_jsr() const { return _parsing_jsr; }
duke@0 139 void set_parsing_jsr() { _parsing_jsr = true; }
duke@0 140 int jsr_entry_bci() const { return _jsr_entry_bci; }
duke@0 141 void set_jsr_entry_bci(int bci) { _jsr_entry_bci = bci; }
duke@0 142 void set_jsr_return_address_local(int local_no){ _jsr_ret_addr_local = local_no; }
duke@0 143 int jsr_return_address_local() const { return _jsr_ret_addr_local; }
duke@0 144 // Must be called after scope is set up for jsr ScopeData
duke@0 145 void setup_jsr_xhandlers();
duke@0 146
duke@0 147 // The jsr continuation is only used when parsing_jsr is true, and
duke@0 148 // is different from the "normal" continuation since we can end up
duke@0 149 // doing a return (rather than a ret) from within a subroutine
duke@0 150 BlockBegin* jsr_continuation() const { return _jsr_continuation; }
duke@0 151 void set_jsr_continuation(BlockBegin* cont) { _jsr_continuation = cont; }
duke@0 152
duke@0 153 int num_returns();
duke@0 154 void incr_num_returns();
duke@0 155
duke@0 156 void set_inline_cleanup_info(BlockBegin* block,
duke@0 157 Instruction* return_prev,
duke@0 158 ValueStack* return_state);
duke@0 159 BlockBegin* inline_cleanup_block() const { return _cleanup_block; }
duke@0 160 Instruction* inline_cleanup_return_prev() const{ return _cleanup_return_prev; }
duke@0 161 ValueStack* inline_cleanup_state() const { return _cleanup_state; }
duke@0 162 };
duke@0 163
duke@0 164 // for all GraphBuilders
duke@0 165 static bool _is_initialized; // true if trap tables were initialized, false otherwise
duke@0 166 static bool _can_trap[Bytecodes::number_of_java_codes];
duke@0 167 static bool _is_async[Bytecodes::number_of_java_codes];
duke@0 168
duke@0 169 // for each instance of GraphBuilder
duke@0 170 ScopeData* _scope_data; // Per-scope data; used for inlining
duke@0 171 Compilation* _compilation; // the current compilation
duke@0 172 ValueMap* _vmap; // the map of values encountered (for CSE)
duke@0 173 MemoryBuffer* _memory;
duke@0 174 const char* _inline_bailout_msg; // non-null if most recent inline attempt failed
duke@0 175 int _instruction_count; // for bailing out in pathological jsr/ret cases
duke@0 176 BlockBegin* _start; // the start block
duke@0 177 BlockBegin* _osr_entry; // the osr entry block block
duke@0 178 ValueStack* _initial_state; // The state for the start block
duke@0 179
duke@0 180 // for each call to connect_to_end; can also be set by inliner
duke@0 181 BlockBegin* _block; // the current block
duke@0 182 ValueStack* _state; // the current execution state
duke@0 183 ValueStack* _exception_state; // state that will be used by handle_exception
duke@0 184 Instruction* _last; // the last instruction added
duke@0 185 bool _skip_block; // skip processing of the rest of this block
duke@0 186
duke@0 187 // accessors
duke@0 188 ScopeData* scope_data() const { return _scope_data; }
duke@0 189 Compilation* compilation() const { return _compilation; }
duke@0 190 BlockList* bci2block() const { return scope_data()->bci2block(); }
duke@0 191 ValueMap* vmap() const { assert(UseLocalValueNumbering, "should not access otherwise"); return _vmap; }
duke@0 192 bool has_handler() const { return scope_data()->has_handler(); }
duke@0 193
duke@0 194 BlockBegin* block() const { return _block; }
duke@0 195 ValueStack* state() const { return _state; }
duke@0 196 void set_state(ValueStack* state) { _state = state; }
duke@0 197 IRScope* scope() const { return scope_data()->scope(); }
duke@0 198 ValueStack* exception_state() const { return _exception_state; }
duke@0 199 void set_exception_state(ValueStack* s) { _exception_state = s; }
duke@0 200 ciMethod* method() const { return scope()->method(); }
duke@0 201 ciBytecodeStream* stream() const { return scope_data()->stream(); }
duke@0 202 Instruction* last() const { return _last; }
duke@0 203 Bytecodes::Code code() const { return stream()->cur_bc(); }
duke@0 204 int bci() const { return stream()->cur_bci(); }
duke@0 205 int next_bci() const { return stream()->next_bci(); }
duke@0 206
duke@0 207 // unified bailout support
duke@0 208 void bailout(const char* msg) const { compilation()->bailout(msg); }
duke@0 209 bool bailed_out() const { return compilation()->bailed_out(); }
duke@0 210
duke@0 211 // stack manipulation helpers
duke@0 212 void ipush(Value t) const { state()->ipush(t); }
duke@0 213 void lpush(Value t) const { state()->lpush(t); }
duke@0 214 void fpush(Value t) const { state()->fpush(t); }
duke@0 215 void dpush(Value t) const { state()->dpush(t); }
duke@0 216 void apush(Value t) const { state()->apush(t); }
duke@0 217 void push(ValueType* type, Value t) const { state()-> push(type, t); }
duke@0 218
duke@0 219 Value ipop() { return state()->ipop(); }
duke@0 220 Value lpop() { return state()->lpop(); }
duke@0 221 Value fpop() { return state()->fpop(); }
duke@0 222 Value dpop() { return state()->dpop(); }
duke@0 223 Value apop() { return state()->apop(); }
duke@0 224 Value pop(ValueType* type) { return state()-> pop(type); }
duke@0 225
duke@0 226 // instruction helpers
duke@0 227 void load_constant();
duke@0 228 void load_local(ValueType* type, int index);
duke@0 229 void store_local(ValueType* type, int index);
duke@0 230 void store_local(ValueStack* state, Value value, ValueType* type, int index);
duke@0 231 void load_indexed (BasicType type);
duke@0 232 void store_indexed(BasicType type);
duke@0 233 void stack_op(Bytecodes::Code code);
duke@0 234 void arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* lock_stack = NULL);
duke@0 235 void negate_op(ValueType* type);
duke@0 236 void shift_op(ValueType* type, Bytecodes::Code code);
duke@0 237 void logic_op(ValueType* type, Bytecodes::Code code);
duke@0 238 void compare_op(ValueType* type, Bytecodes::Code code);
duke@0 239 void convert(Bytecodes::Code op, BasicType from, BasicType to);
duke@0 240 void increment();
duke@0 241 void _goto(int from_bci, int to_bci);
duke@0 242 void if_node(Value x, If::Condition cond, Value y, ValueStack* stack_before);
duke@0 243 void if_zero(ValueType* type, If::Condition cond);
duke@0 244 void if_null(ValueType* type, If::Condition cond);
duke@0 245 void if_same(ValueType* type, If::Condition cond);
duke@0 246 void jsr(int dest);
duke@0 247 void ret(int local_index);
duke@0 248 void table_switch();
duke@0 249 void lookup_switch();
duke@0 250 void method_return(Value x);
duke@0 251 void call_register_finalizer();
duke@0 252 void access_field(Bytecodes::Code code);
duke@0 253 void invoke(Bytecodes::Code code);
duke@0 254 void new_instance(int klass_index);
duke@0 255 void new_type_array();
duke@0 256 void new_object_array();
duke@0 257 void check_cast(int klass_index);
duke@0 258 void instance_of(int klass_index);
duke@0 259 void monitorenter(Value x, int bci);
duke@0 260 void monitorexit(Value x, int bci);
duke@0 261 void new_multi_array(int dimensions);
duke@0 262 void throw_op(int bci);
duke@0 263 Value round_fp(Value fp_value);
duke@0 264
duke@0 265 // stack/code manipulation helpers
duke@0 266 Instruction* append_with_bci(Instruction* instr, int bci);
duke@0 267 Instruction* append(Instruction* instr);
duke@0 268 Instruction* append_split(StateSplit* instr);
duke@0 269
duke@0 270 // other helpers
duke@0 271 static bool is_initialized() { return _is_initialized; }
duke@0 272 static bool is_async(Bytecodes::Code code) {
duke@0 273 assert(0 <= code && code < Bytecodes::number_of_java_codes, "illegal bytecode");
duke@0 274 return _is_async[code];
duke@0 275 }
duke@0 276 BlockBegin* block_at(int bci) { return scope_data()->block_at(bci); }
duke@0 277 XHandlers* handle_exception(int bci);
duke@0 278 void connect_to_end(BlockBegin* beg);
duke@0 279 void null_check(Value value);
duke@0 280 void eliminate_redundant_phis(BlockBegin* start);
duke@0 281 BlockEnd* iterate_bytecodes_for_block(int bci);
duke@0 282 void iterate_all_blocks(bool start_in_current_block_for_inlining = false);
duke@0 283 Dependencies* dependency_recorder() const; // = compilation()->dependencies()
duke@0 284 bool direct_compare(ciKlass* k);
duke@0 285
duke@0 286 void kill_all();
duke@0 287
duke@0 288 ValueStack* lock_stack();
duke@0 289
duke@0 290 //
duke@0 291 // Inlining support
duke@0 292 //
duke@0 293
duke@0 294 // accessors
duke@0 295 bool parsing_jsr() const { return scope_data()->parsing_jsr(); }
duke@0 296 BlockBegin* continuation() const { return scope_data()->continuation(); }
duke@0 297 ValueStack* continuation_state() const { return scope_data()->continuation_state(); }
duke@0 298 BlockBegin* jsr_continuation() const { return scope_data()->jsr_continuation(); }
duke@0 299 int caller_stack_size() const { return scope_data()->caller_stack_size(); }
duke@0 300 void set_continuation(BlockBegin* continuation) { scope_data()->set_continuation(continuation); }
duke@0 301 void set_inline_cleanup_info(BlockBegin* block,
duke@0 302 Instruction* return_prev,
duke@0 303 ValueStack* return_state) { scope_data()->set_inline_cleanup_info(block,
duke@0 304 return_prev,
duke@0 305 return_state); }
duke@0 306 BlockBegin* inline_cleanup_block() const { return scope_data()->inline_cleanup_block(); }
duke@0 307 Instruction* inline_cleanup_return_prev() const { return scope_data()->inline_cleanup_return_prev(); }
duke@0 308 ValueStack* inline_cleanup_state() const { return scope_data()->inline_cleanup_state(); }
duke@0 309 void incr_num_returns() { scope_data()->incr_num_returns(); }
duke@0 310 int num_returns() const { return scope_data()->num_returns(); }
duke@0 311 intx max_inline_size() const { return scope_data()->max_inline_size(); }
duke@0 312 int inline_level() const { return scope()->level(); }
duke@0 313 int recursive_inline_level(ciMethod* callee) const;
duke@0 314
duke@0 315 // inlining of synchronized methods
duke@0 316 void inline_sync_entry(Value lock, BlockBegin* sync_handler);
duke@0 317 void fill_sync_handler(Value lock, BlockBegin* sync_handler, bool default_handler = false);
duke@0 318
duke@0 319 // inliners
duke@0 320 bool try_inline(ciMethod* callee, bool holder_known);
duke@0 321 bool try_inline_intrinsics(ciMethod* callee);
duke@0 322 bool try_inline_full (ciMethod* callee, bool holder_known);
duke@0 323 bool try_inline_jsr(int jsr_dest_bci);
duke@0 324
duke@0 325 // helpers
duke@0 326 void inline_bailout(const char* msg);
duke@0 327 BlockBegin* header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state);
duke@0 328 BlockBegin* setup_start_block(int osr_bci, BlockBegin* std_entry, BlockBegin* osr_entry, ValueStack* init_state);
duke@0 329 void setup_osr_entry_block();
duke@0 330 void clear_inline_bailout();
duke@0 331 ValueStack* state_at_entry();
duke@0 332 void push_root_scope(IRScope* scope, BlockList* bci2block, BlockBegin* start);
duke@0 333 void push_scope(ciMethod* callee, BlockBegin* continuation);
duke@0 334 void push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci);
duke@0 335 void pop_scope();
duke@0 336 void pop_scope_for_jsr();
duke@0 337
duke@0 338 bool append_unsafe_get_obj(ciMethod* callee, BasicType t, bool is_volatile);
duke@0 339 bool append_unsafe_put_obj(ciMethod* callee, BasicType t, bool is_volatile);
duke@0 340 bool append_unsafe_get_raw(ciMethod* callee, BasicType t);
duke@0 341 bool append_unsafe_put_raw(ciMethod* callee, BasicType t);
duke@0 342 bool append_unsafe_prefetch(ciMethod* callee, bool is_store, bool is_static);
duke@0 343 void append_unsafe_CAS(ciMethod* callee);
duke@0 344
duke@0 345 NOT_PRODUCT(void print_inline_result(ciMethod* callee, bool res);)
duke@0 346
duke@0 347 // methodDataOop profiling helpers
duke@0 348 void profile_call(Value recv, ciKlass* predicted_holder);
duke@0 349 void profile_invocation(ciMethod* method);
duke@0 350 void profile_bci(int bci);
duke@0 351
duke@0 352 // Helpers for generation of profile information
duke@0 353 bool profile_branches() {
duke@0 354 return _compilation->env()->comp_level() == CompLevel_fast_compile &&
duke@0 355 Tier1UpdateMethodData && Tier1ProfileBranches;
duke@0 356 }
duke@0 357 bool profile_calls() {
duke@0 358 return _compilation->env()->comp_level() == CompLevel_fast_compile &&
duke@0 359 Tier1UpdateMethodData && Tier1ProfileCalls;
duke@0 360 }
duke@0 361 bool profile_inlined_calls() {
duke@0 362 return profile_calls() && Tier1ProfileInlinedCalls;
duke@0 363 }
duke@0 364 bool profile_checkcasts() {
duke@0 365 return _compilation->env()->comp_level() == CompLevel_fast_compile &&
duke@0 366 Tier1UpdateMethodData && Tier1ProfileCheckcasts;
duke@0 367 }
duke@0 368
duke@0 369 public:
duke@0 370 NOT_PRODUCT(void print_stats();)
duke@0 371
duke@0 372 // initialization
duke@0 373 static void initialize();
duke@0 374
duke@0 375 // public
duke@0 376 static bool can_trap(ciMethod* method, Bytecodes::Code code) {
duke@0 377 assert(0 <= code && code < Bytecodes::number_of_java_codes, "illegal bytecode");
duke@0 378 if (_can_trap[code]) return true;
duke@0 379 // special handling for finalizer registration
duke@0 380 return code == Bytecodes::_return && method->intrinsic_id() == vmIntrinsics::_Object_init;
duke@0 381 }
duke@0 382
duke@0 383 // creation
duke@0 384 GraphBuilder(Compilation* compilation, IRScope* scope);
duke@0 385 static void sort_top_into_worklist(BlockList* worklist, BlockBegin* top);
duke@0 386
duke@0 387 BlockBegin* start() const { return _start; }
duke@0 388 };