src/share/vm/c1/c1_GraphBuilder.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6747
ee1c924763d2
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
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 #include "precompiled.hpp"
aoqi@0 26 #include "c1/c1_CFGPrinter.hpp"
aoqi@0 27 #include "c1/c1_Canonicalizer.hpp"
aoqi@0 28 #include "c1/c1_Compilation.hpp"
aoqi@0 29 #include "c1/c1_GraphBuilder.hpp"
aoqi@0 30 #include "c1/c1_InstructionPrinter.hpp"
aoqi@0 31 #include "ci/ciCallSite.hpp"
aoqi@0 32 #include "ci/ciField.hpp"
aoqi@0 33 #include "ci/ciKlass.hpp"
aoqi@0 34 #include "ci/ciMemberName.hpp"
aoqi@0 35 #include "compiler/compileBroker.hpp"
aoqi@0 36 #include "interpreter/bytecode.hpp"
aoqi@0 37 #include "runtime/sharedRuntime.hpp"
aoqi@0 38 #include "runtime/compilationPolicy.hpp"
aoqi@0 39 #include "utilities/bitMap.inline.hpp"
aoqi@0 40
aoqi@0 41 class BlockListBuilder VALUE_OBJ_CLASS_SPEC {
aoqi@0 42 private:
aoqi@0 43 Compilation* _compilation;
aoqi@0 44 IRScope* _scope;
aoqi@0 45
aoqi@0 46 BlockList _blocks; // internal list of all blocks
aoqi@0 47 BlockList* _bci2block; // mapping from bci to blocks for GraphBuilder
aoqi@0 48
aoqi@0 49 // fields used by mark_loops
aoqi@0 50 BitMap _active; // for iteration of control flow graph
aoqi@0 51 BitMap _visited; // for iteration of control flow graph
aoqi@0 52 intArray _loop_map; // caches the information if a block is contained in a loop
aoqi@0 53 int _next_loop_index; // next free loop number
aoqi@0 54 int _next_block_number; // for reverse postorder numbering of blocks
aoqi@0 55
aoqi@0 56 // accessors
aoqi@0 57 Compilation* compilation() const { return _compilation; }
aoqi@0 58 IRScope* scope() const { return _scope; }
aoqi@0 59 ciMethod* method() const { return scope()->method(); }
aoqi@0 60 XHandlers* xhandlers() const { return scope()->xhandlers(); }
aoqi@0 61
aoqi@0 62 // unified bailout support
aoqi@0 63 void bailout(const char* msg) const { compilation()->bailout(msg); }
aoqi@0 64 bool bailed_out() const { return compilation()->bailed_out(); }
aoqi@0 65
aoqi@0 66 // helper functions
aoqi@0 67 BlockBegin* make_block_at(int bci, BlockBegin* predecessor);
aoqi@0 68 void handle_exceptions(BlockBegin* current, int cur_bci);
aoqi@0 69 void handle_jsr(BlockBegin* current, int sr_bci, int next_bci);
aoqi@0 70 void store_one(BlockBegin* current, int local);
aoqi@0 71 void store_two(BlockBegin* current, int local);
aoqi@0 72 void set_entries(int osr_bci);
aoqi@0 73 void set_leaders();
aoqi@0 74
aoqi@0 75 void make_loop_header(BlockBegin* block);
aoqi@0 76 void mark_loops();
aoqi@0 77 int mark_loops(BlockBegin* b, bool in_subroutine);
aoqi@0 78
aoqi@0 79 // debugging
aoqi@0 80 #ifndef PRODUCT
aoqi@0 81 void print();
aoqi@0 82 #endif
aoqi@0 83
aoqi@0 84 public:
aoqi@0 85 // creation
aoqi@0 86 BlockListBuilder(Compilation* compilation, IRScope* scope, int osr_bci);
aoqi@0 87
aoqi@0 88 // accessors for GraphBuilder
aoqi@0 89 BlockList* bci2block() const { return _bci2block; }
aoqi@0 90 };
aoqi@0 91
aoqi@0 92
aoqi@0 93 // Implementation of BlockListBuilder
aoqi@0 94
aoqi@0 95 BlockListBuilder::BlockListBuilder(Compilation* compilation, IRScope* scope, int osr_bci)
aoqi@0 96 : _compilation(compilation)
aoqi@0 97 , _scope(scope)
aoqi@0 98 , _blocks(16)
aoqi@0 99 , _bci2block(new BlockList(scope->method()->code_size(), NULL))
aoqi@0 100 , _next_block_number(0)
aoqi@0 101 , _active() // size not known yet
aoqi@0 102 , _visited() // size not known yet
aoqi@0 103 , _next_loop_index(0)
aoqi@0 104 , _loop_map() // size not known yet
aoqi@0 105 {
aoqi@0 106 set_entries(osr_bci);
aoqi@0 107 set_leaders();
aoqi@0 108 CHECK_BAILOUT();
aoqi@0 109
aoqi@0 110 mark_loops();
aoqi@0 111 NOT_PRODUCT(if (PrintInitialBlockList) print());
aoqi@0 112
aoqi@0 113 #ifndef PRODUCT
aoqi@0 114 if (PrintCFGToFile) {
aoqi@0 115 stringStream title;
aoqi@0 116 title.print("BlockListBuilder ");
aoqi@0 117 scope->method()->print_name(&title);
aoqi@0 118 CFGPrinter::print_cfg(_bci2block, title.as_string(), false, false);
aoqi@0 119 }
aoqi@0 120 #endif
aoqi@0 121 }
aoqi@0 122
aoqi@0 123
aoqi@0 124 void BlockListBuilder::set_entries(int osr_bci) {
aoqi@0 125 // generate start blocks
aoqi@0 126 BlockBegin* std_entry = make_block_at(0, NULL);
aoqi@0 127 if (scope()->caller() == NULL) {
aoqi@0 128 std_entry->set(BlockBegin::std_entry_flag);
aoqi@0 129 }
aoqi@0 130 if (osr_bci != -1) {
aoqi@0 131 BlockBegin* osr_entry = make_block_at(osr_bci, NULL);
aoqi@0 132 osr_entry->set(BlockBegin::osr_entry_flag);
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 // generate exception entry blocks
aoqi@0 136 XHandlers* list = xhandlers();
aoqi@0 137 const int n = list->length();
aoqi@0 138 for (int i = 0; i < n; i++) {
aoqi@0 139 XHandler* h = list->handler_at(i);
aoqi@0 140 BlockBegin* entry = make_block_at(h->handler_bci(), NULL);
aoqi@0 141 entry->set(BlockBegin::exception_entry_flag);
aoqi@0 142 h->set_entry_block(entry);
aoqi@0 143 }
aoqi@0 144 }
aoqi@0 145
aoqi@0 146
aoqi@0 147 BlockBegin* BlockListBuilder::make_block_at(int cur_bci, BlockBegin* predecessor) {
aoqi@0 148 assert(method()->bci_block_start().at(cur_bci), "wrong block starts of MethodLivenessAnalyzer");
aoqi@0 149
aoqi@0 150 BlockBegin* block = _bci2block->at(cur_bci);
aoqi@0 151 if (block == NULL) {
aoqi@0 152 block = new BlockBegin(cur_bci);
aoqi@0 153 block->init_stores_to_locals(method()->max_locals());
aoqi@0 154 _bci2block->at_put(cur_bci, block);
aoqi@0 155 _blocks.append(block);
aoqi@0 156
aoqi@0 157 assert(predecessor == NULL || predecessor->bci() < cur_bci, "targets for backward branches must already exist");
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 if (predecessor != NULL) {
aoqi@0 161 if (block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 162 BAILOUT_("Exception handler can be reached by both normal and exceptional control flow", block);
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 predecessor->add_successor(block);
aoqi@0 166 block->increment_total_preds();
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 return block;
aoqi@0 170 }
aoqi@0 171
aoqi@0 172
aoqi@0 173 inline void BlockListBuilder::store_one(BlockBegin* current, int local) {
aoqi@0 174 current->stores_to_locals().set_bit(local);
aoqi@0 175 }
aoqi@0 176 inline void BlockListBuilder::store_two(BlockBegin* current, int local) {
aoqi@0 177 store_one(current, local);
aoqi@0 178 store_one(current, local + 1);
aoqi@0 179 }
aoqi@0 180
aoqi@0 181
aoqi@0 182 void BlockListBuilder::handle_exceptions(BlockBegin* current, int cur_bci) {
aoqi@0 183 // Draws edges from a block to its exception handlers
aoqi@0 184 XHandlers* list = xhandlers();
aoqi@0 185 const int n = list->length();
aoqi@0 186
aoqi@0 187 for (int i = 0; i < n; i++) {
aoqi@0 188 XHandler* h = list->handler_at(i);
aoqi@0 189
aoqi@0 190 if (h->covers(cur_bci)) {
aoqi@0 191 BlockBegin* entry = h->entry_block();
aoqi@0 192 assert(entry != NULL && entry == _bci2block->at(h->handler_bci()), "entry must be set");
aoqi@0 193 assert(entry->is_set(BlockBegin::exception_entry_flag), "flag must be set");
aoqi@0 194
aoqi@0 195 // add each exception handler only once
aoqi@0 196 if (!current->is_successor(entry)) {
aoqi@0 197 current->add_successor(entry);
aoqi@0 198 entry->increment_total_preds();
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 // stop when reaching catchall
aoqi@0 202 if (h->catch_type() == 0) break;
aoqi@0 203 }
aoqi@0 204 }
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 void BlockListBuilder::handle_jsr(BlockBegin* current, int sr_bci, int next_bci) {
aoqi@0 208 // start a new block after jsr-bytecode and link this block into cfg
aoqi@0 209 make_block_at(next_bci, current);
aoqi@0 210
aoqi@0 211 // start a new block at the subroutine entry at mark it with special flag
aoqi@0 212 BlockBegin* sr_block = make_block_at(sr_bci, current);
aoqi@0 213 if (!sr_block->is_set(BlockBegin::subroutine_entry_flag)) {
aoqi@0 214 sr_block->set(BlockBegin::subroutine_entry_flag);
aoqi@0 215 }
aoqi@0 216 }
aoqi@0 217
aoqi@0 218
aoqi@0 219 void BlockListBuilder::set_leaders() {
aoqi@0 220 bool has_xhandlers = xhandlers()->has_handlers();
aoqi@0 221 BlockBegin* current = NULL;
aoqi@0 222
aoqi@0 223 // The information which bci starts a new block simplifies the analysis
aoqi@0 224 // Without it, backward branches could jump to a bci where no block was created
aoqi@0 225 // during bytecode iteration. This would require the creation of a new block at the
aoqi@0 226 // branch target and a modification of the successor lists.
aoqi@0 227 BitMap bci_block_start = method()->bci_block_start();
aoqi@0 228
aoqi@0 229 ciBytecodeStream s(method());
aoqi@0 230 while (s.next() != ciBytecodeStream::EOBC()) {
aoqi@0 231 int cur_bci = s.cur_bci();
aoqi@0 232
aoqi@0 233 if (bci_block_start.at(cur_bci)) {
aoqi@0 234 current = make_block_at(cur_bci, current);
aoqi@0 235 }
aoqi@0 236 assert(current != NULL, "must have current block");
aoqi@0 237
aoqi@0 238 if (has_xhandlers && GraphBuilder::can_trap(method(), s.cur_bc())) {
aoqi@0 239 handle_exceptions(current, cur_bci);
aoqi@0 240 }
aoqi@0 241
aoqi@0 242 switch (s.cur_bc()) {
aoqi@0 243 // track stores to local variables for selective creation of phi functions
aoqi@0 244 case Bytecodes::_iinc: store_one(current, s.get_index()); break;
aoqi@0 245 case Bytecodes::_istore: store_one(current, s.get_index()); break;
aoqi@0 246 case Bytecodes::_lstore: store_two(current, s.get_index()); break;
aoqi@0 247 case Bytecodes::_fstore: store_one(current, s.get_index()); break;
aoqi@0 248 case Bytecodes::_dstore: store_two(current, s.get_index()); break;
aoqi@0 249 case Bytecodes::_astore: store_one(current, s.get_index()); break;
aoqi@0 250 case Bytecodes::_istore_0: store_one(current, 0); break;
aoqi@0 251 case Bytecodes::_istore_1: store_one(current, 1); break;
aoqi@0 252 case Bytecodes::_istore_2: store_one(current, 2); break;
aoqi@0 253 case Bytecodes::_istore_3: store_one(current, 3); break;
aoqi@0 254 case Bytecodes::_lstore_0: store_two(current, 0); break;
aoqi@0 255 case Bytecodes::_lstore_1: store_two(current, 1); break;
aoqi@0 256 case Bytecodes::_lstore_2: store_two(current, 2); break;
aoqi@0 257 case Bytecodes::_lstore_3: store_two(current, 3); break;
aoqi@0 258 case Bytecodes::_fstore_0: store_one(current, 0); break;
aoqi@0 259 case Bytecodes::_fstore_1: store_one(current, 1); break;
aoqi@0 260 case Bytecodes::_fstore_2: store_one(current, 2); break;
aoqi@0 261 case Bytecodes::_fstore_3: store_one(current, 3); break;
aoqi@0 262 case Bytecodes::_dstore_0: store_two(current, 0); break;
aoqi@0 263 case Bytecodes::_dstore_1: store_two(current, 1); break;
aoqi@0 264 case Bytecodes::_dstore_2: store_two(current, 2); break;
aoqi@0 265 case Bytecodes::_dstore_3: store_two(current, 3); break;
aoqi@0 266 case Bytecodes::_astore_0: store_one(current, 0); break;
aoqi@0 267 case Bytecodes::_astore_1: store_one(current, 1); break;
aoqi@0 268 case Bytecodes::_astore_2: store_one(current, 2); break;
aoqi@0 269 case Bytecodes::_astore_3: store_one(current, 3); break;
aoqi@0 270
aoqi@0 271 // track bytecodes that affect the control flow
aoqi@0 272 case Bytecodes::_athrow: // fall through
aoqi@0 273 case Bytecodes::_ret: // fall through
aoqi@0 274 case Bytecodes::_ireturn: // fall through
aoqi@0 275 case Bytecodes::_lreturn: // fall through
aoqi@0 276 case Bytecodes::_freturn: // fall through
aoqi@0 277 case Bytecodes::_dreturn: // fall through
aoqi@0 278 case Bytecodes::_areturn: // fall through
aoqi@0 279 case Bytecodes::_return:
aoqi@0 280 current = NULL;
aoqi@0 281 break;
aoqi@0 282
aoqi@0 283 case Bytecodes::_ifeq: // fall through
aoqi@0 284 case Bytecodes::_ifne: // fall through
aoqi@0 285 case Bytecodes::_iflt: // fall through
aoqi@0 286 case Bytecodes::_ifge: // fall through
aoqi@0 287 case Bytecodes::_ifgt: // fall through
aoqi@0 288 case Bytecodes::_ifle: // fall through
aoqi@0 289 case Bytecodes::_if_icmpeq: // fall through
aoqi@0 290 case Bytecodes::_if_icmpne: // fall through
aoqi@0 291 case Bytecodes::_if_icmplt: // fall through
aoqi@0 292 case Bytecodes::_if_icmpge: // fall through
aoqi@0 293 case Bytecodes::_if_icmpgt: // fall through
aoqi@0 294 case Bytecodes::_if_icmple: // fall through
aoqi@0 295 case Bytecodes::_if_acmpeq: // fall through
aoqi@0 296 case Bytecodes::_if_acmpne: // fall through
aoqi@0 297 case Bytecodes::_ifnull: // fall through
aoqi@0 298 case Bytecodes::_ifnonnull:
aoqi@0 299 make_block_at(s.next_bci(), current);
aoqi@0 300 make_block_at(s.get_dest(), current);
aoqi@0 301 current = NULL;
aoqi@0 302 break;
aoqi@0 303
aoqi@0 304 case Bytecodes::_goto:
aoqi@0 305 make_block_at(s.get_dest(), current);
aoqi@0 306 current = NULL;
aoqi@0 307 break;
aoqi@0 308
aoqi@0 309 case Bytecodes::_goto_w:
aoqi@0 310 make_block_at(s.get_far_dest(), current);
aoqi@0 311 current = NULL;
aoqi@0 312 break;
aoqi@0 313
aoqi@0 314 case Bytecodes::_jsr:
aoqi@0 315 handle_jsr(current, s.get_dest(), s.next_bci());
aoqi@0 316 current = NULL;
aoqi@0 317 break;
aoqi@0 318
aoqi@0 319 case Bytecodes::_jsr_w:
aoqi@0 320 handle_jsr(current, s.get_far_dest(), s.next_bci());
aoqi@0 321 current = NULL;
aoqi@0 322 break;
aoqi@0 323
aoqi@0 324 case Bytecodes::_tableswitch: {
aoqi@0 325 // set block for each case
aoqi@0 326 Bytecode_tableswitch sw(&s);
aoqi@0 327 int l = sw.length();
aoqi@0 328 for (int i = 0; i < l; i++) {
aoqi@0 329 make_block_at(cur_bci + sw.dest_offset_at(i), current);
aoqi@0 330 }
aoqi@0 331 make_block_at(cur_bci + sw.default_offset(), current);
aoqi@0 332 current = NULL;
aoqi@0 333 break;
aoqi@0 334 }
aoqi@0 335
aoqi@0 336 case Bytecodes::_lookupswitch: {
aoqi@0 337 // set block for each case
aoqi@0 338 Bytecode_lookupswitch sw(&s);
aoqi@0 339 int l = sw.number_of_pairs();
aoqi@0 340 for (int i = 0; i < l; i++) {
aoqi@0 341 make_block_at(cur_bci + sw.pair_at(i).offset(), current);
aoqi@0 342 }
aoqi@0 343 make_block_at(cur_bci + sw.default_offset(), current);
aoqi@0 344 current = NULL;
aoqi@0 345 break;
aoqi@0 346 }
aoqi@0 347 }
aoqi@0 348 }
aoqi@0 349 }
aoqi@0 350
aoqi@0 351
aoqi@0 352 void BlockListBuilder::mark_loops() {
aoqi@0 353 ResourceMark rm;
aoqi@0 354
aoqi@0 355 _active = BitMap(BlockBegin::number_of_blocks()); _active.clear();
aoqi@0 356 _visited = BitMap(BlockBegin::number_of_blocks()); _visited.clear();
aoqi@0 357 _loop_map = intArray(BlockBegin::number_of_blocks(), 0);
aoqi@0 358 _next_loop_index = 0;
aoqi@0 359 _next_block_number = _blocks.length();
aoqi@0 360
aoqi@0 361 // recursively iterate the control flow graph
aoqi@0 362 mark_loops(_bci2block->at(0), false);
aoqi@0 363 assert(_next_block_number >= 0, "invalid block numbers");
aoqi@0 364 }
aoqi@0 365
aoqi@0 366 void BlockListBuilder::make_loop_header(BlockBegin* block) {
aoqi@0 367 if (block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 368 // exception edges may look like loops but don't mark them as such
aoqi@0 369 // since it screws up block ordering.
aoqi@0 370 return;
aoqi@0 371 }
aoqi@0 372 if (!block->is_set(BlockBegin::parser_loop_header_flag)) {
aoqi@0 373 block->set(BlockBegin::parser_loop_header_flag);
aoqi@0 374
aoqi@0 375 assert(_loop_map.at(block->block_id()) == 0, "must not be set yet");
aoqi@0 376 assert(0 <= _next_loop_index && _next_loop_index < BitsPerInt, "_next_loop_index is used as a bit-index in integer");
aoqi@0 377 _loop_map.at_put(block->block_id(), 1 << _next_loop_index);
aoqi@0 378 if (_next_loop_index < 31) _next_loop_index++;
aoqi@0 379 } else {
aoqi@0 380 // block already marked as loop header
aoqi@0 381 assert(is_power_of_2((unsigned int)_loop_map.at(block->block_id())), "exactly one bit must be set");
aoqi@0 382 }
aoqi@0 383 }
aoqi@0 384
aoqi@0 385 int BlockListBuilder::mark_loops(BlockBegin* block, bool in_subroutine) {
aoqi@0 386 int block_id = block->block_id();
aoqi@0 387
aoqi@0 388 if (_visited.at(block_id)) {
aoqi@0 389 if (_active.at(block_id)) {
aoqi@0 390 // reached block via backward branch
aoqi@0 391 make_loop_header(block);
aoqi@0 392 }
aoqi@0 393 // return cached loop information for this block
aoqi@0 394 return _loop_map.at(block_id);
aoqi@0 395 }
aoqi@0 396
aoqi@0 397 if (block->is_set(BlockBegin::subroutine_entry_flag)) {
aoqi@0 398 in_subroutine = true;
aoqi@0 399 }
aoqi@0 400
aoqi@0 401 // set active and visited bits before successors are processed
aoqi@0 402 _visited.set_bit(block_id);
aoqi@0 403 _active.set_bit(block_id);
aoqi@0 404
aoqi@0 405 intptr_t loop_state = 0;
aoqi@0 406 for (int i = block->number_of_sux() - 1; i >= 0; i--) {
aoqi@0 407 // recursively process all successors
aoqi@0 408 loop_state |= mark_loops(block->sux_at(i), in_subroutine);
aoqi@0 409 }
aoqi@0 410
aoqi@0 411 // clear active-bit after all successors are processed
aoqi@0 412 _active.clear_bit(block_id);
aoqi@0 413
aoqi@0 414 // reverse-post-order numbering of all blocks
aoqi@0 415 block->set_depth_first_number(_next_block_number);
aoqi@0 416 _next_block_number--;
aoqi@0 417
aoqi@0 418 if (loop_state != 0 || in_subroutine ) {
aoqi@0 419 // block is contained at least in one loop, so phi functions are necessary
aoqi@0 420 // phi functions are also necessary for all locals stored in a subroutine
aoqi@0 421 scope()->requires_phi_function().set_union(block->stores_to_locals());
aoqi@0 422 }
aoqi@0 423
aoqi@0 424 if (block->is_set(BlockBegin::parser_loop_header_flag)) {
aoqi@0 425 int header_loop_state = _loop_map.at(block_id);
aoqi@0 426 assert(is_power_of_2((unsigned)header_loop_state), "exactly one bit must be set");
aoqi@0 427
aoqi@0 428 // If the highest bit is set (i.e. when integer value is negative), the method
aoqi@0 429 // has 32 or more loops. This bit is never cleared because it is used for multiple loops
aoqi@0 430 if (header_loop_state >= 0) {
aoqi@0 431 clear_bits(loop_state, header_loop_state);
aoqi@0 432 }
aoqi@0 433 }
aoqi@0 434
aoqi@0 435 // cache and return loop information for this block
aoqi@0 436 _loop_map.at_put(block_id, loop_state);
aoqi@0 437 return loop_state;
aoqi@0 438 }
aoqi@0 439
aoqi@0 440
aoqi@0 441 #ifndef PRODUCT
aoqi@0 442
aoqi@0 443 int compare_depth_first(BlockBegin** a, BlockBegin** b) {
aoqi@0 444 return (*a)->depth_first_number() - (*b)->depth_first_number();
aoqi@0 445 }
aoqi@0 446
aoqi@0 447 void BlockListBuilder::print() {
aoqi@0 448 tty->print("----- initial block list of BlockListBuilder for method ");
aoqi@0 449 method()->print_short_name();
aoqi@0 450 tty->cr();
aoqi@0 451
aoqi@0 452 // better readability if blocks are sorted in processing order
aoqi@0 453 _blocks.sort(compare_depth_first);
aoqi@0 454
aoqi@0 455 for (int i = 0; i < _blocks.length(); i++) {
aoqi@0 456 BlockBegin* cur = _blocks.at(i);
aoqi@0 457 tty->print("%4d: B%-4d bci: %-4d preds: %-4d ", cur->depth_first_number(), cur->block_id(), cur->bci(), cur->total_preds());
aoqi@0 458
aoqi@0 459 tty->print(cur->is_set(BlockBegin::std_entry_flag) ? " std" : " ");
aoqi@0 460 tty->print(cur->is_set(BlockBegin::osr_entry_flag) ? " osr" : " ");
aoqi@0 461 tty->print(cur->is_set(BlockBegin::exception_entry_flag) ? " ex" : " ");
aoqi@0 462 tty->print(cur->is_set(BlockBegin::subroutine_entry_flag) ? " sr" : " ");
aoqi@0 463 tty->print(cur->is_set(BlockBegin::parser_loop_header_flag) ? " lh" : " ");
aoqi@0 464
aoqi@0 465 if (cur->number_of_sux() > 0) {
aoqi@0 466 tty->print(" sux: ");
aoqi@0 467 for (int j = 0; j < cur->number_of_sux(); j++) {
aoqi@0 468 BlockBegin* sux = cur->sux_at(j);
aoqi@0 469 tty->print("B%d ", sux->block_id());
aoqi@0 470 }
aoqi@0 471 }
aoqi@0 472 tty->cr();
aoqi@0 473 }
aoqi@0 474 }
aoqi@0 475
aoqi@0 476 #endif
aoqi@0 477
aoqi@0 478
aoqi@0 479 // A simple growable array of Values indexed by ciFields
aoqi@0 480 class FieldBuffer: public CompilationResourceObj {
aoqi@0 481 private:
aoqi@0 482 GrowableArray<Value> _values;
aoqi@0 483
aoqi@0 484 public:
aoqi@0 485 FieldBuffer() {}
aoqi@0 486
aoqi@0 487 void kill() {
aoqi@0 488 _values.trunc_to(0);
aoqi@0 489 }
aoqi@0 490
aoqi@0 491 Value at(ciField* field) {
aoqi@0 492 assert(field->holder()->is_loaded(), "must be a loaded field");
aoqi@0 493 int offset = field->offset();
aoqi@0 494 if (offset < _values.length()) {
aoqi@0 495 return _values.at(offset);
aoqi@0 496 } else {
aoqi@0 497 return NULL;
aoqi@0 498 }
aoqi@0 499 }
aoqi@0 500
aoqi@0 501 void at_put(ciField* field, Value value) {
aoqi@0 502 assert(field->holder()->is_loaded(), "must be a loaded field");
aoqi@0 503 int offset = field->offset();
aoqi@0 504 _values.at_put_grow(offset, value, NULL);
aoqi@0 505 }
aoqi@0 506
aoqi@0 507 };
aoqi@0 508
aoqi@0 509
aoqi@0 510 // MemoryBuffer is fairly simple model of the current state of memory.
aoqi@0 511 // It partitions memory into several pieces. The first piece is
aoqi@0 512 // generic memory where little is known about the owner of the memory.
aoqi@0 513 // This is conceptually represented by the tuple <O, F, V> which says
aoqi@0 514 // that the field F of object O has value V. This is flattened so
aoqi@0 515 // that F is represented by the offset of the field and the parallel
aoqi@0 516 // arrays _objects and _values are used for O and V. Loads of O.F can
aoqi@0 517 // simply use V. Newly allocated objects are kept in a separate list
aoqi@0 518 // along with a parallel array for each object which represents the
aoqi@0 519 // current value of its fields. Stores of the default value to fields
aoqi@0 520 // which have never been stored to before are eliminated since they
aoqi@0 521 // are redundant. Once newly allocated objects are stored into
aoqi@0 522 // another object or they are passed out of the current compile they
aoqi@0 523 // are treated like generic memory.
aoqi@0 524
aoqi@0 525 class MemoryBuffer: public CompilationResourceObj {
aoqi@0 526 private:
aoqi@0 527 FieldBuffer _values;
aoqi@0 528 GrowableArray<Value> _objects;
aoqi@0 529 GrowableArray<Value> _newobjects;
aoqi@0 530 GrowableArray<FieldBuffer*> _fields;
aoqi@0 531
aoqi@0 532 public:
aoqi@0 533 MemoryBuffer() {}
aoqi@0 534
aoqi@0 535 StoreField* store(StoreField* st) {
aoqi@0 536 if (!EliminateFieldAccess) {
aoqi@0 537 return st;
aoqi@0 538 }
aoqi@0 539
aoqi@0 540 Value object = st->obj();
aoqi@0 541 Value value = st->value();
aoqi@0 542 ciField* field = st->field();
aoqi@0 543 if (field->holder()->is_loaded()) {
aoqi@0 544 int offset = field->offset();
aoqi@0 545 int index = _newobjects.find(object);
aoqi@0 546 if (index != -1) {
aoqi@0 547 // newly allocated object with no other stores performed on this field
aoqi@0 548 FieldBuffer* buf = _fields.at(index);
aoqi@0 549 if (buf->at(field) == NULL && is_default_value(value)) {
aoqi@0 550 #ifndef PRODUCT
aoqi@0 551 if (PrintIRDuringConstruction && Verbose) {
aoqi@0 552 tty->print_cr("Eliminated store for object %d:", index);
aoqi@0 553 st->print_line();
aoqi@0 554 }
aoqi@0 555 #endif
aoqi@0 556 return NULL;
aoqi@0 557 } else {
aoqi@0 558 buf->at_put(field, value);
aoqi@0 559 }
aoqi@0 560 } else {
aoqi@0 561 _objects.at_put_grow(offset, object, NULL);
aoqi@0 562 _values.at_put(field, value);
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 store_value(value);
aoqi@0 566 } else {
aoqi@0 567 // if we held onto field names we could alias based on names but
aoqi@0 568 // we don't know what's being stored to so kill it all.
aoqi@0 569 kill();
aoqi@0 570 }
aoqi@0 571 return st;
aoqi@0 572 }
aoqi@0 573
aoqi@0 574
aoqi@0 575 // return true if this value correspond to the default value of a field.
aoqi@0 576 bool is_default_value(Value value) {
aoqi@0 577 Constant* con = value->as_Constant();
aoqi@0 578 if (con) {
aoqi@0 579 switch (con->type()->tag()) {
aoqi@0 580 case intTag: return con->type()->as_IntConstant()->value() == 0;
aoqi@0 581 case longTag: return con->type()->as_LongConstant()->value() == 0;
aoqi@0 582 case floatTag: return jint_cast(con->type()->as_FloatConstant()->value()) == 0;
aoqi@0 583 case doubleTag: return jlong_cast(con->type()->as_DoubleConstant()->value()) == jlong_cast(0);
aoqi@0 584 case objectTag: return con->type() == objectNull;
aoqi@0 585 default: ShouldNotReachHere();
aoqi@0 586 }
aoqi@0 587 }
aoqi@0 588 return false;
aoqi@0 589 }
aoqi@0 590
aoqi@0 591
aoqi@0 592 // return either the actual value of a load or the load itself
aoqi@0 593 Value load(LoadField* load) {
aoqi@0 594 if (!EliminateFieldAccess) {
aoqi@0 595 return load;
aoqi@0 596 }
aoqi@0 597
aoqi@0 598 if (RoundFPResults && UseSSE < 2 && load->type()->is_float_kind()) {
aoqi@0 599 // can't skip load since value might get rounded as a side effect
aoqi@0 600 return load;
aoqi@0 601 }
aoqi@0 602
aoqi@0 603 ciField* field = load->field();
aoqi@0 604 Value object = load->obj();
aoqi@0 605 if (field->holder()->is_loaded() && !field->is_volatile()) {
aoqi@0 606 int offset = field->offset();
aoqi@0 607 Value result = NULL;
aoqi@0 608 int index = _newobjects.find(object);
aoqi@0 609 if (index != -1) {
aoqi@0 610 result = _fields.at(index)->at(field);
aoqi@0 611 } else if (_objects.at_grow(offset, NULL) == object) {
aoqi@0 612 result = _values.at(field);
aoqi@0 613 }
aoqi@0 614 if (result != NULL) {
aoqi@0 615 #ifndef PRODUCT
aoqi@0 616 if (PrintIRDuringConstruction && Verbose) {
aoqi@0 617 tty->print_cr("Eliminated load: ");
aoqi@0 618 load->print_line();
aoqi@0 619 }
aoqi@0 620 #endif
aoqi@0 621 assert(result->type()->tag() == load->type()->tag(), "wrong types");
aoqi@0 622 return result;
aoqi@0 623 }
aoqi@0 624 }
aoqi@0 625 return load;
aoqi@0 626 }
aoqi@0 627
aoqi@0 628 // Record this newly allocated object
aoqi@0 629 void new_instance(NewInstance* object) {
aoqi@0 630 int index = _newobjects.length();
aoqi@0 631 _newobjects.append(object);
aoqi@0 632 if (_fields.at_grow(index, NULL) == NULL) {
aoqi@0 633 _fields.at_put(index, new FieldBuffer());
aoqi@0 634 } else {
aoqi@0 635 _fields.at(index)->kill();
aoqi@0 636 }
aoqi@0 637 }
aoqi@0 638
aoqi@0 639 void store_value(Value value) {
aoqi@0 640 int index = _newobjects.find(value);
aoqi@0 641 if (index != -1) {
aoqi@0 642 // stored a newly allocated object into another object.
aoqi@0 643 // Assume we've lost track of it as separate slice of memory.
aoqi@0 644 // We could do better by keeping track of whether individual
aoqi@0 645 // fields could alias each other.
aoqi@0 646 _newobjects.remove_at(index);
aoqi@0 647 // pull out the field info and store it at the end up the list
aoqi@0 648 // of field info list to be reused later.
aoqi@0 649 _fields.append(_fields.at(index));
aoqi@0 650 _fields.remove_at(index);
aoqi@0 651 }
aoqi@0 652 }
aoqi@0 653
aoqi@0 654 void kill() {
aoqi@0 655 _newobjects.trunc_to(0);
aoqi@0 656 _objects.trunc_to(0);
aoqi@0 657 _values.kill();
aoqi@0 658 }
aoqi@0 659 };
aoqi@0 660
aoqi@0 661
aoqi@0 662 // Implementation of GraphBuilder's ScopeData
aoqi@0 663
aoqi@0 664 GraphBuilder::ScopeData::ScopeData(ScopeData* parent)
aoqi@0 665 : _parent(parent)
aoqi@0 666 , _bci2block(NULL)
aoqi@0 667 , _scope(NULL)
aoqi@0 668 , _has_handler(false)
aoqi@0 669 , _stream(NULL)
aoqi@0 670 , _work_list(NULL)
aoqi@0 671 , _parsing_jsr(false)
aoqi@0 672 , _jsr_xhandlers(NULL)
aoqi@0 673 , _caller_stack_size(-1)
aoqi@0 674 , _continuation(NULL)
aoqi@0 675 , _num_returns(0)
aoqi@0 676 , _cleanup_block(NULL)
aoqi@0 677 , _cleanup_return_prev(NULL)
aoqi@0 678 , _cleanup_state(NULL)
aoqi@0 679 {
aoqi@0 680 if (parent != NULL) {
aoqi@0 681 _max_inline_size = (intx) ((float) NestedInliningSizeRatio * (float) parent->max_inline_size() / 100.0f);
aoqi@0 682 } else {
aoqi@0 683 _max_inline_size = MaxInlineSize;
aoqi@0 684 }
aoqi@0 685 if (_max_inline_size < MaxTrivialSize) {
aoqi@0 686 _max_inline_size = MaxTrivialSize;
aoqi@0 687 }
aoqi@0 688 }
aoqi@0 689
aoqi@0 690
aoqi@0 691 void GraphBuilder::kill_all() {
aoqi@0 692 if (UseLocalValueNumbering) {
aoqi@0 693 vmap()->kill_all();
aoqi@0 694 }
aoqi@0 695 _memory->kill();
aoqi@0 696 }
aoqi@0 697
aoqi@0 698
aoqi@0 699 BlockBegin* GraphBuilder::ScopeData::block_at(int bci) {
aoqi@0 700 if (parsing_jsr()) {
aoqi@0 701 // It is necessary to clone all blocks associated with a
aoqi@0 702 // subroutine, including those for exception handlers in the scope
aoqi@0 703 // of the method containing the jsr (because those exception
aoqi@0 704 // handlers may contain ret instructions in some cases).
aoqi@0 705 BlockBegin* block = bci2block()->at(bci);
aoqi@0 706 if (block != NULL && block == parent()->bci2block()->at(bci)) {
aoqi@0 707 BlockBegin* new_block = new BlockBegin(block->bci());
aoqi@0 708 #ifndef PRODUCT
aoqi@0 709 if (PrintInitialBlockList) {
aoqi@0 710 tty->print_cr("CFG: cloned block %d (bci %d) as block %d for jsr",
aoqi@0 711 block->block_id(), block->bci(), new_block->block_id());
aoqi@0 712 }
aoqi@0 713 #endif
aoqi@0 714 // copy data from cloned blocked
aoqi@0 715 new_block->set_depth_first_number(block->depth_first_number());
aoqi@0 716 if (block->is_set(BlockBegin::parser_loop_header_flag)) new_block->set(BlockBegin::parser_loop_header_flag);
aoqi@0 717 // Preserve certain flags for assertion checking
aoqi@0 718 if (block->is_set(BlockBegin::subroutine_entry_flag)) new_block->set(BlockBegin::subroutine_entry_flag);
aoqi@0 719 if (block->is_set(BlockBegin::exception_entry_flag)) new_block->set(BlockBegin::exception_entry_flag);
aoqi@0 720
aoqi@0 721 // copy was_visited_flag to allow early detection of bailouts
aoqi@0 722 // if a block that is used in a jsr has already been visited before,
aoqi@0 723 // it is shared between the normal control flow and a subroutine
aoqi@0 724 // BlockBegin::try_merge returns false when the flag is set, this leads
aoqi@0 725 // to a compilation bailout
aoqi@0 726 if (block->is_set(BlockBegin::was_visited_flag)) new_block->set(BlockBegin::was_visited_flag);
aoqi@0 727
aoqi@0 728 bci2block()->at_put(bci, new_block);
aoqi@0 729 block = new_block;
aoqi@0 730 }
aoqi@0 731 return block;
aoqi@0 732 } else {
aoqi@0 733 return bci2block()->at(bci);
aoqi@0 734 }
aoqi@0 735 }
aoqi@0 736
aoqi@0 737
aoqi@0 738 XHandlers* GraphBuilder::ScopeData::xhandlers() const {
aoqi@0 739 if (_jsr_xhandlers == NULL) {
aoqi@0 740 assert(!parsing_jsr(), "");
aoqi@0 741 return scope()->xhandlers();
aoqi@0 742 }
aoqi@0 743 assert(parsing_jsr(), "");
aoqi@0 744 return _jsr_xhandlers;
aoqi@0 745 }
aoqi@0 746
aoqi@0 747
aoqi@0 748 void GraphBuilder::ScopeData::set_scope(IRScope* scope) {
aoqi@0 749 _scope = scope;
aoqi@0 750 bool parent_has_handler = false;
aoqi@0 751 if (parent() != NULL) {
aoqi@0 752 parent_has_handler = parent()->has_handler();
aoqi@0 753 }
aoqi@0 754 _has_handler = parent_has_handler || scope->xhandlers()->has_handlers();
aoqi@0 755 }
aoqi@0 756
aoqi@0 757
aoqi@0 758 void GraphBuilder::ScopeData::set_inline_cleanup_info(BlockBegin* block,
aoqi@0 759 Instruction* return_prev,
aoqi@0 760 ValueStack* return_state) {
aoqi@0 761 _cleanup_block = block;
aoqi@0 762 _cleanup_return_prev = return_prev;
aoqi@0 763 _cleanup_state = return_state;
aoqi@0 764 }
aoqi@0 765
aoqi@0 766
aoqi@0 767 void GraphBuilder::ScopeData::add_to_work_list(BlockBegin* block) {
aoqi@0 768 if (_work_list == NULL) {
aoqi@0 769 _work_list = new BlockList();
aoqi@0 770 }
aoqi@0 771
aoqi@0 772 if (!block->is_set(BlockBegin::is_on_work_list_flag)) {
aoqi@0 773 // Do not start parsing the continuation block while in a
aoqi@0 774 // sub-scope
aoqi@0 775 if (parsing_jsr()) {
aoqi@0 776 if (block == jsr_continuation()) {
aoqi@0 777 return;
aoqi@0 778 }
aoqi@0 779 } else {
aoqi@0 780 if (block == continuation()) {
aoqi@0 781 return;
aoqi@0 782 }
aoqi@0 783 }
aoqi@0 784 block->set(BlockBegin::is_on_work_list_flag);
aoqi@0 785 _work_list->push(block);
aoqi@0 786
aoqi@0 787 sort_top_into_worklist(_work_list, block);
aoqi@0 788 }
aoqi@0 789 }
aoqi@0 790
aoqi@0 791
aoqi@0 792 void GraphBuilder::sort_top_into_worklist(BlockList* worklist, BlockBegin* top) {
aoqi@0 793 assert(worklist->top() == top, "");
aoqi@0 794 // sort block descending into work list
aoqi@0 795 const int dfn = top->depth_first_number();
aoqi@0 796 assert(dfn != -1, "unknown depth first number");
aoqi@0 797 int i = worklist->length()-2;
aoqi@0 798 while (i >= 0) {
aoqi@0 799 BlockBegin* b = worklist->at(i);
aoqi@0 800 if (b->depth_first_number() < dfn) {
aoqi@0 801 worklist->at_put(i+1, b);
aoqi@0 802 } else {
aoqi@0 803 break;
aoqi@0 804 }
aoqi@0 805 i --;
aoqi@0 806 }
aoqi@0 807 if (i >= -1) worklist->at_put(i + 1, top);
aoqi@0 808 }
aoqi@0 809
aoqi@0 810
aoqi@0 811 BlockBegin* GraphBuilder::ScopeData::remove_from_work_list() {
aoqi@0 812 if (is_work_list_empty()) {
aoqi@0 813 return NULL;
aoqi@0 814 }
aoqi@0 815 return _work_list->pop();
aoqi@0 816 }
aoqi@0 817
aoqi@0 818
aoqi@0 819 bool GraphBuilder::ScopeData::is_work_list_empty() const {
aoqi@0 820 return (_work_list == NULL || _work_list->length() == 0);
aoqi@0 821 }
aoqi@0 822
aoqi@0 823
aoqi@0 824 void GraphBuilder::ScopeData::setup_jsr_xhandlers() {
aoqi@0 825 assert(parsing_jsr(), "");
aoqi@0 826 // clone all the exception handlers from the scope
aoqi@0 827 XHandlers* handlers = new XHandlers(scope()->xhandlers());
aoqi@0 828 const int n = handlers->length();
aoqi@0 829 for (int i = 0; i < n; i++) {
aoqi@0 830 // The XHandlers need to be adjusted to dispatch to the cloned
aoqi@0 831 // handler block instead of the default one but the synthetic
aoqi@0 832 // unlocker needs to be handled specially. The synthetic unlocker
aoqi@0 833 // should be left alone since there can be only one and all code
aoqi@0 834 // should dispatch to the same one.
aoqi@0 835 XHandler* h = handlers->handler_at(i);
aoqi@0 836 assert(h->handler_bci() != SynchronizationEntryBCI, "must be real");
aoqi@0 837 h->set_entry_block(block_at(h->handler_bci()));
aoqi@0 838 }
aoqi@0 839 _jsr_xhandlers = handlers;
aoqi@0 840 }
aoqi@0 841
aoqi@0 842
aoqi@0 843 int GraphBuilder::ScopeData::num_returns() {
aoqi@0 844 if (parsing_jsr()) {
aoqi@0 845 return parent()->num_returns();
aoqi@0 846 }
aoqi@0 847 return _num_returns;
aoqi@0 848 }
aoqi@0 849
aoqi@0 850
aoqi@0 851 void GraphBuilder::ScopeData::incr_num_returns() {
aoqi@0 852 if (parsing_jsr()) {
aoqi@0 853 parent()->incr_num_returns();
aoqi@0 854 } else {
aoqi@0 855 ++_num_returns;
aoqi@0 856 }
aoqi@0 857 }
aoqi@0 858
aoqi@0 859
aoqi@0 860 // Implementation of GraphBuilder
aoqi@0 861
aoqi@0 862 #define INLINE_BAILOUT(msg) { inline_bailout(msg); return false; }
aoqi@0 863
aoqi@0 864
aoqi@0 865 void GraphBuilder::load_constant() {
aoqi@0 866 ciConstant con = stream()->get_constant();
aoqi@0 867 if (con.basic_type() == T_ILLEGAL) {
aoqi@0 868 BAILOUT("could not resolve a constant");
aoqi@0 869 } else {
aoqi@0 870 ValueType* t = illegalType;
aoqi@0 871 ValueStack* patch_state = NULL;
aoqi@0 872 switch (con.basic_type()) {
aoqi@0 873 case T_BOOLEAN: t = new IntConstant (con.as_boolean()); break;
aoqi@0 874 case T_BYTE : t = new IntConstant (con.as_byte ()); break;
aoqi@0 875 case T_CHAR : t = new IntConstant (con.as_char ()); break;
aoqi@0 876 case T_SHORT : t = new IntConstant (con.as_short ()); break;
aoqi@0 877 case T_INT : t = new IntConstant (con.as_int ()); break;
aoqi@0 878 case T_LONG : t = new LongConstant (con.as_long ()); break;
aoqi@0 879 case T_FLOAT : t = new FloatConstant (con.as_float ()); break;
aoqi@0 880 case T_DOUBLE : t = new DoubleConstant (con.as_double ()); break;
aoqi@0 881 case T_ARRAY : t = new ArrayConstant (con.as_object ()->as_array ()); break;
aoqi@0 882 case T_OBJECT :
aoqi@0 883 {
aoqi@0 884 ciObject* obj = con.as_object();
aoqi@0 885 if (!obj->is_loaded()
aoqi@0 886 || (PatchALot && obj->klass() != ciEnv::current()->String_klass())) {
aoqi@0 887 patch_state = copy_state_before();
aoqi@0 888 t = new ObjectConstant(obj);
aoqi@0 889 } else {
aoqi@0 890 assert(obj->is_instance(), "must be java_mirror of klass");
aoqi@0 891 t = new InstanceConstant(obj->as_instance());
aoqi@0 892 }
aoqi@0 893 break;
aoqi@0 894 }
aoqi@0 895 default : ShouldNotReachHere();
aoqi@0 896 }
aoqi@0 897 Value x;
aoqi@0 898 if (patch_state != NULL) {
aoqi@0 899 x = new Constant(t, patch_state);
aoqi@0 900 } else {
aoqi@0 901 x = new Constant(t);
aoqi@0 902 }
aoqi@0 903 push(t, append(x));
aoqi@0 904 }
aoqi@0 905 }
aoqi@0 906
aoqi@0 907
aoqi@0 908 void GraphBuilder::load_local(ValueType* type, int index) {
aoqi@0 909 Value x = state()->local_at(index);
aoqi@0 910 assert(x != NULL && !x->type()->is_illegal(), "access of illegal local variable");
aoqi@0 911 push(type, x);
aoqi@0 912 }
aoqi@0 913
aoqi@0 914
aoqi@0 915 void GraphBuilder::store_local(ValueType* type, int index) {
aoqi@0 916 Value x = pop(type);
aoqi@0 917 store_local(state(), x, index);
aoqi@0 918 }
aoqi@0 919
aoqi@0 920
aoqi@0 921 void GraphBuilder::store_local(ValueStack* state, Value x, int index) {
aoqi@0 922 if (parsing_jsr()) {
aoqi@0 923 // We need to do additional tracking of the location of the return
aoqi@0 924 // address for jsrs since we don't handle arbitrary jsr/ret
aoqi@0 925 // constructs. Here we are figuring out in which circumstances we
aoqi@0 926 // need to bail out.
aoqi@0 927 if (x->type()->is_address()) {
aoqi@0 928 scope_data()->set_jsr_return_address_local(index);
aoqi@0 929
aoqi@0 930 // Also check parent jsrs (if any) at this time to see whether
aoqi@0 931 // they are using this local. We don't handle skipping over a
aoqi@0 932 // ret.
aoqi@0 933 for (ScopeData* cur_scope_data = scope_data()->parent();
aoqi@0 934 cur_scope_data != NULL && cur_scope_data->parsing_jsr() && cur_scope_data->scope() == scope();
aoqi@0 935 cur_scope_data = cur_scope_data->parent()) {
aoqi@0 936 if (cur_scope_data->jsr_return_address_local() == index) {
aoqi@0 937 BAILOUT("subroutine overwrites return address from previous subroutine");
aoqi@0 938 }
aoqi@0 939 }
aoqi@0 940 } else if (index == scope_data()->jsr_return_address_local()) {
aoqi@0 941 scope_data()->set_jsr_return_address_local(-1);
aoqi@0 942 }
aoqi@0 943 }
aoqi@0 944
aoqi@0 945 state->store_local(index, round_fp(x));
aoqi@0 946 }
aoqi@0 947
aoqi@0 948
aoqi@0 949 void GraphBuilder::load_indexed(BasicType type) {
aoqi@0 950 // In case of in block code motion in range check elimination
aoqi@0 951 ValueStack* state_before = copy_state_indexed_access();
aoqi@0 952 compilation()->set_has_access_indexed(true);
aoqi@0 953 Value index = ipop();
aoqi@0 954 Value array = apop();
aoqi@0 955 Value length = NULL;
aoqi@0 956 if (CSEArrayLength ||
aoqi@0 957 (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
aoqi@0 958 (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
aoqi@0 959 length = append(new ArrayLength(array, state_before));
aoqi@0 960 }
aoqi@0 961 push(as_ValueType(type), append(new LoadIndexed(array, index, length, type, state_before)));
aoqi@0 962 }
aoqi@0 963
aoqi@0 964
aoqi@0 965 void GraphBuilder::store_indexed(BasicType type) {
aoqi@0 966 // In case of in block code motion in range check elimination
aoqi@0 967 ValueStack* state_before = copy_state_indexed_access();
aoqi@0 968 compilation()->set_has_access_indexed(true);
aoqi@0 969 Value value = pop(as_ValueType(type));
aoqi@0 970 Value index = ipop();
aoqi@0 971 Value array = apop();
aoqi@0 972 Value length = NULL;
aoqi@0 973 if (CSEArrayLength ||
aoqi@0 974 (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
aoqi@0 975 (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
aoqi@0 976 length = append(new ArrayLength(array, state_before));
aoqi@0 977 }
aoqi@0 978 StoreIndexed* result = new StoreIndexed(array, index, length, type, value, state_before);
aoqi@0 979 append(result);
aoqi@0 980 _memory->store_value(value);
aoqi@0 981
aoqi@0 982 if (type == T_OBJECT && is_profiling()) {
aoqi@0 983 // Note that we'd collect profile data in this method if we wanted it.
aoqi@0 984 compilation()->set_would_profile(true);
aoqi@0 985
aoqi@0 986 if (profile_checkcasts()) {
aoqi@0 987 result->set_profiled_method(method());
aoqi@0 988 result->set_profiled_bci(bci());
aoqi@0 989 result->set_should_profile(true);
aoqi@0 990 }
aoqi@0 991 }
aoqi@0 992 }
aoqi@0 993
aoqi@0 994
aoqi@0 995 void GraphBuilder::stack_op(Bytecodes::Code code) {
aoqi@0 996 switch (code) {
aoqi@0 997 case Bytecodes::_pop:
aoqi@0 998 { state()->raw_pop();
aoqi@0 999 }
aoqi@0 1000 break;
aoqi@0 1001 case Bytecodes::_pop2:
aoqi@0 1002 { state()->raw_pop();
aoqi@0 1003 state()->raw_pop();
aoqi@0 1004 }
aoqi@0 1005 break;
aoqi@0 1006 case Bytecodes::_dup:
aoqi@0 1007 { Value w = state()->raw_pop();
aoqi@0 1008 state()->raw_push(w);
aoqi@0 1009 state()->raw_push(w);
aoqi@0 1010 }
aoqi@0 1011 break;
aoqi@0 1012 case Bytecodes::_dup_x1:
aoqi@0 1013 { Value w1 = state()->raw_pop();
aoqi@0 1014 Value w2 = state()->raw_pop();
aoqi@0 1015 state()->raw_push(w1);
aoqi@0 1016 state()->raw_push(w2);
aoqi@0 1017 state()->raw_push(w1);
aoqi@0 1018 }
aoqi@0 1019 break;
aoqi@0 1020 case Bytecodes::_dup_x2:
aoqi@0 1021 { Value w1 = state()->raw_pop();
aoqi@0 1022 Value w2 = state()->raw_pop();
aoqi@0 1023 Value w3 = state()->raw_pop();
aoqi@0 1024 state()->raw_push(w1);
aoqi@0 1025 state()->raw_push(w3);
aoqi@0 1026 state()->raw_push(w2);
aoqi@0 1027 state()->raw_push(w1);
aoqi@0 1028 }
aoqi@0 1029 break;
aoqi@0 1030 case Bytecodes::_dup2:
aoqi@0 1031 { Value w1 = state()->raw_pop();
aoqi@0 1032 Value w2 = state()->raw_pop();
aoqi@0 1033 state()->raw_push(w2);
aoqi@0 1034 state()->raw_push(w1);
aoqi@0 1035 state()->raw_push(w2);
aoqi@0 1036 state()->raw_push(w1);
aoqi@0 1037 }
aoqi@0 1038 break;
aoqi@0 1039 case Bytecodes::_dup2_x1:
aoqi@0 1040 { Value w1 = state()->raw_pop();
aoqi@0 1041 Value w2 = state()->raw_pop();
aoqi@0 1042 Value w3 = state()->raw_pop();
aoqi@0 1043 state()->raw_push(w2);
aoqi@0 1044 state()->raw_push(w1);
aoqi@0 1045 state()->raw_push(w3);
aoqi@0 1046 state()->raw_push(w2);
aoqi@0 1047 state()->raw_push(w1);
aoqi@0 1048 }
aoqi@0 1049 break;
aoqi@0 1050 case Bytecodes::_dup2_x2:
aoqi@0 1051 { Value w1 = state()->raw_pop();
aoqi@0 1052 Value w2 = state()->raw_pop();
aoqi@0 1053 Value w3 = state()->raw_pop();
aoqi@0 1054 Value w4 = state()->raw_pop();
aoqi@0 1055 state()->raw_push(w2);
aoqi@0 1056 state()->raw_push(w1);
aoqi@0 1057 state()->raw_push(w4);
aoqi@0 1058 state()->raw_push(w3);
aoqi@0 1059 state()->raw_push(w2);
aoqi@0 1060 state()->raw_push(w1);
aoqi@0 1061 }
aoqi@0 1062 break;
aoqi@0 1063 case Bytecodes::_swap:
aoqi@0 1064 { Value w1 = state()->raw_pop();
aoqi@0 1065 Value w2 = state()->raw_pop();
aoqi@0 1066 state()->raw_push(w1);
aoqi@0 1067 state()->raw_push(w2);
aoqi@0 1068 }
aoqi@0 1069 break;
aoqi@0 1070 default:
aoqi@0 1071 ShouldNotReachHere();
aoqi@0 1072 break;
aoqi@0 1073 }
aoqi@0 1074 }
aoqi@0 1075
aoqi@0 1076
aoqi@0 1077 void GraphBuilder::arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* state_before) {
aoqi@0 1078 Value y = pop(type);
aoqi@0 1079 Value x = pop(type);
aoqi@0 1080 // NOTE: strictfp can be queried from current method since we don't
aoqi@0 1081 // inline methods with differing strictfp bits
aoqi@0 1082 Value res = new ArithmeticOp(code, x, y, method()->is_strict(), state_before);
aoqi@0 1083 // Note: currently single-precision floating-point rounding on Intel is handled at the LIRGenerator level
aoqi@0 1084 res = append(res);
aoqi@0 1085 if (method()->is_strict()) {
aoqi@0 1086 res = round_fp(res);
aoqi@0 1087 }
aoqi@0 1088 push(type, res);
aoqi@0 1089 }
aoqi@0 1090
aoqi@0 1091
aoqi@0 1092 void GraphBuilder::negate_op(ValueType* type) {
aoqi@0 1093 push(type, append(new NegateOp(pop(type))));
aoqi@0 1094 }
aoqi@0 1095
aoqi@0 1096
aoqi@0 1097 void GraphBuilder::shift_op(ValueType* type, Bytecodes::Code code) {
aoqi@0 1098 Value s = ipop();
aoqi@0 1099 Value x = pop(type);
aoqi@0 1100 // try to simplify
aoqi@0 1101 // Note: This code should go into the canonicalizer as soon as it can
aoqi@0 1102 // can handle canonicalized forms that contain more than one node.
aoqi@0 1103 if (CanonicalizeNodes && code == Bytecodes::_iushr) {
aoqi@0 1104 // pattern: x >>> s
aoqi@0 1105 IntConstant* s1 = s->type()->as_IntConstant();
aoqi@0 1106 if (s1 != NULL) {
aoqi@0 1107 // pattern: x >>> s1, with s1 constant
aoqi@0 1108 ShiftOp* l = x->as_ShiftOp();
aoqi@0 1109 if (l != NULL && l->op() == Bytecodes::_ishl) {
aoqi@0 1110 // pattern: (a << b) >>> s1
aoqi@0 1111 IntConstant* s0 = l->y()->type()->as_IntConstant();
aoqi@0 1112 if (s0 != NULL) {
aoqi@0 1113 // pattern: (a << s0) >>> s1
aoqi@0 1114 const int s0c = s0->value() & 0x1F; // only the low 5 bits are significant for shifts
aoqi@0 1115 const int s1c = s1->value() & 0x1F; // only the low 5 bits are significant for shifts
aoqi@0 1116 if (s0c == s1c) {
aoqi@0 1117 if (s0c == 0) {
aoqi@0 1118 // pattern: (a << 0) >>> 0 => simplify to: a
aoqi@0 1119 ipush(l->x());
aoqi@0 1120 } else {
aoqi@0 1121 // pattern: (a << s0c) >>> s0c => simplify to: a & m, with m constant
aoqi@0 1122 assert(0 < s0c && s0c < BitsPerInt, "adjust code below to handle corner cases");
aoqi@0 1123 const int m = (1 << (BitsPerInt - s0c)) - 1;
aoqi@0 1124 Value s = append(new Constant(new IntConstant(m)));
aoqi@0 1125 ipush(append(new LogicOp(Bytecodes::_iand, l->x(), s)));
aoqi@0 1126 }
aoqi@0 1127 return;
aoqi@0 1128 }
aoqi@0 1129 }
aoqi@0 1130 }
aoqi@0 1131 }
aoqi@0 1132 }
aoqi@0 1133 // could not simplify
aoqi@0 1134 push(type, append(new ShiftOp(code, x, s)));
aoqi@0 1135 }
aoqi@0 1136
aoqi@0 1137
aoqi@0 1138 void GraphBuilder::logic_op(ValueType* type, Bytecodes::Code code) {
aoqi@0 1139 Value y = pop(type);
aoqi@0 1140 Value x = pop(type);
aoqi@0 1141 push(type, append(new LogicOp(code, x, y)));
aoqi@0 1142 }
aoqi@0 1143
aoqi@0 1144
aoqi@0 1145 void GraphBuilder::compare_op(ValueType* type, Bytecodes::Code code) {
aoqi@0 1146 ValueStack* state_before = copy_state_before();
aoqi@0 1147 Value y = pop(type);
aoqi@0 1148 Value x = pop(type);
aoqi@0 1149 ipush(append(new CompareOp(code, x, y, state_before)));
aoqi@0 1150 }
aoqi@0 1151
aoqi@0 1152
aoqi@0 1153 void GraphBuilder::convert(Bytecodes::Code op, BasicType from, BasicType to) {
aoqi@0 1154 push(as_ValueType(to), append(new Convert(op, pop(as_ValueType(from)), as_ValueType(to))));
aoqi@0 1155 }
aoqi@0 1156
aoqi@0 1157
aoqi@0 1158 void GraphBuilder::increment() {
aoqi@0 1159 int index = stream()->get_index();
aoqi@0 1160 int delta = stream()->is_wide() ? (signed short)Bytes::get_Java_u2(stream()->cur_bcp() + 4) : (signed char)(stream()->cur_bcp()[2]);
aoqi@0 1161 load_local(intType, index);
aoqi@0 1162 ipush(append(new Constant(new IntConstant(delta))));
aoqi@0 1163 arithmetic_op(intType, Bytecodes::_iadd);
aoqi@0 1164 store_local(intType, index);
aoqi@0 1165 }
aoqi@0 1166
aoqi@0 1167
aoqi@0 1168 void GraphBuilder::_goto(int from_bci, int to_bci) {
aoqi@0 1169 Goto *x = new Goto(block_at(to_bci), to_bci <= from_bci);
aoqi@0 1170 if (is_profiling()) {
aoqi@0 1171 compilation()->set_would_profile(true);
aoqi@0 1172 x->set_profiled_bci(bci());
aoqi@0 1173 if (profile_branches()) {
aoqi@0 1174 x->set_profiled_method(method());
aoqi@0 1175 x->set_should_profile(true);
aoqi@0 1176 }
aoqi@0 1177 }
aoqi@0 1178 append(x);
aoqi@0 1179 }
aoqi@0 1180
aoqi@0 1181
aoqi@0 1182 void GraphBuilder::if_node(Value x, If::Condition cond, Value y, ValueStack* state_before) {
aoqi@0 1183 BlockBegin* tsux = block_at(stream()->get_dest());
aoqi@0 1184 BlockBegin* fsux = block_at(stream()->next_bci());
aoqi@0 1185 bool is_bb = tsux->bci() < stream()->cur_bci() || fsux->bci() < stream()->cur_bci();
aoqi@0 1186 // In case of loop invariant code motion or predicate insertion
aoqi@0 1187 // before the body of a loop the state is needed
aoqi@0 1188 Instruction *i = append(new If(x, cond, false, y, tsux, fsux, (is_bb || compilation()->is_optimistic()) ? state_before : NULL, is_bb));
aoqi@0 1189
aoqi@0 1190 assert(i->as_Goto() == NULL ||
aoqi@0 1191 (i->as_Goto()->sux_at(0) == tsux && i->as_Goto()->is_safepoint() == tsux->bci() < stream()->cur_bci()) ||
aoqi@0 1192 (i->as_Goto()->sux_at(0) == fsux && i->as_Goto()->is_safepoint() == fsux->bci() < stream()->cur_bci()),
aoqi@0 1193 "safepoint state of Goto returned by canonicalizer incorrect");
aoqi@0 1194
aoqi@0 1195 if (is_profiling()) {
aoqi@0 1196 If* if_node = i->as_If();
aoqi@0 1197 if (if_node != NULL) {
aoqi@0 1198 // Note that we'd collect profile data in this method if we wanted it.
aoqi@0 1199 compilation()->set_would_profile(true);
aoqi@0 1200 // At level 2 we need the proper bci to count backedges
aoqi@0 1201 if_node->set_profiled_bci(bci());
aoqi@0 1202 if (profile_branches()) {
aoqi@0 1203 // Successors can be rotated by the canonicalizer, check for this case.
aoqi@0 1204 if_node->set_profiled_method(method());
aoqi@0 1205 if_node->set_should_profile(true);
aoqi@0 1206 if (if_node->tsux() == fsux) {
aoqi@0 1207 if_node->set_swapped(true);
aoqi@0 1208 }
aoqi@0 1209 }
aoqi@0 1210 return;
aoqi@0 1211 }
aoqi@0 1212
aoqi@0 1213 // Check if this If was reduced to Goto.
aoqi@0 1214 Goto *goto_node = i->as_Goto();
aoqi@0 1215 if (goto_node != NULL) {
aoqi@0 1216 compilation()->set_would_profile(true);
aoqi@0 1217 goto_node->set_profiled_bci(bci());
aoqi@0 1218 if (profile_branches()) {
aoqi@0 1219 goto_node->set_profiled_method(method());
aoqi@0 1220 goto_node->set_should_profile(true);
aoqi@0 1221 // Find out which successor is used.
aoqi@0 1222 if (goto_node->default_sux() == tsux) {
aoqi@0 1223 goto_node->set_direction(Goto::taken);
aoqi@0 1224 } else if (goto_node->default_sux() == fsux) {
aoqi@0 1225 goto_node->set_direction(Goto::not_taken);
aoqi@0 1226 } else {
aoqi@0 1227 ShouldNotReachHere();
aoqi@0 1228 }
aoqi@0 1229 }
aoqi@0 1230 return;
aoqi@0 1231 }
aoqi@0 1232 }
aoqi@0 1233 }
aoqi@0 1234
aoqi@0 1235
aoqi@0 1236 void GraphBuilder::if_zero(ValueType* type, If::Condition cond) {
aoqi@0 1237 Value y = append(new Constant(intZero));
aoqi@0 1238 ValueStack* state_before = copy_state_before();
aoqi@0 1239 Value x = ipop();
aoqi@0 1240 if_node(x, cond, y, state_before);
aoqi@0 1241 }
aoqi@0 1242
aoqi@0 1243
aoqi@0 1244 void GraphBuilder::if_null(ValueType* type, If::Condition cond) {
aoqi@0 1245 Value y = append(new Constant(objectNull));
aoqi@0 1246 ValueStack* state_before = copy_state_before();
aoqi@0 1247 Value x = apop();
aoqi@0 1248 if_node(x, cond, y, state_before);
aoqi@0 1249 }
aoqi@0 1250
aoqi@0 1251
aoqi@0 1252 void GraphBuilder::if_same(ValueType* type, If::Condition cond) {
aoqi@0 1253 ValueStack* state_before = copy_state_before();
aoqi@0 1254 Value y = pop(type);
aoqi@0 1255 Value x = pop(type);
aoqi@0 1256 if_node(x, cond, y, state_before);
aoqi@0 1257 }
aoqi@0 1258
aoqi@0 1259
aoqi@0 1260 void GraphBuilder::jsr(int dest) {
aoqi@0 1261 // We only handle well-formed jsrs (those which are "block-structured").
aoqi@0 1262 // If the bytecodes are strange (jumping out of a jsr block) then we
aoqi@0 1263 // might end up trying to re-parse a block containing a jsr which
aoqi@0 1264 // has already been activated. Watch for this case and bail out.
aoqi@0 1265 for (ScopeData* cur_scope_data = scope_data();
aoqi@0 1266 cur_scope_data != NULL && cur_scope_data->parsing_jsr() && cur_scope_data->scope() == scope();
aoqi@0 1267 cur_scope_data = cur_scope_data->parent()) {
aoqi@0 1268 if (cur_scope_data->jsr_entry_bci() == dest) {
aoqi@0 1269 BAILOUT("too-complicated jsr/ret structure");
aoqi@0 1270 }
aoqi@0 1271 }
aoqi@0 1272
aoqi@0 1273 push(addressType, append(new Constant(new AddressConstant(next_bci()))));
aoqi@0 1274 if (!try_inline_jsr(dest)) {
aoqi@0 1275 return; // bailed out while parsing and inlining subroutine
aoqi@0 1276 }
aoqi@0 1277 }
aoqi@0 1278
aoqi@0 1279
aoqi@0 1280 void GraphBuilder::ret(int local_index) {
aoqi@0 1281 if (!parsing_jsr()) BAILOUT("ret encountered while not parsing subroutine");
aoqi@0 1282
aoqi@0 1283 if (local_index != scope_data()->jsr_return_address_local()) {
aoqi@0 1284 BAILOUT("can not handle complicated jsr/ret constructs");
aoqi@0 1285 }
aoqi@0 1286
aoqi@0 1287 // Rets simply become (NON-SAFEPOINT) gotos to the jsr continuation
aoqi@0 1288 append(new Goto(scope_data()->jsr_continuation(), false));
aoqi@0 1289 }
aoqi@0 1290
aoqi@0 1291
aoqi@0 1292 void GraphBuilder::table_switch() {
aoqi@0 1293 Bytecode_tableswitch sw(stream());
aoqi@0 1294 const int l = sw.length();
aoqi@0 1295 if (CanonicalizeNodes && l == 1) {
aoqi@0 1296 // total of 2 successors => use If instead of switch
aoqi@0 1297 // Note: This code should go into the canonicalizer as soon as it can
aoqi@0 1298 // can handle canonicalized forms that contain more than one node.
aoqi@0 1299 Value key = append(new Constant(new IntConstant(sw.low_key())));
aoqi@0 1300 BlockBegin* tsux = block_at(bci() + sw.dest_offset_at(0));
aoqi@0 1301 BlockBegin* fsux = block_at(bci() + sw.default_offset());
aoqi@0 1302 bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
aoqi@0 1303 // In case of loop invariant code motion or predicate insertion
aoqi@0 1304 // before the body of a loop the state is needed
aoqi@0 1305 ValueStack* state_before = copy_state_if_bb(is_bb);
aoqi@0 1306 append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
aoqi@0 1307 } else {
aoqi@0 1308 // collect successors
aoqi@0 1309 BlockList* sux = new BlockList(l + 1, NULL);
aoqi@0 1310 int i;
aoqi@0 1311 bool has_bb = false;
aoqi@0 1312 for (i = 0; i < l; i++) {
aoqi@0 1313 sux->at_put(i, block_at(bci() + sw.dest_offset_at(i)));
aoqi@0 1314 if (sw.dest_offset_at(i) < 0) has_bb = true;
aoqi@0 1315 }
aoqi@0 1316 // add default successor
aoqi@0 1317 if (sw.default_offset() < 0) has_bb = true;
aoqi@0 1318 sux->at_put(i, block_at(bci() + sw.default_offset()));
aoqi@0 1319 // In case of loop invariant code motion or predicate insertion
aoqi@0 1320 // before the body of a loop the state is needed
aoqi@0 1321 ValueStack* state_before = copy_state_if_bb(has_bb);
aoqi@0 1322 Instruction* res = append(new TableSwitch(ipop(), sux, sw.low_key(), state_before, has_bb));
aoqi@0 1323 #ifdef ASSERT
aoqi@0 1324 if (res->as_Goto()) {
aoqi@0 1325 for (i = 0; i < l; i++) {
aoqi@0 1326 if (sux->at(i) == res->as_Goto()->sux_at(0)) {
aoqi@0 1327 assert(res->as_Goto()->is_safepoint() == sw.dest_offset_at(i) < 0, "safepoint state of Goto returned by canonicalizer incorrect");
aoqi@0 1328 }
aoqi@0 1329 }
aoqi@0 1330 }
aoqi@0 1331 #endif
aoqi@0 1332 }
aoqi@0 1333 }
aoqi@0 1334
aoqi@0 1335
aoqi@0 1336 void GraphBuilder::lookup_switch() {
aoqi@0 1337 Bytecode_lookupswitch sw(stream());
aoqi@0 1338 const int l = sw.number_of_pairs();
aoqi@0 1339 if (CanonicalizeNodes && l == 1) {
aoqi@0 1340 // total of 2 successors => use If instead of switch
aoqi@0 1341 // Note: This code should go into the canonicalizer as soon as it can
aoqi@0 1342 // can handle canonicalized forms that contain more than one node.
aoqi@0 1343 // simplify to If
aoqi@0 1344 LookupswitchPair pair = sw.pair_at(0);
aoqi@0 1345 Value key = append(new Constant(new IntConstant(pair.match())));
aoqi@0 1346 BlockBegin* tsux = block_at(bci() + pair.offset());
aoqi@0 1347 BlockBegin* fsux = block_at(bci() + sw.default_offset());
aoqi@0 1348 bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
aoqi@0 1349 // In case of loop invariant code motion or predicate insertion
aoqi@0 1350 // before the body of a loop the state is needed
aoqi@0 1351 ValueStack* state_before = copy_state_if_bb(is_bb);;
aoqi@0 1352 append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
aoqi@0 1353 } else {
aoqi@0 1354 // collect successors & keys
aoqi@0 1355 BlockList* sux = new BlockList(l + 1, NULL);
aoqi@0 1356 intArray* keys = new intArray(l, 0);
aoqi@0 1357 int i;
aoqi@0 1358 bool has_bb = false;
aoqi@0 1359 for (i = 0; i < l; i++) {
aoqi@0 1360 LookupswitchPair pair = sw.pair_at(i);
aoqi@0 1361 if (pair.offset() < 0) has_bb = true;
aoqi@0 1362 sux->at_put(i, block_at(bci() + pair.offset()));
aoqi@0 1363 keys->at_put(i, pair.match());
aoqi@0 1364 }
aoqi@0 1365 // add default successor
aoqi@0 1366 if (sw.default_offset() < 0) has_bb = true;
aoqi@0 1367 sux->at_put(i, block_at(bci() + sw.default_offset()));
aoqi@0 1368 // In case of loop invariant code motion or predicate insertion
aoqi@0 1369 // before the body of a loop the state is needed
aoqi@0 1370 ValueStack* state_before = copy_state_if_bb(has_bb);
aoqi@0 1371 Instruction* res = append(new LookupSwitch(ipop(), sux, keys, state_before, has_bb));
aoqi@0 1372 #ifdef ASSERT
aoqi@0 1373 if (res->as_Goto()) {
aoqi@0 1374 for (i = 0; i < l; i++) {
aoqi@0 1375 if (sux->at(i) == res->as_Goto()->sux_at(0)) {
aoqi@0 1376 assert(res->as_Goto()->is_safepoint() == sw.pair_at(i).offset() < 0, "safepoint state of Goto returned by canonicalizer incorrect");
aoqi@0 1377 }
aoqi@0 1378 }
aoqi@0 1379 }
aoqi@0 1380 #endif
aoqi@0 1381 }
aoqi@0 1382 }
aoqi@0 1383
aoqi@0 1384 void GraphBuilder::call_register_finalizer() {
aoqi@0 1385 // If the receiver requires finalization then emit code to perform
aoqi@0 1386 // the registration on return.
aoqi@0 1387
aoqi@0 1388 // Gather some type information about the receiver
aoqi@0 1389 Value receiver = state()->local_at(0);
aoqi@0 1390 assert(receiver != NULL, "must have a receiver");
aoqi@0 1391 ciType* declared_type = receiver->declared_type();
aoqi@0 1392 ciType* exact_type = receiver->exact_type();
aoqi@0 1393 if (exact_type == NULL &&
aoqi@0 1394 receiver->as_Local() &&
aoqi@0 1395 receiver->as_Local()->java_index() == 0) {
aoqi@0 1396 ciInstanceKlass* ik = compilation()->method()->holder();
aoqi@0 1397 if (ik->is_final()) {
aoqi@0 1398 exact_type = ik;
aoqi@0 1399 } else if (UseCHA && !(ik->has_subklass() || ik->is_interface())) {
aoqi@0 1400 // test class is leaf class
aoqi@0 1401 compilation()->dependency_recorder()->assert_leaf_type(ik);
aoqi@0 1402 exact_type = ik;
aoqi@0 1403 } else {
aoqi@0 1404 declared_type = ik;
aoqi@0 1405 }
aoqi@0 1406 }
aoqi@0 1407
aoqi@0 1408 // see if we know statically that registration isn't required
aoqi@0 1409 bool needs_check = true;
aoqi@0 1410 if (exact_type != NULL) {
aoqi@0 1411 needs_check = exact_type->as_instance_klass()->has_finalizer();
aoqi@0 1412 } else if (declared_type != NULL) {
aoqi@0 1413 ciInstanceKlass* ik = declared_type->as_instance_klass();
aoqi@0 1414 if (!Dependencies::has_finalizable_subclass(ik)) {
aoqi@0 1415 compilation()->dependency_recorder()->assert_has_no_finalizable_subclasses(ik);
aoqi@0 1416 needs_check = false;
aoqi@0 1417 }
aoqi@0 1418 }
aoqi@0 1419
aoqi@0 1420 if (needs_check) {
aoqi@0 1421 // Perform the registration of finalizable objects.
aoqi@0 1422 ValueStack* state_before = copy_state_for_exception();
aoqi@0 1423 load_local(objectType, 0);
aoqi@0 1424 append_split(new Intrinsic(voidType, vmIntrinsics::_Object_init,
aoqi@0 1425 state()->pop_arguments(1),
aoqi@0 1426 true, state_before, true));
aoqi@0 1427 }
aoqi@0 1428 }
aoqi@0 1429
aoqi@0 1430
aoqi@0 1431 void GraphBuilder::method_return(Value x) {
aoqi@0 1432 if (RegisterFinalizersAtInit &&
aoqi@0 1433 method()->intrinsic_id() == vmIntrinsics::_Object_init) {
aoqi@0 1434 call_register_finalizer();
aoqi@0 1435 }
aoqi@0 1436
aoqi@0 1437 bool need_mem_bar = false;
aoqi@0 1438 if (method()->name() == ciSymbol::object_initializer_name() &&
aoqi@0 1439 scope()->wrote_final()) {
aoqi@0 1440 need_mem_bar = true;
aoqi@0 1441 }
aoqi@0 1442
aoqi@0 1443 // Check to see whether we are inlining. If so, Return
aoqi@0 1444 // instructions become Gotos to the continuation point.
aoqi@0 1445 if (continuation() != NULL) {
aoqi@0 1446 assert(!method()->is_synchronized() || InlineSynchronizedMethods, "can not inline synchronized methods yet");
aoqi@0 1447
aoqi@0 1448 if (compilation()->env()->dtrace_method_probes()) {
aoqi@0 1449 // Report exit from inline methods
aoqi@0 1450 Values* args = new Values(1);
aoqi@0 1451 args->push(append(new Constant(new MethodConstant(method()))));
aoqi@0 1452 append(new RuntimeCall(voidType, "dtrace_method_exit", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), args));
aoqi@0 1453 }
aoqi@0 1454
aoqi@0 1455 // If the inlined method is synchronized, the monitor must be
aoqi@0 1456 // released before we jump to the continuation block.
aoqi@0 1457 if (method()->is_synchronized()) {
aoqi@0 1458 assert(state()->locks_size() == 1, "receiver must be locked here");
aoqi@0 1459 monitorexit(state()->lock_at(0), SynchronizationEntryBCI);
aoqi@0 1460 }
aoqi@0 1461
aoqi@0 1462 if (need_mem_bar) {
aoqi@0 1463 append(new MemBar(lir_membar_storestore));
aoqi@0 1464 }
aoqi@0 1465
aoqi@0 1466 // State at end of inlined method is the state of the caller
aoqi@0 1467 // without the method parameters on stack, including the
aoqi@0 1468 // return value, if any, of the inlined method on operand stack.
aoqi@0 1469 int invoke_bci = state()->caller_state()->bci();
aoqi@0 1470 set_state(state()->caller_state()->copy_for_parsing());
aoqi@0 1471 if (x != NULL) {
aoqi@0 1472 state()->push(x->type(), x);
aoqi@0 1473 if (profile_return() && x->type()->is_object_kind()) {
aoqi@0 1474 ciMethod* caller = state()->scope()->method();
aoqi@0 1475 ciMethodData* md = caller->method_data_or_null();
aoqi@0 1476 ciProfileData* data = md->bci_to_data(invoke_bci);
aoqi@0 1477 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
aoqi@0 1478 bool has_return = data->is_CallTypeData() ? ((ciCallTypeData*)data)->has_return() : ((ciVirtualCallTypeData*)data)->has_return();
aoqi@0 1479 // May not be true in case of an inlined call through a method handle intrinsic.
aoqi@0 1480 if (has_return) {
aoqi@0 1481 profile_return_type(x, method(), caller, invoke_bci);
aoqi@0 1482 }
aoqi@0 1483 }
aoqi@0 1484 }
aoqi@0 1485 }
aoqi@0 1486 Goto* goto_callee = new Goto(continuation(), false);
aoqi@0 1487
aoqi@0 1488 // See whether this is the first return; if so, store off some
aoqi@0 1489 // of the state for later examination
aoqi@0 1490 if (num_returns() == 0) {
aoqi@0 1491 set_inline_cleanup_info();
aoqi@0 1492 }
aoqi@0 1493
aoqi@0 1494 // The current bci() is in the wrong scope, so use the bci() of
aoqi@0 1495 // the continuation point.
aoqi@0 1496 append_with_bci(goto_callee, scope_data()->continuation()->bci());
aoqi@0 1497 incr_num_returns();
aoqi@0 1498 return;
aoqi@0 1499 }
aoqi@0 1500
aoqi@0 1501 state()->truncate_stack(0);
aoqi@0 1502 if (method()->is_synchronized()) {
aoqi@0 1503 // perform the unlocking before exiting the method
aoqi@0 1504 Value receiver;
aoqi@0 1505 if (!method()->is_static()) {
aoqi@0 1506 receiver = _initial_state->local_at(0);
aoqi@0 1507 } else {
aoqi@0 1508 receiver = append(new Constant(new ClassConstant(method()->holder())));
aoqi@0 1509 }
aoqi@0 1510 append_split(new MonitorExit(receiver, state()->unlock()));
aoqi@0 1511 }
aoqi@0 1512
aoqi@0 1513 if (need_mem_bar) {
aoqi@0 1514 append(new MemBar(lir_membar_storestore));
aoqi@0 1515 }
aoqi@0 1516
aoqi@0 1517 append(new Return(x));
aoqi@0 1518 }
aoqi@0 1519
aoqi@0 1520
aoqi@0 1521 void GraphBuilder::access_field(Bytecodes::Code code) {
aoqi@0 1522 bool will_link;
aoqi@0 1523 ciField* field = stream()->get_field(will_link);
aoqi@0 1524 ciInstanceKlass* holder = field->holder();
aoqi@0 1525 BasicType field_type = field->type()->basic_type();
aoqi@0 1526 ValueType* type = as_ValueType(field_type);
aoqi@0 1527 // call will_link again to determine if the field is valid.
aoqi@0 1528 const bool needs_patching = !holder->is_loaded() ||
aoqi@0 1529 !field->will_link(method()->holder(), code) ||
aoqi@0 1530 PatchALot;
aoqi@0 1531
aoqi@0 1532 ValueStack* state_before = NULL;
aoqi@0 1533 if (!holder->is_initialized() || needs_patching) {
aoqi@0 1534 // save state before instruction for debug info when
aoqi@0 1535 // deoptimization happens during patching
aoqi@0 1536 state_before = copy_state_before();
aoqi@0 1537 }
aoqi@0 1538
aoqi@0 1539 Value obj = NULL;
aoqi@0 1540 if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) {
aoqi@0 1541 if (state_before != NULL) {
aoqi@0 1542 // build a patching constant
aoqi@0 1543 obj = new Constant(new InstanceConstant(holder->java_mirror()), state_before);
aoqi@0 1544 } else {
aoqi@0 1545 obj = new Constant(new InstanceConstant(holder->java_mirror()));
aoqi@0 1546 }
aoqi@0 1547 }
aoqi@0 1548
aoqi@0 1549 if (field->is_final() && (code == Bytecodes::_putfield)) {
aoqi@0 1550 scope()->set_wrote_final();
aoqi@0 1551 }
aoqi@0 1552
aoqi@0 1553 const int offset = !needs_patching ? field->offset() : -1;
aoqi@0 1554 switch (code) {
aoqi@0 1555 case Bytecodes::_getstatic: {
aoqi@0 1556 // check for compile-time constants, i.e., initialized static final fields
aoqi@0 1557 Instruction* constant = NULL;
aoqi@0 1558 if (field->is_constant() && !PatchALot) {
aoqi@0 1559 ciConstant field_val = field->constant_value();
aoqi@0 1560 BasicType field_type = field_val.basic_type();
aoqi@0 1561 switch (field_type) {
aoqi@0 1562 case T_ARRAY:
aoqi@0 1563 case T_OBJECT:
aoqi@0 1564 if (field_val.as_object()->should_be_constant()) {
aoqi@0 1565 constant = new Constant(as_ValueType(field_val));
aoqi@0 1566 }
aoqi@0 1567 break;
aoqi@0 1568
aoqi@0 1569 default:
aoqi@0 1570 constant = new Constant(as_ValueType(field_val));
aoqi@0 1571 }
aoqi@0 1572 // Stable static fields are checked for non-default values in ciField::initialize_from().
aoqi@0 1573 }
aoqi@0 1574 if (constant != NULL) {
aoqi@0 1575 push(type, append(constant));
aoqi@0 1576 } else {
aoqi@0 1577 if (state_before == NULL) {
aoqi@0 1578 state_before = copy_state_for_exception();
aoqi@0 1579 }
aoqi@0 1580 push(type, append(new LoadField(append(obj), offset, field, true,
aoqi@0 1581 state_before, needs_patching)));
aoqi@0 1582 }
aoqi@0 1583 break;
aoqi@0 1584 }
aoqi@0 1585 case Bytecodes::_putstatic:
aoqi@0 1586 { Value val = pop(type);
aoqi@0 1587 if (state_before == NULL) {
aoqi@0 1588 state_before = copy_state_for_exception();
aoqi@0 1589 }
aoqi@0 1590 append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching));
aoqi@0 1591 }
aoqi@0 1592 break;
aoqi@0 1593 case Bytecodes::_getfield: {
aoqi@0 1594 // Check for compile-time constants, i.e., trusted final non-static fields.
aoqi@0 1595 Instruction* constant = NULL;
aoqi@0 1596 obj = apop();
aoqi@0 1597 ObjectType* obj_type = obj->type()->as_ObjectType();
aoqi@0 1598 if (obj_type->is_constant() && !PatchALot) {
aoqi@0 1599 ciObject* const_oop = obj_type->constant_value();
aoqi@0 1600 if (!const_oop->is_null_object() && const_oop->is_loaded()) {
aoqi@0 1601 if (field->is_constant()) {
aoqi@0 1602 ciConstant field_val = field->constant_value_of(const_oop);
aoqi@0 1603 BasicType field_type = field_val.basic_type();
aoqi@0 1604 switch (field_type) {
aoqi@0 1605 case T_ARRAY:
aoqi@0 1606 case T_OBJECT:
aoqi@0 1607 if (field_val.as_object()->should_be_constant()) {
aoqi@0 1608 constant = new Constant(as_ValueType(field_val));
aoqi@0 1609 }
aoqi@0 1610 break;
aoqi@0 1611 default:
aoqi@0 1612 constant = new Constant(as_ValueType(field_val));
aoqi@0 1613 }
aoqi@0 1614 if (FoldStableValues && field->is_stable() && field_val.is_null_or_zero()) {
aoqi@0 1615 // Stable field with default value can't be constant.
aoqi@0 1616 constant = NULL;
aoqi@0 1617 }
aoqi@0 1618 } else {
aoqi@0 1619 // For CallSite objects treat the target field as a compile time constant.
aoqi@0 1620 if (const_oop->is_call_site()) {
aoqi@0 1621 ciCallSite* call_site = const_oop->as_call_site();
aoqi@0 1622 if (field->is_call_site_target()) {
aoqi@0 1623 ciMethodHandle* target = call_site->get_target();
aoqi@0 1624 if (target != NULL) { // just in case
aoqi@0 1625 ciConstant field_val(T_OBJECT, target);
aoqi@0 1626 constant = new Constant(as_ValueType(field_val));
aoqi@0 1627 // Add a dependence for invalidation of the optimization.
aoqi@0 1628 if (!call_site->is_constant_call_site()) {
aoqi@0 1629 dependency_recorder()->assert_call_site_target_value(call_site, target);
aoqi@0 1630 }
aoqi@0 1631 }
aoqi@0 1632 }
aoqi@0 1633 }
aoqi@0 1634 }
aoqi@0 1635 }
aoqi@0 1636 }
aoqi@0 1637 if (constant != NULL) {
aoqi@0 1638 push(type, append(constant));
aoqi@0 1639 } else {
aoqi@0 1640 if (state_before == NULL) {
aoqi@0 1641 state_before = copy_state_for_exception();
aoqi@0 1642 }
aoqi@0 1643 LoadField* load = new LoadField(obj, offset, field, false, state_before, needs_patching);
aoqi@0 1644 Value replacement = !needs_patching ? _memory->load(load) : load;
aoqi@0 1645 if (replacement != load) {
aoqi@0 1646 assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked");
aoqi@0 1647 push(type, replacement);
aoqi@0 1648 } else {
aoqi@0 1649 push(type, append(load));
aoqi@0 1650 }
aoqi@0 1651 }
aoqi@0 1652 break;
aoqi@0 1653 }
aoqi@0 1654 case Bytecodes::_putfield: {
aoqi@0 1655 Value val = pop(type);
aoqi@0 1656 obj = apop();
aoqi@0 1657 if (state_before == NULL) {
aoqi@0 1658 state_before = copy_state_for_exception();
aoqi@0 1659 }
aoqi@0 1660 StoreField* store = new StoreField(obj, offset, field, val, false, state_before, needs_patching);
aoqi@0 1661 if (!needs_patching) store = _memory->store(store);
aoqi@0 1662 if (store != NULL) {
aoqi@0 1663 append(store);
aoqi@0 1664 }
aoqi@0 1665 break;
aoqi@0 1666 }
aoqi@0 1667 default:
aoqi@0 1668 ShouldNotReachHere();
aoqi@0 1669 break;
aoqi@0 1670 }
aoqi@0 1671 }
aoqi@0 1672
aoqi@0 1673
aoqi@0 1674 Dependencies* GraphBuilder::dependency_recorder() const {
aoqi@0 1675 assert(DeoptC1, "need debug information");
aoqi@0 1676 return compilation()->dependency_recorder();
aoqi@0 1677 }
aoqi@0 1678
aoqi@0 1679 // How many arguments do we want to profile?
aoqi@0 1680 Values* GraphBuilder::args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver) {
aoqi@0 1681 int n = 0;
aoqi@0 1682 bool has_receiver = may_have_receiver && Bytecodes::has_receiver(method()->java_code_at_bci(bci()));
aoqi@0 1683 start = has_receiver ? 1 : 0;
aoqi@0 1684 if (profile_arguments()) {
aoqi@0 1685 ciProfileData* data = method()->method_data()->bci_to_data(bci());
aoqi@0 1686 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
aoqi@0 1687 n = data->is_CallTypeData() ? data->as_CallTypeData()->number_of_arguments() : data->as_VirtualCallTypeData()->number_of_arguments();
aoqi@0 1688 }
aoqi@0 1689 }
aoqi@0 1690 // If we are inlining then we need to collect arguments to profile parameters for the target
aoqi@0 1691 if (profile_parameters() && target != NULL) {
aoqi@0 1692 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
aoqi@0 1693 // The receiver is profiled on method entry so it's included in
aoqi@0 1694 // the number of parameters but here we're only interested in
aoqi@0 1695 // actual arguments.
aoqi@0 1696 n = MAX2(n, target->method_data()->parameters_type_data()->number_of_parameters() - start);
aoqi@0 1697 }
aoqi@0 1698 }
aoqi@0 1699 if (n > 0) {
aoqi@0 1700 return new Values(n);
aoqi@0 1701 }
aoqi@0 1702 return NULL;
aoqi@0 1703 }
aoqi@0 1704
aoqi@0 1705 void GraphBuilder::check_args_for_profiling(Values* obj_args, int expected) {
aoqi@0 1706 #ifdef ASSERT
aoqi@0 1707 bool ignored_will_link;
aoqi@0 1708 ciSignature* declared_signature = NULL;
aoqi@0 1709 ciMethod* real_target = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
aoqi@0 1710 assert(expected == obj_args->length() || real_target->is_method_handle_intrinsic(), "missed on arg?");
aoqi@0 1711 #endif
aoqi@0 1712 }
aoqi@0 1713
aoqi@0 1714 // Collect arguments that we want to profile in a list
aoqi@0 1715 Values* GraphBuilder::collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver) {
aoqi@0 1716 int start = 0;
aoqi@0 1717 Values* obj_args = args_list_for_profiling(target, start, may_have_receiver);
aoqi@0 1718 if (obj_args == NULL) {
aoqi@0 1719 return NULL;
aoqi@0 1720 }
aoqi@0 1721 int s = obj_args->size();
aoqi@0 1722 // if called through method handle invoke, some arguments may have been popped
aoqi@0 1723 for (int i = start, j = 0; j < s && i < args->length(); i++) {
aoqi@0 1724 if (args->at(i)->type()->is_object_kind()) {
aoqi@0 1725 obj_args->push(args->at(i));
aoqi@0 1726 j++;
aoqi@0 1727 }
aoqi@0 1728 }
aoqi@0 1729 check_args_for_profiling(obj_args, s);
aoqi@0 1730 return obj_args;
aoqi@0 1731 }
aoqi@0 1732
aoqi@0 1733
aoqi@0 1734 void GraphBuilder::invoke(Bytecodes::Code code) {
aoqi@0 1735 bool will_link;
aoqi@0 1736 ciSignature* declared_signature = NULL;
aoqi@0 1737 ciMethod* target = stream()->get_method(will_link, &declared_signature);
aoqi@0 1738 ciKlass* holder = stream()->get_declared_method_holder();
aoqi@0 1739 const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
aoqi@0 1740 assert(declared_signature != NULL, "cannot be null");
aoqi@0 1741
aoqi@0 1742 if (!C1PatchInvokeDynamic && Bytecodes::has_optional_appendix(bc_raw) && !will_link) {
aoqi@0 1743 BAILOUT("unlinked call site (C1PatchInvokeDynamic is off)");
aoqi@0 1744 }
aoqi@0 1745
aoqi@0 1746 // we have to make sure the argument size (incl. the receiver)
aoqi@0 1747 // is correct for compilation (the call would fail later during
aoqi@0 1748 // linkage anyway) - was bug (gri 7/28/99)
aoqi@0 1749 {
aoqi@0 1750 // Use raw to get rewritten bytecode.
aoqi@0 1751 const bool is_invokestatic = bc_raw == Bytecodes::_invokestatic;
aoqi@0 1752 const bool allow_static =
aoqi@0 1753 is_invokestatic ||
aoqi@0 1754 bc_raw == Bytecodes::_invokehandle ||
aoqi@0 1755 bc_raw == Bytecodes::_invokedynamic;
aoqi@0 1756 if (target->is_loaded()) {
aoqi@0 1757 if (( target->is_static() && !allow_static) ||
aoqi@0 1758 (!target->is_static() && is_invokestatic)) {
aoqi@0 1759 BAILOUT("will cause link error");
aoqi@0 1760 }
aoqi@0 1761 }
aoqi@0 1762 }
aoqi@0 1763 ciInstanceKlass* klass = target->holder();
aoqi@0 1764
aoqi@0 1765 // check if CHA possible: if so, change the code to invoke_special
aoqi@0 1766 ciInstanceKlass* calling_klass = method()->holder();
aoqi@0 1767 ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
aoqi@0 1768 ciInstanceKlass* actual_recv = callee_holder;
aoqi@0 1769
aoqi@0 1770 CompileLog* log = compilation()->log();
aoqi@0 1771 if (log != NULL)
aoqi@0 1772 log->elem("call method='%d' instr='%s'",
aoqi@0 1773 log->identify(target),
aoqi@0 1774 Bytecodes::name(code));
aoqi@0 1775
aoqi@0 1776 // Some methods are obviously bindable without any type checks so
aoqi@0 1777 // convert them directly to an invokespecial or invokestatic.
aoqi@0 1778 if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
aoqi@0 1779 switch (bc_raw) {
aoqi@0 1780 case Bytecodes::_invokevirtual:
aoqi@0 1781 code = Bytecodes::_invokespecial;
aoqi@0 1782 break;
aoqi@0 1783 case Bytecodes::_invokehandle:
aoqi@0 1784 code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial;
aoqi@0 1785 break;
aoqi@0 1786 }
aoqi@0 1787 } else {
aoqi@0 1788 if (bc_raw == Bytecodes::_invokehandle) {
aoqi@0 1789 assert(!will_link, "should come here only for unlinked call");
aoqi@0 1790 code = Bytecodes::_invokespecial;
aoqi@0 1791 }
aoqi@0 1792 }
aoqi@0 1793
aoqi@0 1794 // Push appendix argument (MethodType, CallSite, etc.), if one.
aoqi@0 1795 bool patch_for_appendix = false;
aoqi@0 1796 int patching_appendix_arg = 0;
aoqi@0 1797 if (C1PatchInvokeDynamic &&
aoqi@0 1798 (Bytecodes::has_optional_appendix(bc_raw) && (!will_link || PatchALot))) {
aoqi@0 1799 Value arg = append(new Constant(new ObjectConstant(compilation()->env()->unloaded_ciinstance()), copy_state_before()));
aoqi@0 1800 apush(arg);
aoqi@0 1801 patch_for_appendix = true;
aoqi@0 1802 patching_appendix_arg = (will_link && stream()->has_appendix()) ? 0 : 1;
aoqi@0 1803 } else if (stream()->has_appendix()) {
aoqi@0 1804 ciObject* appendix = stream()->get_appendix();
aoqi@0 1805 Value arg = append(new Constant(new ObjectConstant(appendix)));
aoqi@0 1806 apush(arg);
aoqi@0 1807 }
aoqi@0 1808
aoqi@0 1809 // NEEDS_CLEANUP
aoqi@0 1810 // I've added the target->is_loaded() test below but I don't really understand
aoqi@0 1811 // how klass->is_loaded() can be true and yet target->is_loaded() is false.
aoqi@0 1812 // this happened while running the JCK invokevirtual tests under doit. TKR
aoqi@0 1813 ciMethod* cha_monomorphic_target = NULL;
aoqi@0 1814 ciMethod* exact_target = NULL;
aoqi@0 1815 Value better_receiver = NULL;
aoqi@0 1816 if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
aoqi@0 1817 !(// %%% FIXME: Are both of these relevant?
aoqi@0 1818 target->is_method_handle_intrinsic() ||
aoqi@0 1819 target->is_compiled_lambda_form()) &&
aoqi@0 1820 !patch_for_appendix) {
aoqi@0 1821 Value receiver = NULL;
aoqi@0 1822 ciInstanceKlass* receiver_klass = NULL;
aoqi@0 1823 bool type_is_exact = false;
aoqi@0 1824 // try to find a precise receiver type
aoqi@0 1825 if (will_link && !target->is_static()) {
aoqi@0 1826 int index = state()->stack_size() - (target->arg_size_no_receiver() + 1);
aoqi@0 1827 receiver = state()->stack_at(index);
aoqi@0 1828 ciType* type = receiver->exact_type();
aoqi@0 1829 if (type != NULL && type->is_loaded() &&
aoqi@0 1830 type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
aoqi@0 1831 receiver_klass = (ciInstanceKlass*) type;
aoqi@0 1832 type_is_exact = true;
aoqi@0 1833 }
aoqi@0 1834 if (type == NULL) {
aoqi@0 1835 type = receiver->declared_type();
aoqi@0 1836 if (type != NULL && type->is_loaded() &&
aoqi@0 1837 type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
aoqi@0 1838 receiver_klass = (ciInstanceKlass*) type;
aoqi@0 1839 if (receiver_klass->is_leaf_type() && !receiver_klass->is_final()) {
aoqi@0 1840 // Insert a dependency on this type since
aoqi@0 1841 // find_monomorphic_target may assume it's already done.
aoqi@0 1842 dependency_recorder()->assert_leaf_type(receiver_klass);
aoqi@0 1843 type_is_exact = true;
aoqi@0 1844 }
aoqi@0 1845 }
aoqi@0 1846 }
aoqi@0 1847 }
aoqi@0 1848 if (receiver_klass != NULL && type_is_exact &&
aoqi@0 1849 receiver_klass->is_loaded() && code != Bytecodes::_invokespecial) {
aoqi@0 1850 // If we have the exact receiver type we can bind directly to
aoqi@0 1851 // the method to call.
aoqi@0 1852 exact_target = target->resolve_invoke(calling_klass, receiver_klass);
aoqi@0 1853 if (exact_target != NULL) {
aoqi@0 1854 target = exact_target;
aoqi@0 1855 code = Bytecodes::_invokespecial;
aoqi@0 1856 }
aoqi@0 1857 }
aoqi@0 1858 if (receiver_klass != NULL &&
aoqi@0 1859 receiver_klass->is_subtype_of(actual_recv) &&
aoqi@0 1860 actual_recv->is_initialized()) {
aoqi@0 1861 actual_recv = receiver_klass;
aoqi@0 1862 }
aoqi@0 1863
aoqi@0 1864 if ((code == Bytecodes::_invokevirtual && callee_holder->is_initialized()) ||
aoqi@0 1865 (code == Bytecodes::_invokeinterface && callee_holder->is_initialized() && !actual_recv->is_interface())) {
aoqi@0 1866 // Use CHA on the receiver to select a more precise method.
aoqi@0 1867 cha_monomorphic_target = target->find_monomorphic_target(calling_klass, callee_holder, actual_recv);
aoqi@0 1868 } else if (code == Bytecodes::_invokeinterface && callee_holder->is_loaded() && receiver != NULL) {
aoqi@0 1869 // if there is only one implementor of this interface then we
aoqi@0 1870 // may be able bind this invoke directly to the implementing
aoqi@0 1871 // klass but we need both a dependence on the single interface
aoqi@0 1872 // and on the method we bind to. Additionally since all we know
aoqi@0 1873 // about the receiver type is the it's supposed to implement the
aoqi@0 1874 // interface we have to insert a check that it's the class we
aoqi@0 1875 // expect. Interface types are not checked by the verifier so
aoqi@0 1876 // they are roughly equivalent to Object.
aoqi@0 1877 ciInstanceKlass* singleton = NULL;
aoqi@0 1878 if (target->holder()->nof_implementors() == 1) {
aoqi@0 1879 singleton = target->holder()->implementor();
aoqi@0 1880 assert(singleton != NULL && singleton != target->holder(),
aoqi@0 1881 "just checking");
aoqi@0 1882
aoqi@0 1883 assert(holder->is_interface(), "invokeinterface to non interface?");
aoqi@0 1884 ciInstanceKlass* decl_interface = (ciInstanceKlass*)holder;
aoqi@0 1885 // the number of implementors for decl_interface is less or
aoqi@0 1886 // equal to the number of implementors for target->holder() so
aoqi@0 1887 // if number of implementors of target->holder() == 1 then
aoqi@0 1888 // number of implementors for decl_interface is 0 or 1. If
aoqi@0 1889 // it's 0 then no class implements decl_interface and there's
aoqi@0 1890 // no point in inlining.
aoqi@0 1891 if (!holder->is_loaded() || decl_interface->nof_implementors() != 1 || decl_interface->has_default_methods()) {
aoqi@0 1892 singleton = NULL;
aoqi@0 1893 }
aoqi@0 1894 }
aoqi@0 1895 if (singleton) {
aoqi@0 1896 cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton);
aoqi@0 1897 if (cha_monomorphic_target != NULL) {
aoqi@0 1898 // If CHA is able to bind this invoke then update the class
aoqi@0 1899 // to match that class, otherwise klass will refer to the
aoqi@0 1900 // interface.
aoqi@0 1901 klass = cha_monomorphic_target->holder();
aoqi@0 1902 actual_recv = target->holder();
aoqi@0 1903
aoqi@0 1904 // insert a check it's really the expected class.
aoqi@0 1905 CheckCast* c = new CheckCast(klass, receiver, copy_state_for_exception());
aoqi@0 1906 c->set_incompatible_class_change_check();
aoqi@0 1907 c->set_direct_compare(klass->is_final());
aoqi@0 1908 // pass the result of the checkcast so that the compiler has
aoqi@0 1909 // more accurate type info in the inlinee
aoqi@0 1910 better_receiver = append_split(c);
aoqi@0 1911 }
aoqi@0 1912 }
aoqi@0 1913 }
aoqi@0 1914 }
aoqi@0 1915
aoqi@0 1916 if (cha_monomorphic_target != NULL) {
aoqi@0 1917 if (cha_monomorphic_target->is_abstract()) {
aoqi@0 1918 // Do not optimize for abstract methods
aoqi@0 1919 cha_monomorphic_target = NULL;
aoqi@0 1920 }
aoqi@0 1921 }
aoqi@0 1922
aoqi@0 1923 if (cha_monomorphic_target != NULL) {
aoqi@0 1924 if (!(target->is_final_method())) {
aoqi@0 1925 // If we inlined because CHA revealed only a single target method,
aoqi@0 1926 // then we are dependent on that target method not getting overridden
aoqi@0 1927 // by dynamic class loading. Be sure to test the "static" receiver
aoqi@0 1928 // dest_method here, as opposed to the actual receiver, which may
aoqi@0 1929 // falsely lead us to believe that the receiver is final or private.
aoqi@0 1930 dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target);
aoqi@0 1931 }
aoqi@0 1932 code = Bytecodes::_invokespecial;
aoqi@0 1933 }
aoqi@0 1934
aoqi@0 1935 // check if we could do inlining
aoqi@0 1936 if (!PatchALot && Inline && klass->is_loaded() &&
aoqi@0 1937 (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
aoqi@0 1938 && target->is_loaded()
aoqi@0 1939 && !patch_for_appendix) {
aoqi@0 1940 // callee is known => check if we have static binding
aoqi@0 1941 assert(target->is_loaded(), "callee must be known");
aoqi@0 1942 if (code == Bytecodes::_invokestatic ||
aoqi@0 1943 code == Bytecodes::_invokespecial ||
aoqi@0 1944 code == Bytecodes::_invokevirtual && target->is_final_method() ||
aoqi@0 1945 code == Bytecodes::_invokedynamic) {
aoqi@0 1946 ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target;
aoqi@0 1947 // static binding => check if callee is ok
aoqi@0 1948 bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), code, better_receiver);
aoqi@0 1949
aoqi@0 1950 CHECK_BAILOUT();
aoqi@0 1951 clear_inline_bailout();
aoqi@0 1952
aoqi@0 1953 if (success) {
aoqi@0 1954 // Register dependence if JVMTI has either breakpoint
aoqi@0 1955 // setting or hotswapping of methods capabilities since they may
aoqi@0 1956 // cause deoptimization.
aoqi@0 1957 if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) {
aoqi@0 1958 dependency_recorder()->assert_evol_method(inline_target);
aoqi@0 1959 }
aoqi@0 1960 return;
aoqi@0 1961 }
aoqi@0 1962 } else {
aoqi@0 1963 print_inlining(target, "no static binding", /*success*/ false);
aoqi@0 1964 }
aoqi@0 1965 } else {
aoqi@0 1966 print_inlining(target, "not inlineable", /*success*/ false);
aoqi@0 1967 }
aoqi@0 1968
aoqi@0 1969 // If we attempted an inline which did not succeed because of a
aoqi@0 1970 // bailout during construction of the callee graph, the entire
aoqi@0 1971 // compilation has to be aborted. This is fairly rare and currently
aoqi@0 1972 // seems to only occur for jasm-generated classes which contain
aoqi@0 1973 // jsr/ret pairs which are not associated with finally clauses and
aoqi@0 1974 // do not have exception handlers in the containing method, and are
aoqi@0 1975 // therefore not caught early enough to abort the inlining without
aoqi@0 1976 // corrupting the graph. (We currently bail out with a non-empty
aoqi@0 1977 // stack at a ret in these situations.)
aoqi@0 1978 CHECK_BAILOUT();
aoqi@0 1979
aoqi@0 1980 // inlining not successful => standard invoke
aoqi@0 1981 bool is_loaded = target->is_loaded();
aoqi@0 1982 ValueType* result_type = as_ValueType(declared_signature->return_type());
aoqi@0 1983 ValueStack* state_before = copy_state_exhandling();
aoqi@0 1984
aoqi@0 1985 // The bytecode (code) might change in this method so we are checking this very late.
aoqi@0 1986 const bool has_receiver =
aoqi@0 1987 code == Bytecodes::_invokespecial ||
aoqi@0 1988 code == Bytecodes::_invokevirtual ||
aoqi@0 1989 code == Bytecodes::_invokeinterface;
aoqi@0 1990 Values* args = state()->pop_arguments(target->arg_size_no_receiver() + patching_appendix_arg);
aoqi@0 1991 Value recv = has_receiver ? apop() : NULL;
aoqi@0 1992 int vtable_index = Method::invalid_vtable_index;
aoqi@0 1993
aoqi@0 1994 #ifdef SPARC
aoqi@0 1995 // Currently only supported on Sparc.
aoqi@0 1996 // The UseInlineCaches only controls dispatch to invokevirtuals for
aoqi@0 1997 // loaded classes which we weren't able to statically bind.
aoqi@0 1998 if (!UseInlineCaches && is_loaded && code == Bytecodes::_invokevirtual
aoqi@0 1999 && !target->can_be_statically_bound()) {
aoqi@0 2000 // Find a vtable index if one is available
aoqi@0 2001 // For arrays, callee_holder is Object. Resolving the call with
aoqi@0 2002 // Object would allow an illegal call to finalize() on an
aoqi@0 2003 // array. We use holder instead: illegal calls to finalize() won't
aoqi@0 2004 // be compiled as vtable calls (IC call resolution will catch the
aoqi@0 2005 // illegal call) and the few legal calls on array types won't be
aoqi@0 2006 // either.
aoqi@0 2007 vtable_index = target->resolve_vtable_index(calling_klass, holder);
aoqi@0 2008 }
aoqi@0 2009 #endif
aoqi@0 2010
aoqi@0 2011 if (recv != NULL &&
aoqi@0 2012 (code == Bytecodes::_invokespecial ||
aoqi@0 2013 !is_loaded || target->is_final())) {
aoqi@0 2014 // invokespecial always needs a NULL check. invokevirtual where
aoqi@0 2015 // the target is final or where it's not known that whether the
aoqi@0 2016 // target is final requires a NULL check. Otherwise normal
aoqi@0 2017 // invokevirtual will perform the null check during the lookup
aoqi@0 2018 // logic or the unverified entry point. Profiling of calls
aoqi@0 2019 // requires that the null check is performed in all cases.
aoqi@0 2020 null_check(recv);
aoqi@0 2021 }
aoqi@0 2022
aoqi@0 2023 if (is_profiling()) {
aoqi@0 2024 if (recv != NULL && profile_calls()) {
aoqi@0 2025 null_check(recv);
aoqi@0 2026 }
aoqi@0 2027 // Note that we'd collect profile data in this method if we wanted it.
aoqi@0 2028 compilation()->set_would_profile(true);
aoqi@0 2029
aoqi@0 2030 if (profile_calls()) {
aoqi@0 2031 assert(cha_monomorphic_target == NULL || exact_target == NULL, "both can not be set");
aoqi@0 2032 ciKlass* target_klass = NULL;
aoqi@0 2033 if (cha_monomorphic_target != NULL) {
aoqi@0 2034 target_klass = cha_monomorphic_target->holder();
aoqi@0 2035 } else if (exact_target != NULL) {
aoqi@0 2036 target_klass = exact_target->holder();
aoqi@0 2037 }
aoqi@0 2038 profile_call(target, recv, target_klass, collect_args_for_profiling(args, NULL, false), false);
aoqi@0 2039 }
aoqi@0 2040 }
aoqi@0 2041
aoqi@0 2042 Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before);
aoqi@0 2043 // push result
aoqi@0 2044 append_split(result);
aoqi@0 2045
aoqi@0 2046 if (result_type != voidType) {
aoqi@0 2047 if (method()->is_strict()) {
aoqi@0 2048 push(result_type, round_fp(result));
aoqi@0 2049 } else {
aoqi@0 2050 push(result_type, result);
aoqi@0 2051 }
aoqi@0 2052 }
aoqi@0 2053 if (profile_return() && result_type->is_object_kind()) {
aoqi@0 2054 profile_return_type(result, target);
aoqi@0 2055 }
aoqi@0 2056 }
aoqi@0 2057
aoqi@0 2058
aoqi@0 2059 void GraphBuilder::new_instance(int klass_index) {
aoqi@0 2060 ValueStack* state_before = copy_state_exhandling();
aoqi@0 2061 bool will_link;
aoqi@0 2062 ciKlass* klass = stream()->get_klass(will_link);
aoqi@0 2063 assert(klass->is_instance_klass(), "must be an instance klass");
aoqi@0 2064 NewInstance* new_instance = new NewInstance(klass->as_instance_klass(), state_before);
aoqi@0 2065 _memory->new_instance(new_instance);
aoqi@0 2066 apush(append_split(new_instance));
aoqi@0 2067 }
aoqi@0 2068
aoqi@0 2069
aoqi@0 2070 void GraphBuilder::new_type_array() {
aoqi@0 2071 ValueStack* state_before = copy_state_exhandling();
aoqi@0 2072 apush(append_split(new NewTypeArray(ipop(), (BasicType)stream()->get_index(), state_before)));
aoqi@0 2073 }
aoqi@0 2074
aoqi@0 2075
aoqi@0 2076 void GraphBuilder::new_object_array() {
aoqi@0 2077 bool will_link;
aoqi@0 2078 ciKlass* klass = stream()->get_klass(will_link);
aoqi@0 2079 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
aoqi@0 2080 NewArray* n = new NewObjectArray(klass, ipop(), state_before);
aoqi@0 2081 apush(append_split(n));
aoqi@0 2082 }
aoqi@0 2083
aoqi@0 2084
aoqi@0 2085 bool GraphBuilder::direct_compare(ciKlass* k) {
aoqi@0 2086 if (k->is_loaded() && k->is_instance_klass() && !UseSlowPath) {
aoqi@0 2087 ciInstanceKlass* ik = k->as_instance_klass();
aoqi@0 2088 if (ik->is_final()) {
aoqi@0 2089 return true;
aoqi@0 2090 } else {
aoqi@0 2091 if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) {
aoqi@0 2092 // test class is leaf class
aoqi@0 2093 dependency_recorder()->assert_leaf_type(ik);
aoqi@0 2094 return true;
aoqi@0 2095 }
aoqi@0 2096 }
aoqi@0 2097 }
aoqi@0 2098 return false;
aoqi@0 2099 }
aoqi@0 2100
aoqi@0 2101
aoqi@0 2102 void GraphBuilder::check_cast(int klass_index) {
aoqi@0 2103 bool will_link;
aoqi@0 2104 ciKlass* klass = stream()->get_klass(will_link);
aoqi@0 2105 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_for_exception();
aoqi@0 2106 CheckCast* c = new CheckCast(klass, apop(), state_before);
aoqi@0 2107 apush(append_split(c));
aoqi@0 2108 c->set_direct_compare(direct_compare(klass));
aoqi@0 2109
aoqi@0 2110 if (is_profiling()) {
aoqi@0 2111 // Note that we'd collect profile data in this method if we wanted it.
aoqi@0 2112 compilation()->set_would_profile(true);
aoqi@0 2113
aoqi@0 2114 if (profile_checkcasts()) {
aoqi@0 2115 c->set_profiled_method(method());
aoqi@0 2116 c->set_profiled_bci(bci());
aoqi@0 2117 c->set_should_profile(true);
aoqi@0 2118 }
aoqi@0 2119 }
aoqi@0 2120 }
aoqi@0 2121
aoqi@0 2122
aoqi@0 2123 void GraphBuilder::instance_of(int klass_index) {
aoqi@0 2124 bool will_link;
aoqi@0 2125 ciKlass* klass = stream()->get_klass(will_link);
aoqi@0 2126 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
aoqi@0 2127 InstanceOf* i = new InstanceOf(klass, apop(), state_before);
aoqi@0 2128 ipush(append_split(i));
aoqi@0 2129 i->set_direct_compare(direct_compare(klass));
aoqi@0 2130
aoqi@0 2131 if (is_profiling()) {
aoqi@0 2132 // Note that we'd collect profile data in this method if we wanted it.
aoqi@0 2133 compilation()->set_would_profile(true);
aoqi@0 2134
aoqi@0 2135 if (profile_checkcasts()) {
aoqi@0 2136 i->set_profiled_method(method());
aoqi@0 2137 i->set_profiled_bci(bci());
aoqi@0 2138 i->set_should_profile(true);
aoqi@0 2139 }
aoqi@0 2140 }
aoqi@0 2141 }
aoqi@0 2142
aoqi@0 2143
aoqi@0 2144 void GraphBuilder::monitorenter(Value x, int bci) {
aoqi@0 2145 // save state before locking in case of deoptimization after a NullPointerException
aoqi@0 2146 ValueStack* state_before = copy_state_for_exception_with_bci(bci);
aoqi@0 2147 append_with_bci(new MonitorEnter(x, state()->lock(x), state_before), bci);
aoqi@0 2148 kill_all();
aoqi@0 2149 }
aoqi@0 2150
aoqi@0 2151
aoqi@0 2152 void GraphBuilder::monitorexit(Value x, int bci) {
aoqi@0 2153 append_with_bci(new MonitorExit(x, state()->unlock()), bci);
aoqi@0 2154 kill_all();
aoqi@0 2155 }
aoqi@0 2156
aoqi@0 2157
aoqi@0 2158 void GraphBuilder::new_multi_array(int dimensions) {
aoqi@0 2159 bool will_link;
aoqi@0 2160 ciKlass* klass = stream()->get_klass(will_link);
aoqi@0 2161 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
aoqi@0 2162
aoqi@0 2163 Values* dims = new Values(dimensions, NULL);
aoqi@0 2164 // fill in all dimensions
aoqi@0 2165 int i = dimensions;
aoqi@0 2166 while (i-- > 0) dims->at_put(i, ipop());
aoqi@0 2167 // create array
aoqi@0 2168 NewArray* n = new NewMultiArray(klass, dims, state_before);
aoqi@0 2169 apush(append_split(n));
aoqi@0 2170 }
aoqi@0 2171
aoqi@0 2172
aoqi@0 2173 void GraphBuilder::throw_op(int bci) {
aoqi@0 2174 // We require that the debug info for a Throw be the "state before"
aoqi@0 2175 // the Throw (i.e., exception oop is still on TOS)
aoqi@0 2176 ValueStack* state_before = copy_state_before_with_bci(bci);
aoqi@0 2177 Throw* t = new Throw(apop(), state_before);
aoqi@0 2178 // operand stack not needed after a throw
aoqi@0 2179 state()->truncate_stack(0);
aoqi@0 2180 append_with_bci(t, bci);
aoqi@0 2181 }
aoqi@0 2182
aoqi@0 2183
aoqi@0 2184 Value GraphBuilder::round_fp(Value fp_value) {
aoqi@0 2185 // no rounding needed if SSE2 is used
aoqi@0 2186 if (RoundFPResults && UseSSE < 2) {
aoqi@0 2187 // Must currently insert rounding node for doubleword values that
aoqi@0 2188 // are results of expressions (i.e., not loads from memory or
aoqi@0 2189 // constants)
aoqi@0 2190 if (fp_value->type()->tag() == doubleTag &&
aoqi@0 2191 fp_value->as_Constant() == NULL &&
aoqi@0 2192 fp_value->as_Local() == NULL && // method parameters need no rounding
aoqi@0 2193 fp_value->as_RoundFP() == NULL) {
aoqi@0 2194 return append(new RoundFP(fp_value));
aoqi@0 2195 }
aoqi@0 2196 }
aoqi@0 2197 return fp_value;
aoqi@0 2198 }
aoqi@0 2199
aoqi@0 2200
aoqi@0 2201 Instruction* GraphBuilder::append_with_bci(Instruction* instr, int bci) {
aoqi@0 2202 Canonicalizer canon(compilation(), instr, bci);
aoqi@0 2203 Instruction* i1 = canon.canonical();
aoqi@0 2204 if (i1->is_linked() || !i1->can_be_linked()) {
aoqi@0 2205 // Canonicalizer returned an instruction which was already
aoqi@0 2206 // appended so simply return it.
aoqi@0 2207 return i1;
aoqi@0 2208 }
aoqi@0 2209
aoqi@0 2210 if (UseLocalValueNumbering) {
aoqi@0 2211 // Lookup the instruction in the ValueMap and add it to the map if
aoqi@0 2212 // it's not found.
aoqi@0 2213 Instruction* i2 = vmap()->find_insert(i1);
aoqi@0 2214 if (i2 != i1) {
aoqi@0 2215 // found an entry in the value map, so just return it.
aoqi@0 2216 assert(i2->is_linked(), "should already be linked");
aoqi@0 2217 return i2;
aoqi@0 2218 }
aoqi@0 2219 ValueNumberingEffects vne(vmap());
aoqi@0 2220 i1->visit(&vne);
aoqi@0 2221 }
aoqi@0 2222
aoqi@0 2223 // i1 was not eliminated => append it
aoqi@0 2224 assert(i1->next() == NULL, "shouldn't already be linked");
aoqi@0 2225 _last = _last->set_next(i1, canon.bci());
aoqi@0 2226
aoqi@0 2227 if (++_instruction_count >= InstructionCountCutoff && !bailed_out()) {
aoqi@0 2228 // set the bailout state but complete normal processing. We
aoqi@0 2229 // might do a little more work before noticing the bailout so we
aoqi@0 2230 // want processing to continue normally until it's noticed.
aoqi@0 2231 bailout("Method and/or inlining is too large");
aoqi@0 2232 }
aoqi@0 2233
aoqi@0 2234 #ifndef PRODUCT
aoqi@0 2235 if (PrintIRDuringConstruction) {
aoqi@0 2236 InstructionPrinter ip;
aoqi@0 2237 ip.print_line(i1);
aoqi@0 2238 if (Verbose) {
aoqi@0 2239 state()->print();
aoqi@0 2240 }
aoqi@0 2241 }
aoqi@0 2242 #endif
aoqi@0 2243
aoqi@0 2244 // save state after modification of operand stack for StateSplit instructions
aoqi@0 2245 StateSplit* s = i1->as_StateSplit();
aoqi@0 2246 if (s != NULL) {
aoqi@0 2247 if (EliminateFieldAccess) {
aoqi@0 2248 Intrinsic* intrinsic = s->as_Intrinsic();
aoqi@0 2249 if (s->as_Invoke() != NULL || (intrinsic && !intrinsic->preserves_state())) {
aoqi@0 2250 _memory->kill();
aoqi@0 2251 }
aoqi@0 2252 }
aoqi@0 2253 s->set_state(state()->copy(ValueStack::StateAfter, canon.bci()));
aoqi@0 2254 }
aoqi@0 2255
aoqi@0 2256 // set up exception handlers for this instruction if necessary
aoqi@0 2257 if (i1->can_trap()) {
aoqi@0 2258 i1->set_exception_handlers(handle_exception(i1));
aoqi@0 2259 assert(i1->exception_state() != NULL || !i1->needs_exception_state() || bailed_out(), "handle_exception must set exception state");
aoqi@0 2260 }
aoqi@0 2261 return i1;
aoqi@0 2262 }
aoqi@0 2263
aoqi@0 2264
aoqi@0 2265 Instruction* GraphBuilder::append(Instruction* instr) {
aoqi@0 2266 assert(instr->as_StateSplit() == NULL || instr->as_BlockEnd() != NULL, "wrong append used");
aoqi@0 2267 return append_with_bci(instr, bci());
aoqi@0 2268 }
aoqi@0 2269
aoqi@0 2270
aoqi@0 2271 Instruction* GraphBuilder::append_split(StateSplit* instr) {
aoqi@0 2272 return append_with_bci(instr, bci());
aoqi@0 2273 }
aoqi@0 2274
aoqi@0 2275
aoqi@0 2276 void GraphBuilder::null_check(Value value) {
aoqi@0 2277 if (value->as_NewArray() != NULL || value->as_NewInstance() != NULL) {
aoqi@0 2278 return;
aoqi@0 2279 } else {
aoqi@0 2280 Constant* con = value->as_Constant();
aoqi@0 2281 if (con) {
aoqi@0 2282 ObjectType* c = con->type()->as_ObjectType();
aoqi@0 2283 if (c && c->is_loaded()) {
aoqi@0 2284 ObjectConstant* oc = c->as_ObjectConstant();
aoqi@0 2285 if (!oc || !oc->value()->is_null_object()) {
aoqi@0 2286 return;
aoqi@0 2287 }
aoqi@0 2288 }
aoqi@0 2289 }
aoqi@0 2290 }
aoqi@0 2291 append(new NullCheck(value, copy_state_for_exception()));
aoqi@0 2292 }
aoqi@0 2293
aoqi@0 2294
aoqi@0 2295
aoqi@0 2296 XHandlers* GraphBuilder::handle_exception(Instruction* instruction) {
aoqi@0 2297 if (!has_handler() && (!instruction->needs_exception_state() || instruction->exception_state() != NULL)) {
aoqi@0 2298 assert(instruction->exception_state() == NULL
aoqi@0 2299 || instruction->exception_state()->kind() == ValueStack::EmptyExceptionState
aoqi@0 2300 || (instruction->exception_state()->kind() == ValueStack::ExceptionState && _compilation->env()->jvmti_can_access_local_variables()),
aoqi@0 2301 "exception_state should be of exception kind");
aoqi@0 2302 return new XHandlers();
aoqi@0 2303 }
aoqi@0 2304
aoqi@0 2305 XHandlers* exception_handlers = new XHandlers();
aoqi@0 2306 ScopeData* cur_scope_data = scope_data();
aoqi@0 2307 ValueStack* cur_state = instruction->state_before();
aoqi@0 2308 ValueStack* prev_state = NULL;
aoqi@0 2309 int scope_count = 0;
aoqi@0 2310
aoqi@0 2311 assert(cur_state != NULL, "state_before must be set");
aoqi@0 2312 do {
aoqi@0 2313 int cur_bci = cur_state->bci();
aoqi@0 2314 assert(cur_scope_data->scope() == cur_state->scope(), "scopes do not match");
aoqi@0 2315 assert(cur_bci == SynchronizationEntryBCI || cur_bci == cur_scope_data->stream()->cur_bci(), "invalid bci");
aoqi@0 2316
aoqi@0 2317 // join with all potential exception handlers
aoqi@0 2318 XHandlers* list = cur_scope_data->xhandlers();
aoqi@0 2319 const int n = list->length();
aoqi@0 2320 for (int i = 0; i < n; i++) {
aoqi@0 2321 XHandler* h = list->handler_at(i);
aoqi@0 2322 if (h->covers(cur_bci)) {
aoqi@0 2323 // h is a potential exception handler => join it
aoqi@0 2324 compilation()->set_has_exception_handlers(true);
aoqi@0 2325
aoqi@0 2326 BlockBegin* entry = h->entry_block();
aoqi@0 2327 if (entry == block()) {
aoqi@0 2328 // It's acceptable for an exception handler to cover itself
aoqi@0 2329 // but we don't handle that in the parser currently. It's
aoqi@0 2330 // very rare so we bailout instead of trying to handle it.
aoqi@0 2331 BAILOUT_("exception handler covers itself", exception_handlers);
aoqi@0 2332 }
aoqi@0 2333 assert(entry->bci() == h->handler_bci(), "must match");
aoqi@0 2334 assert(entry->bci() == -1 || entry == cur_scope_data->block_at(entry->bci()), "blocks must correspond");
aoqi@0 2335
aoqi@0 2336 // previously this was a BAILOUT, but this is not necessary
aoqi@0 2337 // now because asynchronous exceptions are not handled this way.
aoqi@0 2338 assert(entry->state() == NULL || cur_state->total_locks_size() == entry->state()->total_locks_size(), "locks do not match");
aoqi@0 2339
aoqi@0 2340 // xhandler start with an empty expression stack
aoqi@0 2341 if (cur_state->stack_size() != 0) {
aoqi@0 2342 cur_state = cur_state->copy(ValueStack::ExceptionState, cur_state->bci());
aoqi@0 2343 }
aoqi@0 2344 if (instruction->exception_state() == NULL) {
aoqi@0 2345 instruction->set_exception_state(cur_state);
aoqi@0 2346 }
aoqi@0 2347
aoqi@0 2348 // Note: Usually this join must work. However, very
aoqi@0 2349 // complicated jsr-ret structures where we don't ret from
aoqi@0 2350 // the subroutine can cause the objects on the monitor
aoqi@0 2351 // stacks to not match because blocks can be parsed twice.
aoqi@0 2352 // The only test case we've seen so far which exhibits this
aoqi@0 2353 // problem is caught by the infinite recursion test in
aoqi@0 2354 // GraphBuilder::jsr() if the join doesn't work.
aoqi@0 2355 if (!entry->try_merge(cur_state)) {
aoqi@0 2356 BAILOUT_("error while joining with exception handler, prob. due to complicated jsr/rets", exception_handlers);
aoqi@0 2357 }
aoqi@0 2358
aoqi@0 2359 // add current state for correct handling of phi functions at begin of xhandler
aoqi@0 2360 int phi_operand = entry->add_exception_state(cur_state);
aoqi@0 2361
aoqi@0 2362 // add entry to the list of xhandlers of this block
aoqi@0 2363 _block->add_exception_handler(entry);
aoqi@0 2364
aoqi@0 2365 // add back-edge from xhandler entry to this block
aoqi@0 2366 if (!entry->is_predecessor(_block)) {
aoqi@0 2367 entry->add_predecessor(_block);
aoqi@0 2368 }
aoqi@0 2369
aoqi@0 2370 // clone XHandler because phi_operand and scope_count can not be shared
aoqi@0 2371 XHandler* new_xhandler = new XHandler(h);
aoqi@0 2372 new_xhandler->set_phi_operand(phi_operand);
aoqi@0 2373 new_xhandler->set_scope_count(scope_count);
aoqi@0 2374 exception_handlers->append(new_xhandler);
aoqi@0 2375
aoqi@0 2376 // fill in exception handler subgraph lazily
aoqi@0 2377 assert(!entry->is_set(BlockBegin::was_visited_flag), "entry must not be visited yet");
aoqi@0 2378 cur_scope_data->add_to_work_list(entry);
aoqi@0 2379
aoqi@0 2380 // stop when reaching catchall
aoqi@0 2381 if (h->catch_type() == 0) {
aoqi@0 2382 return exception_handlers;
aoqi@0 2383 }
aoqi@0 2384 }
aoqi@0 2385 }
aoqi@0 2386
aoqi@0 2387 if (exception_handlers->length() == 0) {
aoqi@0 2388 // This scope and all callees do not handle exceptions, so the local
aoqi@0 2389 // variables of this scope are not needed. However, the scope itself is
aoqi@0 2390 // required for a correct exception stack trace -> clear out the locals.
aoqi@0 2391 if (_compilation->env()->jvmti_can_access_local_variables()) {
aoqi@0 2392 cur_state = cur_state->copy(ValueStack::ExceptionState, cur_state->bci());
aoqi@0 2393 } else {
aoqi@0 2394 cur_state = cur_state->copy(ValueStack::EmptyExceptionState, cur_state->bci());
aoqi@0 2395 }
aoqi@0 2396 if (prev_state != NULL) {
aoqi@0 2397 prev_state->set_caller_state(cur_state);
aoqi@0 2398 }
aoqi@0 2399 if (instruction->exception_state() == NULL) {
aoqi@0 2400 instruction->set_exception_state(cur_state);
aoqi@0 2401 }
aoqi@0 2402 }
aoqi@0 2403
aoqi@0 2404 // Set up iteration for next time.
aoqi@0 2405 // If parsing a jsr, do not grab exception handlers from the
aoqi@0 2406 // parent scopes for this method (already got them, and they
aoqi@0 2407 // needed to be cloned)
aoqi@0 2408
aoqi@0 2409 while (cur_scope_data->parsing_jsr()) {
aoqi@0 2410 cur_scope_data = cur_scope_data->parent();
aoqi@0 2411 }
aoqi@0 2412
aoqi@0 2413 assert(cur_scope_data->scope() == cur_state->scope(), "scopes do not match");
aoqi@0 2414 assert(cur_state->locks_size() == 0 || cur_state->locks_size() == 1, "unlocking must be done in a catchall exception handler");
aoqi@0 2415
aoqi@0 2416 prev_state = cur_state;
aoqi@0 2417 cur_state = cur_state->caller_state();
aoqi@0 2418 cur_scope_data = cur_scope_data->parent();
aoqi@0 2419 scope_count++;
aoqi@0 2420 } while (cur_scope_data != NULL);
aoqi@0 2421
aoqi@0 2422 return exception_handlers;
aoqi@0 2423 }
aoqi@0 2424
aoqi@0 2425
aoqi@0 2426 // Helper class for simplifying Phis.
aoqi@0 2427 class PhiSimplifier : public BlockClosure {
aoqi@0 2428 private:
aoqi@0 2429 bool _has_substitutions;
aoqi@0 2430 Value simplify(Value v);
aoqi@0 2431
aoqi@0 2432 public:
aoqi@0 2433 PhiSimplifier(BlockBegin* start) : _has_substitutions(false) {
aoqi@0 2434 start->iterate_preorder(this);
aoqi@0 2435 if (_has_substitutions) {
aoqi@0 2436 SubstitutionResolver sr(start);
aoqi@0 2437 }
aoqi@0 2438 }
aoqi@0 2439 void block_do(BlockBegin* b);
aoqi@0 2440 bool has_substitutions() const { return _has_substitutions; }
aoqi@0 2441 };
aoqi@0 2442
aoqi@0 2443
aoqi@0 2444 Value PhiSimplifier::simplify(Value v) {
aoqi@0 2445 Phi* phi = v->as_Phi();
aoqi@0 2446
aoqi@0 2447 if (phi == NULL) {
aoqi@0 2448 // no phi function
aoqi@0 2449 return v;
aoqi@0 2450 } else if (v->has_subst()) {
aoqi@0 2451 // already substituted; subst can be phi itself -> simplify
aoqi@0 2452 return simplify(v->subst());
aoqi@0 2453 } else if (phi->is_set(Phi::cannot_simplify)) {
aoqi@0 2454 // already tried to simplify phi before
aoqi@0 2455 return phi;
aoqi@0 2456 } else if (phi->is_set(Phi::visited)) {
aoqi@0 2457 // break cycles in phi functions
aoqi@0 2458 return phi;
aoqi@0 2459 } else if (phi->type()->is_illegal()) {
aoqi@0 2460 // illegal phi functions are ignored anyway
aoqi@0 2461 return phi;
aoqi@0 2462
aoqi@0 2463 } else {
aoqi@0 2464 // mark phi function as processed to break cycles in phi functions
aoqi@0 2465 phi->set(Phi::visited);
aoqi@0 2466
aoqi@0 2467 // simplify x = [y, x] and x = [y, y] to y
aoqi@0 2468 Value subst = NULL;
aoqi@0 2469 int opd_count = phi->operand_count();
aoqi@0 2470 for (int i = 0; i < opd_count; i++) {
aoqi@0 2471 Value opd = phi->operand_at(i);
aoqi@0 2472 assert(opd != NULL, "Operand must exist!");
aoqi@0 2473
aoqi@0 2474 if (opd->type()->is_illegal()) {
aoqi@0 2475 // if one operand is illegal, the entire phi function is illegal
aoqi@0 2476 phi->make_illegal();
aoqi@0 2477 phi->clear(Phi::visited);
aoqi@0 2478 return phi;
aoqi@0 2479 }
aoqi@0 2480
aoqi@0 2481 Value new_opd = simplify(opd);
aoqi@0 2482 assert(new_opd != NULL, "Simplified operand must exist!");
aoqi@0 2483
aoqi@0 2484 if (new_opd != phi && new_opd != subst) {
aoqi@0 2485 if (subst == NULL) {
aoqi@0 2486 subst = new_opd;
aoqi@0 2487 } else {
aoqi@0 2488 // no simplification possible
aoqi@0 2489 phi->set(Phi::cannot_simplify);
aoqi@0 2490 phi->clear(Phi::visited);
aoqi@0 2491 return phi;
aoqi@0 2492 }
aoqi@0 2493 }
aoqi@0 2494 }
aoqi@0 2495
aoqi@0 2496 // sucessfully simplified phi function
aoqi@0 2497 assert(subst != NULL, "illegal phi function");
aoqi@0 2498 _has_substitutions = true;
aoqi@0 2499 phi->clear(Phi::visited);
aoqi@0 2500 phi->set_subst(subst);
aoqi@0 2501
aoqi@0 2502 #ifndef PRODUCT
aoqi@0 2503 if (PrintPhiFunctions) {
aoqi@0 2504 tty->print_cr("simplified phi function %c%d to %c%d (Block B%d)", phi->type()->tchar(), phi->id(), subst->type()->tchar(), subst->id(), phi->block()->block_id());
aoqi@0 2505 }
aoqi@0 2506 #endif
aoqi@0 2507
aoqi@0 2508 return subst;
aoqi@0 2509 }
aoqi@0 2510 }
aoqi@0 2511
aoqi@0 2512
aoqi@0 2513 void PhiSimplifier::block_do(BlockBegin* b) {
aoqi@0 2514 for_each_phi_fun(b, phi,
aoqi@0 2515 simplify(phi);
aoqi@0 2516 );
aoqi@0 2517
aoqi@0 2518 #ifdef ASSERT
aoqi@0 2519 for_each_phi_fun(b, phi,
aoqi@0 2520 assert(phi->operand_count() != 1 || phi->subst() != phi, "missed trivial simplification");
aoqi@0 2521 );
aoqi@0 2522
aoqi@0 2523 ValueStack* state = b->state()->caller_state();
aoqi@0 2524 for_each_state_value(state, value,
aoqi@0 2525 Phi* phi = value->as_Phi();
aoqi@0 2526 assert(phi == NULL || phi->block() != b, "must not have phi function to simplify in caller state");
aoqi@0 2527 );
aoqi@0 2528 #endif
aoqi@0 2529 }
aoqi@0 2530
aoqi@0 2531 // This method is called after all blocks are filled with HIR instructions
aoqi@0 2532 // It eliminates all Phi functions of the form x = [y, y] and x = [y, x]
aoqi@0 2533 void GraphBuilder::eliminate_redundant_phis(BlockBegin* start) {
aoqi@0 2534 PhiSimplifier simplifier(start);
aoqi@0 2535 }
aoqi@0 2536
aoqi@0 2537
aoqi@0 2538 void GraphBuilder::connect_to_end(BlockBegin* beg) {
aoqi@0 2539 // setup iteration
aoqi@0 2540 kill_all();
aoqi@0 2541 _block = beg;
aoqi@0 2542 _state = beg->state()->copy_for_parsing();
aoqi@0 2543 _last = beg;
aoqi@0 2544 iterate_bytecodes_for_block(beg->bci());
aoqi@0 2545 }
aoqi@0 2546
aoqi@0 2547
aoqi@0 2548 BlockEnd* GraphBuilder::iterate_bytecodes_for_block(int bci) {
aoqi@0 2549 #ifndef PRODUCT
aoqi@0 2550 if (PrintIRDuringConstruction) {
aoqi@0 2551 tty->cr();
aoqi@0 2552 InstructionPrinter ip;
aoqi@0 2553 ip.print_instr(_block); tty->cr();
aoqi@0 2554 ip.print_stack(_block->state()); tty->cr();
aoqi@0 2555 ip.print_inline_level(_block);
aoqi@0 2556 ip.print_head();
aoqi@0 2557 tty->print_cr("locals size: %d stack size: %d", state()->locals_size(), state()->stack_size());
aoqi@0 2558 }
aoqi@0 2559 #endif
aoqi@0 2560 _skip_block = false;
aoqi@0 2561 assert(state() != NULL, "ValueStack missing!");
aoqi@0 2562 CompileLog* log = compilation()->log();
aoqi@0 2563 ciBytecodeStream s(method());
aoqi@0 2564 s.reset_to_bci(bci);
aoqi@0 2565 int prev_bci = bci;
aoqi@0 2566 scope_data()->set_stream(&s);
aoqi@0 2567 // iterate
aoqi@0 2568 Bytecodes::Code code = Bytecodes::_illegal;
aoqi@0 2569 bool push_exception = false;
aoqi@0 2570
aoqi@0 2571 if (block()->is_set(BlockBegin::exception_entry_flag) && block()->next() == NULL) {
aoqi@0 2572 // first thing in the exception entry block should be the exception object.
aoqi@0 2573 push_exception = true;
aoqi@0 2574 }
aoqi@0 2575
aoqi@0 2576 while (!bailed_out() && last()->as_BlockEnd() == NULL &&
aoqi@0 2577 (code = stream()->next()) != ciBytecodeStream::EOBC() &&
aoqi@0 2578 (block_at(s.cur_bci()) == NULL || block_at(s.cur_bci()) == block())) {
aoqi@0 2579 assert(state()->kind() == ValueStack::Parsing, "invalid state kind");
aoqi@0 2580
aoqi@0 2581 if (log != NULL)
aoqi@0 2582 log->set_context("bc code='%d' bci='%d'", (int)code, s.cur_bci());
aoqi@0 2583
aoqi@0 2584 // Check for active jsr during OSR compilation
aoqi@0 2585 if (compilation()->is_osr_compile()
aoqi@0 2586 && scope()->is_top_scope()
aoqi@0 2587 && parsing_jsr()
aoqi@0 2588 && s.cur_bci() == compilation()->osr_bci()) {
aoqi@0 2589 bailout("OSR not supported while a jsr is active");
aoqi@0 2590 }
aoqi@0 2591
aoqi@0 2592 if (push_exception) {
aoqi@0 2593 apush(append(new ExceptionObject()));
aoqi@0 2594 push_exception = false;
aoqi@0 2595 }
aoqi@0 2596
aoqi@0 2597 // handle bytecode
aoqi@0 2598 switch (code) {
aoqi@0 2599 case Bytecodes::_nop : /* nothing to do */ break;
aoqi@0 2600 case Bytecodes::_aconst_null : apush(append(new Constant(objectNull ))); break;
aoqi@0 2601 case Bytecodes::_iconst_m1 : ipush(append(new Constant(new IntConstant (-1)))); break;
aoqi@0 2602 case Bytecodes::_iconst_0 : ipush(append(new Constant(intZero ))); break;
aoqi@0 2603 case Bytecodes::_iconst_1 : ipush(append(new Constant(intOne ))); break;
aoqi@0 2604 case Bytecodes::_iconst_2 : ipush(append(new Constant(new IntConstant ( 2)))); break;
aoqi@0 2605 case Bytecodes::_iconst_3 : ipush(append(new Constant(new IntConstant ( 3)))); break;
aoqi@0 2606 case Bytecodes::_iconst_4 : ipush(append(new Constant(new IntConstant ( 4)))); break;
aoqi@0 2607 case Bytecodes::_iconst_5 : ipush(append(new Constant(new IntConstant ( 5)))); break;
aoqi@0 2608 case Bytecodes::_lconst_0 : lpush(append(new Constant(new LongConstant ( 0)))); break;
aoqi@0 2609 case Bytecodes::_lconst_1 : lpush(append(new Constant(new LongConstant ( 1)))); break;
aoqi@0 2610 case Bytecodes::_fconst_0 : fpush(append(new Constant(new FloatConstant ( 0)))); break;
aoqi@0 2611 case Bytecodes::_fconst_1 : fpush(append(new Constant(new FloatConstant ( 1)))); break;
aoqi@0 2612 case Bytecodes::_fconst_2 : fpush(append(new Constant(new FloatConstant ( 2)))); break;
aoqi@0 2613 case Bytecodes::_dconst_0 : dpush(append(new Constant(new DoubleConstant( 0)))); break;
aoqi@0 2614 case Bytecodes::_dconst_1 : dpush(append(new Constant(new DoubleConstant( 1)))); break;
aoqi@0 2615 case Bytecodes::_bipush : ipush(append(new Constant(new IntConstant(((signed char*)s.cur_bcp())[1])))); break;
aoqi@0 2616 case Bytecodes::_sipush : ipush(append(new Constant(new IntConstant((short)Bytes::get_Java_u2(s.cur_bcp()+1))))); break;
aoqi@0 2617 case Bytecodes::_ldc : // fall through
aoqi@0 2618 case Bytecodes::_ldc_w : // fall through
aoqi@0 2619 case Bytecodes::_ldc2_w : load_constant(); break;
aoqi@0 2620 case Bytecodes::_iload : load_local(intType , s.get_index()); break;
aoqi@0 2621 case Bytecodes::_lload : load_local(longType , s.get_index()); break;
aoqi@0 2622 case Bytecodes::_fload : load_local(floatType , s.get_index()); break;
aoqi@0 2623 case Bytecodes::_dload : load_local(doubleType , s.get_index()); break;
aoqi@0 2624 case Bytecodes::_aload : load_local(instanceType, s.get_index()); break;
aoqi@0 2625 case Bytecodes::_iload_0 : load_local(intType , 0); break;
aoqi@0 2626 case Bytecodes::_iload_1 : load_local(intType , 1); break;
aoqi@0 2627 case Bytecodes::_iload_2 : load_local(intType , 2); break;
aoqi@0 2628 case Bytecodes::_iload_3 : load_local(intType , 3); break;
aoqi@0 2629 case Bytecodes::_lload_0 : load_local(longType , 0); break;
aoqi@0 2630 case Bytecodes::_lload_1 : load_local(longType , 1); break;
aoqi@0 2631 case Bytecodes::_lload_2 : load_local(longType , 2); break;
aoqi@0 2632 case Bytecodes::_lload_3 : load_local(longType , 3); break;
aoqi@0 2633 case Bytecodes::_fload_0 : load_local(floatType , 0); break;
aoqi@0 2634 case Bytecodes::_fload_1 : load_local(floatType , 1); break;
aoqi@0 2635 case Bytecodes::_fload_2 : load_local(floatType , 2); break;
aoqi@0 2636 case Bytecodes::_fload_3 : load_local(floatType , 3); break;
aoqi@0 2637 case Bytecodes::_dload_0 : load_local(doubleType, 0); break;
aoqi@0 2638 case Bytecodes::_dload_1 : load_local(doubleType, 1); break;
aoqi@0 2639 case Bytecodes::_dload_2 : load_local(doubleType, 2); break;
aoqi@0 2640 case Bytecodes::_dload_3 : load_local(doubleType, 3); break;
aoqi@0 2641 case Bytecodes::_aload_0 : load_local(objectType, 0); break;
aoqi@0 2642 case Bytecodes::_aload_1 : load_local(objectType, 1); break;
aoqi@0 2643 case Bytecodes::_aload_2 : load_local(objectType, 2); break;
aoqi@0 2644 case Bytecodes::_aload_3 : load_local(objectType, 3); break;
aoqi@0 2645 case Bytecodes::_iaload : load_indexed(T_INT ); break;
aoqi@0 2646 case Bytecodes::_laload : load_indexed(T_LONG ); break;
aoqi@0 2647 case Bytecodes::_faload : load_indexed(T_FLOAT ); break;
aoqi@0 2648 case Bytecodes::_daload : load_indexed(T_DOUBLE); break;
aoqi@0 2649 case Bytecodes::_aaload : load_indexed(T_OBJECT); break;
aoqi@0 2650 case Bytecodes::_baload : load_indexed(T_BYTE ); break;
aoqi@0 2651 case Bytecodes::_caload : load_indexed(T_CHAR ); break;
aoqi@0 2652 case Bytecodes::_saload : load_indexed(T_SHORT ); break;
aoqi@0 2653 case Bytecodes::_istore : store_local(intType , s.get_index()); break;
aoqi@0 2654 case Bytecodes::_lstore : store_local(longType , s.get_index()); break;
aoqi@0 2655 case Bytecodes::_fstore : store_local(floatType , s.get_index()); break;
aoqi@0 2656 case Bytecodes::_dstore : store_local(doubleType, s.get_index()); break;
aoqi@0 2657 case Bytecodes::_astore : store_local(objectType, s.get_index()); break;
aoqi@0 2658 case Bytecodes::_istore_0 : store_local(intType , 0); break;
aoqi@0 2659 case Bytecodes::_istore_1 : store_local(intType , 1); break;
aoqi@0 2660 case Bytecodes::_istore_2 : store_local(intType , 2); break;
aoqi@0 2661 case Bytecodes::_istore_3 : store_local(intType , 3); break;
aoqi@0 2662 case Bytecodes::_lstore_0 : store_local(longType , 0); break;
aoqi@0 2663 case Bytecodes::_lstore_1 : store_local(longType , 1); break;
aoqi@0 2664 case Bytecodes::_lstore_2 : store_local(longType , 2); break;
aoqi@0 2665 case Bytecodes::_lstore_3 : store_local(longType , 3); break;
aoqi@0 2666 case Bytecodes::_fstore_0 : store_local(floatType , 0); break;
aoqi@0 2667 case Bytecodes::_fstore_1 : store_local(floatType , 1); break;
aoqi@0 2668 case Bytecodes::_fstore_2 : store_local(floatType , 2); break;
aoqi@0 2669 case Bytecodes::_fstore_3 : store_local(floatType , 3); break;
aoqi@0 2670 case Bytecodes::_dstore_0 : store_local(doubleType, 0); break;
aoqi@0 2671 case Bytecodes::_dstore_1 : store_local(doubleType, 1); break;
aoqi@0 2672 case Bytecodes::_dstore_2 : store_local(doubleType, 2); break;
aoqi@0 2673 case Bytecodes::_dstore_3 : store_local(doubleType, 3); break;
aoqi@0 2674 case Bytecodes::_astore_0 : store_local(objectType, 0); break;
aoqi@0 2675 case Bytecodes::_astore_1 : store_local(objectType, 1); break;
aoqi@0 2676 case Bytecodes::_astore_2 : store_local(objectType, 2); break;
aoqi@0 2677 case Bytecodes::_astore_3 : store_local(objectType, 3); break;
aoqi@0 2678 case Bytecodes::_iastore : store_indexed(T_INT ); break;
aoqi@0 2679 case Bytecodes::_lastore : store_indexed(T_LONG ); break;
aoqi@0 2680 case Bytecodes::_fastore : store_indexed(T_FLOAT ); break;
aoqi@0 2681 case Bytecodes::_dastore : store_indexed(T_DOUBLE); break;
aoqi@0 2682 case Bytecodes::_aastore : store_indexed(T_OBJECT); break;
aoqi@0 2683 case Bytecodes::_bastore : store_indexed(T_BYTE ); break;
aoqi@0 2684 case Bytecodes::_castore : store_indexed(T_CHAR ); break;
aoqi@0 2685 case Bytecodes::_sastore : store_indexed(T_SHORT ); break;
aoqi@0 2686 case Bytecodes::_pop : // fall through
aoqi@0 2687 case Bytecodes::_pop2 : // fall through
aoqi@0 2688 case Bytecodes::_dup : // fall through
aoqi@0 2689 case Bytecodes::_dup_x1 : // fall through
aoqi@0 2690 case Bytecodes::_dup_x2 : // fall through
aoqi@0 2691 case Bytecodes::_dup2 : // fall through
aoqi@0 2692 case Bytecodes::_dup2_x1 : // fall through
aoqi@0 2693 case Bytecodes::_dup2_x2 : // fall through
aoqi@0 2694 case Bytecodes::_swap : stack_op(code); break;
aoqi@0 2695 case Bytecodes::_iadd : arithmetic_op(intType , code); break;
aoqi@0 2696 case Bytecodes::_ladd : arithmetic_op(longType , code); break;
aoqi@0 2697 case Bytecodes::_fadd : arithmetic_op(floatType , code); break;
aoqi@0 2698 case Bytecodes::_dadd : arithmetic_op(doubleType, code); break;
aoqi@0 2699 case Bytecodes::_isub : arithmetic_op(intType , code); break;
aoqi@0 2700 case Bytecodes::_lsub : arithmetic_op(longType , code); break;
aoqi@0 2701 case Bytecodes::_fsub : arithmetic_op(floatType , code); break;
aoqi@0 2702 case Bytecodes::_dsub : arithmetic_op(doubleType, code); break;
aoqi@0 2703 case Bytecodes::_imul : arithmetic_op(intType , code); break;
aoqi@0 2704 case Bytecodes::_lmul : arithmetic_op(longType , code); break;
aoqi@0 2705 case Bytecodes::_fmul : arithmetic_op(floatType , code); break;
aoqi@0 2706 case Bytecodes::_dmul : arithmetic_op(doubleType, code); break;
aoqi@0 2707 case Bytecodes::_idiv : arithmetic_op(intType , code, copy_state_for_exception()); break;
aoqi@0 2708 case Bytecodes::_ldiv : arithmetic_op(longType , code, copy_state_for_exception()); break;
aoqi@0 2709 case Bytecodes::_fdiv : arithmetic_op(floatType , code); break;
aoqi@0 2710 case Bytecodes::_ddiv : arithmetic_op(doubleType, code); break;
aoqi@0 2711 case Bytecodes::_irem : arithmetic_op(intType , code, copy_state_for_exception()); break;
aoqi@0 2712 case Bytecodes::_lrem : arithmetic_op(longType , code, copy_state_for_exception()); break;
aoqi@0 2713 case Bytecodes::_frem : arithmetic_op(floatType , code); break;
aoqi@0 2714 case Bytecodes::_drem : arithmetic_op(doubleType, code); break;
aoqi@0 2715 case Bytecodes::_ineg : negate_op(intType ); break;
aoqi@0 2716 case Bytecodes::_lneg : negate_op(longType ); break;
aoqi@0 2717 case Bytecodes::_fneg : negate_op(floatType ); break;
aoqi@0 2718 case Bytecodes::_dneg : negate_op(doubleType); break;
aoqi@0 2719 case Bytecodes::_ishl : shift_op(intType , code); break;
aoqi@0 2720 case Bytecodes::_lshl : shift_op(longType, code); break;
aoqi@0 2721 case Bytecodes::_ishr : shift_op(intType , code); break;
aoqi@0 2722 case Bytecodes::_lshr : shift_op(longType, code); break;
aoqi@0 2723 case Bytecodes::_iushr : shift_op(intType , code); break;
aoqi@0 2724 case Bytecodes::_lushr : shift_op(longType, code); break;
aoqi@0 2725 case Bytecodes::_iand : logic_op(intType , code); break;
aoqi@0 2726 case Bytecodes::_land : logic_op(longType, code); break;
aoqi@0 2727 case Bytecodes::_ior : logic_op(intType , code); break;
aoqi@0 2728 case Bytecodes::_lor : logic_op(longType, code); break;
aoqi@0 2729 case Bytecodes::_ixor : logic_op(intType , code); break;
aoqi@0 2730 case Bytecodes::_lxor : logic_op(longType, code); break;
aoqi@0 2731 case Bytecodes::_iinc : increment(); break;
aoqi@0 2732 case Bytecodes::_i2l : convert(code, T_INT , T_LONG ); break;
aoqi@0 2733 case Bytecodes::_i2f : convert(code, T_INT , T_FLOAT ); break;
aoqi@0 2734 case Bytecodes::_i2d : convert(code, T_INT , T_DOUBLE); break;
aoqi@0 2735 case Bytecodes::_l2i : convert(code, T_LONG , T_INT ); break;
aoqi@0 2736 case Bytecodes::_l2f : convert(code, T_LONG , T_FLOAT ); break;
aoqi@0 2737 case Bytecodes::_l2d : convert(code, T_LONG , T_DOUBLE); break;
aoqi@0 2738 case Bytecodes::_f2i : convert(code, T_FLOAT , T_INT ); break;
aoqi@0 2739 case Bytecodes::_f2l : convert(code, T_FLOAT , T_LONG ); break;
aoqi@0 2740 case Bytecodes::_f2d : convert(code, T_FLOAT , T_DOUBLE); break;
aoqi@0 2741 case Bytecodes::_d2i : convert(code, T_DOUBLE, T_INT ); break;
aoqi@0 2742 case Bytecodes::_d2l : convert(code, T_DOUBLE, T_LONG ); break;
aoqi@0 2743 case Bytecodes::_d2f : convert(code, T_DOUBLE, T_FLOAT ); break;
aoqi@0 2744 case Bytecodes::_i2b : convert(code, T_INT , T_BYTE ); break;
aoqi@0 2745 case Bytecodes::_i2c : convert(code, T_INT , T_CHAR ); break;
aoqi@0 2746 case Bytecodes::_i2s : convert(code, T_INT , T_SHORT ); break;
aoqi@0 2747 case Bytecodes::_lcmp : compare_op(longType , code); break;
aoqi@0 2748 case Bytecodes::_fcmpl : compare_op(floatType , code); break;
aoqi@0 2749 case Bytecodes::_fcmpg : compare_op(floatType , code); break;
aoqi@0 2750 case Bytecodes::_dcmpl : compare_op(doubleType, code); break;
aoqi@0 2751 case Bytecodes::_dcmpg : compare_op(doubleType, code); break;
aoqi@0 2752 case Bytecodes::_ifeq : if_zero(intType , If::eql); break;
aoqi@0 2753 case Bytecodes::_ifne : if_zero(intType , If::neq); break;
aoqi@0 2754 case Bytecodes::_iflt : if_zero(intType , If::lss); break;
aoqi@0 2755 case Bytecodes::_ifge : if_zero(intType , If::geq); break;
aoqi@0 2756 case Bytecodes::_ifgt : if_zero(intType , If::gtr); break;
aoqi@0 2757 case Bytecodes::_ifle : if_zero(intType , If::leq); break;
aoqi@0 2758 case Bytecodes::_if_icmpeq : if_same(intType , If::eql); break;
aoqi@0 2759 case Bytecodes::_if_icmpne : if_same(intType , If::neq); break;
aoqi@0 2760 case Bytecodes::_if_icmplt : if_same(intType , If::lss); break;
aoqi@0 2761 case Bytecodes::_if_icmpge : if_same(intType , If::geq); break;
aoqi@0 2762 case Bytecodes::_if_icmpgt : if_same(intType , If::gtr); break;
aoqi@0 2763 case Bytecodes::_if_icmple : if_same(intType , If::leq); break;
aoqi@0 2764 case Bytecodes::_if_acmpeq : if_same(objectType, If::eql); break;
aoqi@0 2765 case Bytecodes::_if_acmpne : if_same(objectType, If::neq); break;
aoqi@0 2766 case Bytecodes::_goto : _goto(s.cur_bci(), s.get_dest()); break;
aoqi@0 2767 case Bytecodes::_jsr : jsr(s.get_dest()); break;
aoqi@0 2768 case Bytecodes::_ret : ret(s.get_index()); break;
aoqi@0 2769 case Bytecodes::_tableswitch : table_switch(); break;
aoqi@0 2770 case Bytecodes::_lookupswitch : lookup_switch(); break;
aoqi@0 2771 case Bytecodes::_ireturn : method_return(ipop()); break;
aoqi@0 2772 case Bytecodes::_lreturn : method_return(lpop()); break;
aoqi@0 2773 case Bytecodes::_freturn : method_return(fpop()); break;
aoqi@0 2774 case Bytecodes::_dreturn : method_return(dpop()); break;
aoqi@0 2775 case Bytecodes::_areturn : method_return(apop()); break;
aoqi@0 2776 case Bytecodes::_return : method_return(NULL ); break;
aoqi@0 2777 case Bytecodes::_getstatic : // fall through
aoqi@0 2778 case Bytecodes::_putstatic : // fall through
aoqi@0 2779 case Bytecodes::_getfield : // fall through
aoqi@0 2780 case Bytecodes::_putfield : access_field(code); break;
aoqi@0 2781 case Bytecodes::_invokevirtual : // fall through
aoqi@0 2782 case Bytecodes::_invokespecial : // fall through
aoqi@0 2783 case Bytecodes::_invokestatic : // fall through
aoqi@0 2784 case Bytecodes::_invokedynamic : // fall through
aoqi@0 2785 case Bytecodes::_invokeinterface: invoke(code); break;
aoqi@0 2786 case Bytecodes::_new : new_instance(s.get_index_u2()); break;
aoqi@0 2787 case Bytecodes::_newarray : new_type_array(); break;
aoqi@0 2788 case Bytecodes::_anewarray : new_object_array(); break;
aoqi@0 2789 case Bytecodes::_arraylength : { ValueStack* state_before = copy_state_for_exception(); ipush(append(new ArrayLength(apop(), state_before))); break; }
aoqi@0 2790 case Bytecodes::_athrow : throw_op(s.cur_bci()); break;
aoqi@0 2791 case Bytecodes::_checkcast : check_cast(s.get_index_u2()); break;
aoqi@0 2792 case Bytecodes::_instanceof : instance_of(s.get_index_u2()); break;
aoqi@0 2793 case Bytecodes::_monitorenter : monitorenter(apop(), s.cur_bci()); break;
aoqi@0 2794 case Bytecodes::_monitorexit : monitorexit (apop(), s.cur_bci()); break;
aoqi@0 2795 case Bytecodes::_wide : ShouldNotReachHere(); break;
aoqi@0 2796 case Bytecodes::_multianewarray : new_multi_array(s.cur_bcp()[3]); break;
aoqi@0 2797 case Bytecodes::_ifnull : if_null(objectType, If::eql); break;
aoqi@0 2798 case Bytecodes::_ifnonnull : if_null(objectType, If::neq); break;
aoqi@0 2799 case Bytecodes::_goto_w : _goto(s.cur_bci(), s.get_far_dest()); break;
aoqi@0 2800 case Bytecodes::_jsr_w : jsr(s.get_far_dest()); break;
aoqi@0 2801 case Bytecodes::_breakpoint : BAILOUT_("concurrent setting of breakpoint", NULL);
aoqi@0 2802 default : ShouldNotReachHere(); break;
aoqi@0 2803 }
aoqi@0 2804
aoqi@0 2805 if (log != NULL)
aoqi@0 2806 log->clear_context(); // skip marker if nothing was printed
aoqi@0 2807
aoqi@0 2808 // save current bci to setup Goto at the end
aoqi@0 2809 prev_bci = s.cur_bci();
aoqi@0 2810
aoqi@0 2811 }
aoqi@0 2812 CHECK_BAILOUT_(NULL);
aoqi@0 2813 // stop processing of this block (see try_inline_full)
aoqi@0 2814 if (_skip_block) {
aoqi@0 2815 _skip_block = false;
aoqi@0 2816 assert(_last && _last->as_BlockEnd(), "");
aoqi@0 2817 return _last->as_BlockEnd();
aoqi@0 2818 }
aoqi@0 2819 // if there are any, check if last instruction is a BlockEnd instruction
aoqi@0 2820 BlockEnd* end = last()->as_BlockEnd();
aoqi@0 2821 if (end == NULL) {
aoqi@0 2822 // all blocks must end with a BlockEnd instruction => add a Goto
aoqi@0 2823 end = new Goto(block_at(s.cur_bci()), false);
aoqi@0 2824 append(end);
aoqi@0 2825 }
aoqi@0 2826 assert(end == last()->as_BlockEnd(), "inconsistency");
aoqi@0 2827
aoqi@0 2828 assert(end->state() != NULL, "state must already be present");
aoqi@0 2829 assert(end->as_Return() == NULL || end->as_Throw() == NULL || end->state()->stack_size() == 0, "stack not needed for return and throw");
aoqi@0 2830
aoqi@0 2831 // connect to begin & set state
aoqi@0 2832 // NOTE that inlining may have changed the block we are parsing
aoqi@0 2833 block()->set_end(end);
aoqi@0 2834 // propagate state
aoqi@0 2835 for (int i = end->number_of_sux() - 1; i >= 0; i--) {
aoqi@0 2836 BlockBegin* sux = end->sux_at(i);
aoqi@0 2837 assert(sux->is_predecessor(block()), "predecessor missing");
aoqi@0 2838 // be careful, bailout if bytecodes are strange
aoqi@0 2839 if (!sux->try_merge(end->state())) BAILOUT_("block join failed", NULL);
aoqi@0 2840 scope_data()->add_to_work_list(end->sux_at(i));
aoqi@0 2841 }
aoqi@0 2842
aoqi@0 2843 scope_data()->set_stream(NULL);
aoqi@0 2844
aoqi@0 2845 // done
aoqi@0 2846 return end;
aoqi@0 2847 }
aoqi@0 2848
aoqi@0 2849
aoqi@0 2850 void GraphBuilder::iterate_all_blocks(bool start_in_current_block_for_inlining) {
aoqi@0 2851 do {
aoqi@0 2852 if (start_in_current_block_for_inlining && !bailed_out()) {
aoqi@0 2853 iterate_bytecodes_for_block(0);
aoqi@0 2854 start_in_current_block_for_inlining = false;
aoqi@0 2855 } else {
aoqi@0 2856 BlockBegin* b;
aoqi@0 2857 while ((b = scope_data()->remove_from_work_list()) != NULL) {
aoqi@0 2858 if (!b->is_set(BlockBegin::was_visited_flag)) {
aoqi@0 2859 if (b->is_set(BlockBegin::osr_entry_flag)) {
aoqi@0 2860 // we're about to parse the osr entry block, so make sure
aoqi@0 2861 // we setup the OSR edge leading into this block so that
aoqi@0 2862 // Phis get setup correctly.
aoqi@0 2863 setup_osr_entry_block();
aoqi@0 2864 // this is no longer the osr entry block, so clear it.
aoqi@0 2865 b->clear(BlockBegin::osr_entry_flag);
aoqi@0 2866 }
aoqi@0 2867 b->set(BlockBegin::was_visited_flag);
aoqi@0 2868 connect_to_end(b);
aoqi@0 2869 }
aoqi@0 2870 }
aoqi@0 2871 }
aoqi@0 2872 } while (!bailed_out() && !scope_data()->is_work_list_empty());
aoqi@0 2873 }
aoqi@0 2874
aoqi@0 2875
aoqi@0 2876 bool GraphBuilder::_can_trap [Bytecodes::number_of_java_codes];
aoqi@0 2877
aoqi@0 2878 void GraphBuilder::initialize() {
aoqi@0 2879 // the following bytecodes are assumed to potentially
aoqi@0 2880 // throw exceptions in compiled code - note that e.g.
aoqi@0 2881 // monitorexit & the return bytecodes do not throw
aoqi@0 2882 // exceptions since monitor pairing proved that they
aoqi@0 2883 // succeed (if monitor pairing succeeded)
aoqi@0 2884 Bytecodes::Code can_trap_list[] =
aoqi@0 2885 { Bytecodes::_ldc
aoqi@0 2886 , Bytecodes::_ldc_w
aoqi@0 2887 , Bytecodes::_ldc2_w
aoqi@0 2888 , Bytecodes::_iaload
aoqi@0 2889 , Bytecodes::_laload
aoqi@0 2890 , Bytecodes::_faload
aoqi@0 2891 , Bytecodes::_daload
aoqi@0 2892 , Bytecodes::_aaload
aoqi@0 2893 , Bytecodes::_baload
aoqi@0 2894 , Bytecodes::_caload
aoqi@0 2895 , Bytecodes::_saload
aoqi@0 2896 , Bytecodes::_iastore
aoqi@0 2897 , Bytecodes::_lastore
aoqi@0 2898 , Bytecodes::_fastore
aoqi@0 2899 , Bytecodes::_dastore
aoqi@0 2900 , Bytecodes::_aastore
aoqi@0 2901 , Bytecodes::_bastore
aoqi@0 2902 , Bytecodes::_castore
aoqi@0 2903 , Bytecodes::_sastore
aoqi@0 2904 , Bytecodes::_idiv
aoqi@0 2905 , Bytecodes::_ldiv
aoqi@0 2906 , Bytecodes::_irem
aoqi@0 2907 , Bytecodes::_lrem
aoqi@0 2908 , Bytecodes::_getstatic
aoqi@0 2909 , Bytecodes::_putstatic
aoqi@0 2910 , Bytecodes::_getfield
aoqi@0 2911 , Bytecodes::_putfield
aoqi@0 2912 , Bytecodes::_invokevirtual
aoqi@0 2913 , Bytecodes::_invokespecial
aoqi@0 2914 , Bytecodes::_invokestatic
aoqi@0 2915 , Bytecodes::_invokedynamic
aoqi@0 2916 , Bytecodes::_invokeinterface
aoqi@0 2917 , Bytecodes::_new
aoqi@0 2918 , Bytecodes::_newarray
aoqi@0 2919 , Bytecodes::_anewarray
aoqi@0 2920 , Bytecodes::_arraylength
aoqi@0 2921 , Bytecodes::_athrow
aoqi@0 2922 , Bytecodes::_checkcast
aoqi@0 2923 , Bytecodes::_instanceof
aoqi@0 2924 , Bytecodes::_monitorenter
aoqi@0 2925 , Bytecodes::_multianewarray
aoqi@0 2926 };
aoqi@0 2927
aoqi@0 2928 // inititialize trap tables
aoqi@0 2929 for (int i = 0; i < Bytecodes::number_of_java_codes; i++) {
aoqi@0 2930 _can_trap[i] = false;
aoqi@0 2931 }
aoqi@0 2932 // set standard trap info
aoqi@0 2933 for (uint j = 0; j < ARRAY_SIZE(can_trap_list); j++) {
aoqi@0 2934 _can_trap[can_trap_list[j]] = true;
aoqi@0 2935 }
aoqi@0 2936 }
aoqi@0 2937
aoqi@0 2938
aoqi@0 2939 BlockBegin* GraphBuilder::header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state) {
aoqi@0 2940 assert(entry->is_set(f), "entry/flag mismatch");
aoqi@0 2941 // create header block
aoqi@0 2942 BlockBegin* h = new BlockBegin(entry->bci());
aoqi@0 2943 h->set_depth_first_number(0);
aoqi@0 2944
aoqi@0 2945 Value l = h;
aoqi@0 2946 BlockEnd* g = new Goto(entry, false);
aoqi@0 2947 l->set_next(g, entry->bci());
aoqi@0 2948 h->set_end(g);
aoqi@0 2949 h->set(f);
aoqi@0 2950 // setup header block end state
aoqi@0 2951 ValueStack* s = state->copy(ValueStack::StateAfter, entry->bci()); // can use copy since stack is empty (=> no phis)
aoqi@0 2952 assert(s->stack_is_empty(), "must have empty stack at entry point");
aoqi@0 2953 g->set_state(s);
aoqi@0 2954 return h;
aoqi@0 2955 }
aoqi@0 2956
aoqi@0 2957
aoqi@0 2958
aoqi@0 2959 BlockBegin* GraphBuilder::setup_start_block(int osr_bci, BlockBegin* std_entry, BlockBegin* osr_entry, ValueStack* state) {
aoqi@0 2960 BlockBegin* start = new BlockBegin(0);
aoqi@0 2961
aoqi@0 2962 // This code eliminates the empty start block at the beginning of
aoqi@0 2963 // each method. Previously, each method started with the
aoqi@0 2964 // start-block created below, and this block was followed by the
aoqi@0 2965 // header block that was always empty. This header block is only
aoqi@0 2966 // necesary if std_entry is also a backward branch target because
aoqi@0 2967 // then phi functions may be necessary in the header block. It's
aoqi@0 2968 // also necessary when profiling so that there's a single block that
aoqi@0 2969 // can increment the interpreter_invocation_count.
aoqi@0 2970 BlockBegin* new_header_block;
aoqi@0 2971 if (std_entry->number_of_preds() > 0 || count_invocations() || count_backedges()) {
aoqi@0 2972 new_header_block = header_block(std_entry, BlockBegin::std_entry_flag, state);
aoqi@0 2973 } else {
aoqi@0 2974 new_header_block = std_entry;
aoqi@0 2975 }
aoqi@0 2976
aoqi@0 2977 // setup start block (root for the IR graph)
aoqi@0 2978 Base* base =
aoqi@0 2979 new Base(
aoqi@0 2980 new_header_block,
aoqi@0 2981 osr_entry
aoqi@0 2982 );
aoqi@0 2983 start->set_next(base, 0);
aoqi@0 2984 start->set_end(base);
aoqi@0 2985 // create & setup state for start block
aoqi@0 2986 start->set_state(state->copy(ValueStack::StateAfter, std_entry->bci()));
aoqi@0 2987 base->set_state(state->copy(ValueStack::StateAfter, std_entry->bci()));
aoqi@0 2988
aoqi@0 2989 if (base->std_entry()->state() == NULL) {
aoqi@0 2990 // setup states for header blocks
aoqi@0 2991 base->std_entry()->merge(state);
aoqi@0 2992 }
aoqi@0 2993
aoqi@0 2994 assert(base->std_entry()->state() != NULL, "");
aoqi@0 2995 return start;
aoqi@0 2996 }
aoqi@0 2997
aoqi@0 2998
aoqi@0 2999 void GraphBuilder::setup_osr_entry_block() {
aoqi@0 3000 assert(compilation()->is_osr_compile(), "only for osrs");
aoqi@0 3001
aoqi@0 3002 int osr_bci = compilation()->osr_bci();
aoqi@0 3003 ciBytecodeStream s(method());
aoqi@0 3004 s.reset_to_bci(osr_bci);
aoqi@0 3005 s.next();
aoqi@0 3006 scope_data()->set_stream(&s);
aoqi@0 3007
aoqi@0 3008 // create a new block to be the osr setup code
aoqi@0 3009 _osr_entry = new BlockBegin(osr_bci);
aoqi@0 3010 _osr_entry->set(BlockBegin::osr_entry_flag);
aoqi@0 3011 _osr_entry->set_depth_first_number(0);
aoqi@0 3012 BlockBegin* target = bci2block()->at(osr_bci);
aoqi@0 3013 assert(target != NULL && target->is_set(BlockBegin::osr_entry_flag), "must be there");
aoqi@0 3014 // the osr entry has no values for locals
aoqi@0 3015 ValueStack* state = target->state()->copy();
aoqi@0 3016 _osr_entry->set_state(state);
aoqi@0 3017
aoqi@0 3018 kill_all();
aoqi@0 3019 _block = _osr_entry;
aoqi@0 3020 _state = _osr_entry->state()->copy();
aoqi@0 3021 assert(_state->bci() == osr_bci, "mismatch");
aoqi@0 3022 _last = _osr_entry;
aoqi@0 3023 Value e = append(new OsrEntry());
aoqi@0 3024 e->set_needs_null_check(false);
aoqi@0 3025
aoqi@0 3026 // OSR buffer is
aoqi@0 3027 //
aoqi@0 3028 // locals[nlocals-1..0]
aoqi@0 3029 // monitors[number_of_locks-1..0]
aoqi@0 3030 //
aoqi@0 3031 // locals is a direct copy of the interpreter frame so in the osr buffer
aoqi@0 3032 // so first slot in the local array is the last local from the interpreter
aoqi@0 3033 // and last slot is local[0] (receiver) from the interpreter
aoqi@0 3034 //
aoqi@0 3035 // Similarly with locks. The first lock slot in the osr buffer is the nth lock
aoqi@0 3036 // from the interpreter frame, the nth lock slot in the osr buffer is 0th lock
aoqi@0 3037 // in the interpreter frame (the method lock if a sync method)
aoqi@0 3038
aoqi@0 3039 // Initialize monitors in the compiled activation.
aoqi@0 3040
aoqi@0 3041 int index;
aoqi@0 3042 Value local;
aoqi@0 3043
aoqi@0 3044 // find all the locals that the interpreter thinks contain live oops
aoqi@0 3045 const BitMap live_oops = method()->live_local_oops_at_bci(osr_bci);
aoqi@0 3046
aoqi@0 3047 // compute the offset into the locals so that we can treat the buffer
aoqi@0 3048 // as if the locals were still in the interpreter frame
aoqi@0 3049 int locals_offset = BytesPerWord * (method()->max_locals() - 1);
aoqi@0 3050 for_each_local_value(state, index, local) {
aoqi@0 3051 int offset = locals_offset - (index + local->type()->size() - 1) * BytesPerWord;
aoqi@0 3052 Value get;
aoqi@0 3053 if (local->type()->is_object_kind() && !live_oops.at(index)) {
aoqi@0 3054 // The interpreter thinks this local is dead but the compiler
aoqi@0 3055 // doesn't so pretend that the interpreter passed in null.
aoqi@0 3056 get = append(new Constant(objectNull));
aoqi@0 3057 } else {
aoqi@0 3058 get = append(new UnsafeGetRaw(as_BasicType(local->type()), e,
aoqi@0 3059 append(new Constant(new IntConstant(offset))),
aoqi@0 3060 0,
aoqi@0 3061 true /*unaligned*/, true /*wide*/));
aoqi@0 3062 }
aoqi@0 3063 _state->store_local(index, get);
aoqi@0 3064 }
aoqi@0 3065
aoqi@0 3066 // the storage for the OSR buffer is freed manually in the LIRGenerator.
aoqi@0 3067
aoqi@0 3068 assert(state->caller_state() == NULL, "should be top scope");
aoqi@0 3069 state->clear_locals();
aoqi@0 3070 Goto* g = new Goto(target, false);
aoqi@0 3071 append(g);
aoqi@0 3072 _osr_entry->set_end(g);
aoqi@0 3073 target->merge(_osr_entry->end()->state());
aoqi@0 3074
aoqi@0 3075 scope_data()->set_stream(NULL);
aoqi@0 3076 }
aoqi@0 3077
aoqi@0 3078
aoqi@0 3079 ValueStack* GraphBuilder::state_at_entry() {
aoqi@0 3080 ValueStack* state = new ValueStack(scope(), NULL);
aoqi@0 3081
aoqi@0 3082 // Set up locals for receiver
aoqi@0 3083 int idx = 0;
aoqi@0 3084 if (!method()->is_static()) {
aoqi@0 3085 // we should always see the receiver
aoqi@0 3086 state->store_local(idx, new Local(method()->holder(), objectType, idx));
aoqi@0 3087 idx = 1;
aoqi@0 3088 }
aoqi@0 3089
aoqi@0 3090 // Set up locals for incoming arguments
aoqi@0 3091 ciSignature* sig = method()->signature();
aoqi@0 3092 for (int i = 0; i < sig->count(); i++) {
aoqi@0 3093 ciType* type = sig->type_at(i);
aoqi@0 3094 BasicType basic_type = type->basic_type();
aoqi@0 3095 // don't allow T_ARRAY to propagate into locals types
aoqi@0 3096 if (basic_type == T_ARRAY) basic_type = T_OBJECT;
aoqi@0 3097 ValueType* vt = as_ValueType(basic_type);
aoqi@0 3098 state->store_local(idx, new Local(type, vt, idx));
aoqi@0 3099 idx += type->size();
aoqi@0 3100 }
aoqi@0 3101
aoqi@0 3102 // lock synchronized method
aoqi@0 3103 if (method()->is_synchronized()) {
aoqi@0 3104 state->lock(NULL);
aoqi@0 3105 }
aoqi@0 3106
aoqi@0 3107 return state;
aoqi@0 3108 }
aoqi@0 3109
aoqi@0 3110
aoqi@0 3111 GraphBuilder::GraphBuilder(Compilation* compilation, IRScope* scope)
aoqi@0 3112 : _scope_data(NULL)
aoqi@0 3113 , _instruction_count(0)
aoqi@0 3114 , _osr_entry(NULL)
aoqi@0 3115 , _memory(new MemoryBuffer())
aoqi@0 3116 , _compilation(compilation)
aoqi@0 3117 , _inline_bailout_msg(NULL)
aoqi@0 3118 {
aoqi@0 3119 int osr_bci = compilation->osr_bci();
aoqi@0 3120
aoqi@0 3121 // determine entry points and bci2block mapping
aoqi@0 3122 BlockListBuilder blm(compilation, scope, osr_bci);
aoqi@0 3123 CHECK_BAILOUT();
aoqi@0 3124
aoqi@0 3125 BlockList* bci2block = blm.bci2block();
aoqi@0 3126 BlockBegin* start_block = bci2block->at(0);
aoqi@0 3127
aoqi@0 3128 push_root_scope(scope, bci2block, start_block);
aoqi@0 3129
aoqi@0 3130 // setup state for std entry
aoqi@0 3131 _initial_state = state_at_entry();
aoqi@0 3132 start_block->merge(_initial_state);
aoqi@0 3133
aoqi@0 3134 // complete graph
aoqi@0 3135 _vmap = new ValueMap();
aoqi@0 3136 switch (scope->method()->intrinsic_id()) {
aoqi@0 3137 case vmIntrinsics::_dabs : // fall through
aoqi@0 3138 case vmIntrinsics::_dsqrt : // fall through
aoqi@0 3139 case vmIntrinsics::_dsin : // fall through
aoqi@0 3140 case vmIntrinsics::_dcos : // fall through
aoqi@0 3141 case vmIntrinsics::_dtan : // fall through
aoqi@0 3142 case vmIntrinsics::_dlog : // fall through
aoqi@0 3143 case vmIntrinsics::_dlog10 : // fall through
aoqi@0 3144 case vmIntrinsics::_dexp : // fall through
aoqi@0 3145 case vmIntrinsics::_dpow : // fall through
aoqi@0 3146 {
aoqi@0 3147 // Compiles where the root method is an intrinsic need a special
aoqi@0 3148 // compilation environment because the bytecodes for the method
aoqi@0 3149 // shouldn't be parsed during the compilation, only the special
aoqi@0 3150 // Intrinsic node should be emitted. If this isn't done the the
aoqi@0 3151 // code for the inlined version will be different than the root
aoqi@0 3152 // compiled version which could lead to monotonicity problems on
aoqi@0 3153 // intel.
aoqi@0 3154
aoqi@0 3155 // Set up a stream so that appending instructions works properly.
aoqi@0 3156 ciBytecodeStream s(scope->method());
aoqi@0 3157 s.reset_to_bci(0);
aoqi@0 3158 scope_data()->set_stream(&s);
aoqi@0 3159 s.next();
aoqi@0 3160
aoqi@0 3161 // setup the initial block state
aoqi@0 3162 _block = start_block;
aoqi@0 3163 _state = start_block->state()->copy_for_parsing();
aoqi@0 3164 _last = start_block;
aoqi@0 3165 load_local(doubleType, 0);
aoqi@0 3166 if (scope->method()->intrinsic_id() == vmIntrinsics::_dpow) {
aoqi@0 3167 load_local(doubleType, 2);
aoqi@0 3168 }
aoqi@0 3169
aoqi@0 3170 // Emit the intrinsic node.
aoqi@0 3171 bool result = try_inline_intrinsics(scope->method());
aoqi@0 3172 if (!result) BAILOUT("failed to inline intrinsic");
aoqi@0 3173 method_return(dpop());
aoqi@0 3174
aoqi@0 3175 // connect the begin and end blocks and we're all done.
aoqi@0 3176 BlockEnd* end = last()->as_BlockEnd();
aoqi@0 3177 block()->set_end(end);
aoqi@0 3178 break;
aoqi@0 3179 }
aoqi@0 3180
aoqi@0 3181 case vmIntrinsics::_Reference_get:
aoqi@0 3182 {
aoqi@0 3183 {
aoqi@0 3184 // With java.lang.ref.reference.get() we must go through the
aoqi@0 3185 // intrinsic - when G1 is enabled - even when get() is the root
aoqi@0 3186 // method of the compile so that, if necessary, the value in
aoqi@0 3187 // the referent field of the reference object gets recorded by
aoqi@0 3188 // the pre-barrier code.
aoqi@0 3189 // Specifically, if G1 is enabled, the value in the referent
aoqi@0 3190 // field is recorded by the G1 SATB pre barrier. This will
aoqi@0 3191 // result in the referent being marked live and the reference
aoqi@0 3192 // object removed from the list of discovered references during
aoqi@0 3193 // reference processing.
aoqi@0 3194
aoqi@0 3195 // Also we need intrinsic to prevent commoning reads from this field
aoqi@0 3196 // across safepoint since GC can change its value.
aoqi@0 3197
aoqi@0 3198 // Set up a stream so that appending instructions works properly.
aoqi@0 3199 ciBytecodeStream s(scope->method());
aoqi@0 3200 s.reset_to_bci(0);
aoqi@0 3201 scope_data()->set_stream(&s);
aoqi@0 3202 s.next();
aoqi@0 3203
aoqi@0 3204 // setup the initial block state
aoqi@0 3205 _block = start_block;
aoqi@0 3206 _state = start_block->state()->copy_for_parsing();
aoqi@0 3207 _last = start_block;
aoqi@0 3208 load_local(objectType, 0);
aoqi@0 3209
aoqi@0 3210 // Emit the intrinsic node.
aoqi@0 3211 bool result = try_inline_intrinsics(scope->method());
aoqi@0 3212 if (!result) BAILOUT("failed to inline intrinsic");
aoqi@0 3213 method_return(apop());
aoqi@0 3214
aoqi@0 3215 // connect the begin and end blocks and we're all done.
aoqi@0 3216 BlockEnd* end = last()->as_BlockEnd();
aoqi@0 3217 block()->set_end(end);
aoqi@0 3218 break;
aoqi@0 3219 }
aoqi@0 3220 // Otherwise, fall thru
aoqi@0 3221 }
aoqi@0 3222
aoqi@0 3223 default:
aoqi@0 3224 scope_data()->add_to_work_list(start_block);
aoqi@0 3225 iterate_all_blocks();
aoqi@0 3226 break;
aoqi@0 3227 }
aoqi@0 3228 CHECK_BAILOUT();
aoqi@0 3229
aoqi@0 3230 _start = setup_start_block(osr_bci, start_block, _osr_entry, _initial_state);
aoqi@0 3231
aoqi@0 3232 eliminate_redundant_phis(_start);
aoqi@0 3233
aoqi@0 3234 NOT_PRODUCT(if (PrintValueNumbering && Verbose) print_stats());
aoqi@0 3235 // for osr compile, bailout if some requirements are not fulfilled
aoqi@0 3236 if (osr_bci != -1) {
aoqi@0 3237 BlockBegin* osr_block = blm.bci2block()->at(osr_bci);
aoqi@0 3238 assert(osr_block->is_set(BlockBegin::was_visited_flag),"osr entry must have been visited for osr compile");
aoqi@0 3239
aoqi@0 3240 // check if osr entry point has empty stack - we cannot handle non-empty stacks at osr entry points
aoqi@0 3241 if (!osr_block->state()->stack_is_empty()) {
aoqi@0 3242 BAILOUT("stack not empty at OSR entry point");
aoqi@0 3243 }
aoqi@0 3244 }
aoqi@0 3245 #ifndef PRODUCT
aoqi@0 3246 if (PrintCompilation && Verbose) tty->print_cr("Created %d Instructions", _instruction_count);
aoqi@0 3247 #endif
aoqi@0 3248 }
aoqi@0 3249
aoqi@0 3250
aoqi@0 3251 ValueStack* GraphBuilder::copy_state_before() {
aoqi@0 3252 return copy_state_before_with_bci(bci());
aoqi@0 3253 }
aoqi@0 3254
aoqi@0 3255 ValueStack* GraphBuilder::copy_state_exhandling() {
aoqi@0 3256 return copy_state_exhandling_with_bci(bci());
aoqi@0 3257 }
aoqi@0 3258
aoqi@0 3259 ValueStack* GraphBuilder::copy_state_for_exception() {
aoqi@0 3260 return copy_state_for_exception_with_bci(bci());
aoqi@0 3261 }
aoqi@0 3262
aoqi@0 3263 ValueStack* GraphBuilder::copy_state_before_with_bci(int bci) {
aoqi@0 3264 return state()->copy(ValueStack::StateBefore, bci);
aoqi@0 3265 }
aoqi@0 3266
aoqi@0 3267 ValueStack* GraphBuilder::copy_state_exhandling_with_bci(int bci) {
aoqi@0 3268 if (!has_handler()) return NULL;
aoqi@0 3269 return state()->copy(ValueStack::StateBefore, bci);
aoqi@0 3270 }
aoqi@0 3271
aoqi@0 3272 ValueStack* GraphBuilder::copy_state_for_exception_with_bci(int bci) {
aoqi@0 3273 ValueStack* s = copy_state_exhandling_with_bci(bci);
aoqi@0 3274 if (s == NULL) {
aoqi@0 3275 if (_compilation->env()->jvmti_can_access_local_variables()) {
aoqi@0 3276 s = state()->copy(ValueStack::ExceptionState, bci);
aoqi@0 3277 } else {
aoqi@0 3278 s = state()->copy(ValueStack::EmptyExceptionState, bci);
aoqi@0 3279 }
aoqi@0 3280 }
aoqi@0 3281 return s;
aoqi@0 3282 }
aoqi@0 3283
aoqi@0 3284 int GraphBuilder::recursive_inline_level(ciMethod* cur_callee) const {
aoqi@0 3285 int recur_level = 0;
aoqi@0 3286 for (IRScope* s = scope(); s != NULL; s = s->caller()) {
aoqi@0 3287 if (s->method() == cur_callee) {
aoqi@0 3288 ++recur_level;
aoqi@0 3289 }
aoqi@0 3290 }
aoqi@0 3291 return recur_level;
aoqi@0 3292 }
aoqi@0 3293
aoqi@0 3294
aoqi@0 3295 bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, Bytecodes::Code bc, Value receiver) {
aoqi@0 3296 const char* msg = NULL;
aoqi@0 3297
aoqi@0 3298 // clear out any existing inline bailout condition
aoqi@0 3299 clear_inline_bailout();
aoqi@0 3300
aoqi@0 3301 // exclude methods we don't want to inline
aoqi@0 3302 msg = should_not_inline(callee);
aoqi@0 3303 if (msg != NULL) {
aoqi@0 3304 print_inlining(callee, msg, /*success*/ false);
aoqi@0 3305 return false;
aoqi@0 3306 }
aoqi@0 3307
aoqi@0 3308 // method handle invokes
aoqi@0 3309 if (callee->is_method_handle_intrinsic()) {
aoqi@0 3310 return try_method_handle_inline(callee);
aoqi@0 3311 }
aoqi@0 3312
aoqi@0 3313 // handle intrinsics
aoqi@0 3314 if (callee->intrinsic_id() != vmIntrinsics::_none) {
aoqi@0 3315 if (try_inline_intrinsics(callee)) {
aoqi@0 3316 print_inlining(callee, "intrinsic");
aoqi@0 3317 return true;
aoqi@0 3318 }
aoqi@0 3319 // try normal inlining
aoqi@0 3320 }
aoqi@0 3321
aoqi@0 3322 // certain methods cannot be parsed at all
aoqi@0 3323 msg = check_can_parse(callee);
aoqi@0 3324 if (msg != NULL) {
aoqi@0 3325 print_inlining(callee, msg, /*success*/ false);
aoqi@0 3326 return false;
aoqi@0 3327 }
aoqi@0 3328
aoqi@0 3329 // If bytecode not set use the current one.
aoqi@0 3330 if (bc == Bytecodes::_illegal) {
aoqi@0 3331 bc = code();
aoqi@0 3332 }
aoqi@0 3333 if (try_inline_full(callee, holder_known, bc, receiver))
aoqi@0 3334 return true;
aoqi@0 3335
aoqi@0 3336 // Entire compilation could fail during try_inline_full call.
aoqi@0 3337 // In that case printing inlining decision info is useless.
aoqi@0 3338 if (!bailed_out())
aoqi@0 3339 print_inlining(callee, _inline_bailout_msg, /*success*/ false);
aoqi@0 3340
aoqi@0 3341 return false;
aoqi@0 3342 }
aoqi@0 3343
aoqi@0 3344
aoqi@0 3345 const char* GraphBuilder::check_can_parse(ciMethod* callee) const {
aoqi@0 3346 // Certain methods cannot be parsed at all:
aoqi@0 3347 if ( callee->is_native()) return "native method";
aoqi@0 3348 if ( callee->is_abstract()) return "abstract method";
aoqi@0 3349 if (!callee->can_be_compiled()) return "not compilable (disabled)";
aoqi@0 3350 return NULL;
aoqi@0 3351 }
aoqi@0 3352
aoqi@0 3353
aoqi@0 3354 // negative filter: should callee NOT be inlined? returns NULL, ok to inline, or rejection msg
aoqi@0 3355 const char* GraphBuilder::should_not_inline(ciMethod* callee) const {
aoqi@0 3356 if ( callee->should_exclude()) return "excluded by CompilerOracle";
aoqi@0 3357 if ( callee->should_not_inline()) return "disallowed by CompilerOracle";
aoqi@0 3358 if ( callee->dont_inline()) return "don't inline by annotation";
aoqi@0 3359 return NULL;
aoqi@0 3360 }
aoqi@0 3361
aoqi@0 3362
aoqi@0 3363 bool GraphBuilder::try_inline_intrinsics(ciMethod* callee) {
aoqi@0 3364 if (callee->is_synchronized()) {
aoqi@0 3365 // We don't currently support any synchronized intrinsics
aoqi@0 3366 return false;
aoqi@0 3367 }
aoqi@0 3368
aoqi@0 3369 // callee seems like a good candidate
aoqi@0 3370 // determine id
aoqi@0 3371 vmIntrinsics::ID id = callee->intrinsic_id();
aoqi@0 3372 if (!InlineNatives && id != vmIntrinsics::_Reference_get) {
aoqi@0 3373 // InlineNatives does not control Reference.get
aoqi@0 3374 INLINE_BAILOUT("intrinsic method inlining disabled");
aoqi@0 3375 }
aoqi@0 3376 bool preserves_state = false;
aoqi@0 3377 bool cantrap = true;
aoqi@0 3378 switch (id) {
aoqi@0 3379 case vmIntrinsics::_arraycopy:
aoqi@0 3380 if (!InlineArrayCopy) return false;
aoqi@0 3381 break;
aoqi@0 3382
aoqi@0 3383 #ifdef TRACE_HAVE_INTRINSICS
aoqi@0 3384 case vmIntrinsics::_classID:
aoqi@0 3385 case vmIntrinsics::_threadID:
aoqi@0 3386 preserves_state = true;
aoqi@0 3387 cantrap = true;
aoqi@0 3388 break;
aoqi@0 3389
aoqi@0 3390 case vmIntrinsics::_counterTime:
aoqi@0 3391 preserves_state = true;
aoqi@0 3392 cantrap = false;
aoqi@0 3393 break;
aoqi@0 3394 #endif
aoqi@0 3395
aoqi@0 3396 case vmIntrinsics::_currentTimeMillis:
aoqi@0 3397 case vmIntrinsics::_nanoTime:
aoqi@0 3398 preserves_state = true;
aoqi@0 3399 cantrap = false;
aoqi@0 3400 break;
aoqi@0 3401
aoqi@0 3402 case vmIntrinsics::_floatToRawIntBits :
aoqi@0 3403 case vmIntrinsics::_intBitsToFloat :
aoqi@0 3404 case vmIntrinsics::_doubleToRawLongBits :
aoqi@0 3405 case vmIntrinsics::_longBitsToDouble :
aoqi@0 3406 if (!InlineMathNatives) return false;
aoqi@0 3407 preserves_state = true;
aoqi@0 3408 cantrap = false;
aoqi@0 3409 break;
aoqi@0 3410
aoqi@0 3411 case vmIntrinsics::_getClass :
aoqi@0 3412 case vmIntrinsics::_isInstance :
aoqi@0 3413 if (!InlineClassNatives) return false;
aoqi@0 3414 preserves_state = true;
aoqi@0 3415 break;
aoqi@0 3416
aoqi@0 3417 case vmIntrinsics::_currentThread :
aoqi@0 3418 if (!InlineThreadNatives) return false;
aoqi@0 3419 preserves_state = true;
aoqi@0 3420 cantrap = false;
aoqi@0 3421 break;
aoqi@0 3422
aoqi@0 3423 case vmIntrinsics::_dabs : // fall through
aoqi@0 3424 case vmIntrinsics::_dsqrt : // fall through
aoqi@0 3425 case vmIntrinsics::_dsin : // fall through
aoqi@0 3426 case vmIntrinsics::_dcos : // fall through
aoqi@0 3427 case vmIntrinsics::_dtan : // fall through
aoqi@0 3428 case vmIntrinsics::_dlog : // fall through
aoqi@0 3429 case vmIntrinsics::_dlog10 : // fall through
aoqi@0 3430 case vmIntrinsics::_dexp : // fall through
aoqi@0 3431 case vmIntrinsics::_dpow : // fall through
aoqi@0 3432 if (!InlineMathNatives) return false;
aoqi@0 3433 cantrap = false;
aoqi@0 3434 preserves_state = true;
aoqi@0 3435 break;
aoqi@0 3436
aoqi@0 3437 // Use special nodes for Unsafe instructions so we can more easily
aoqi@0 3438 // perform an address-mode optimization on the raw variants
aoqi@0 3439 case vmIntrinsics::_getObject : return append_unsafe_get_obj(callee, T_OBJECT, false);
aoqi@0 3440 case vmIntrinsics::_getBoolean: return append_unsafe_get_obj(callee, T_BOOLEAN, false);
aoqi@0 3441 case vmIntrinsics::_getByte : return append_unsafe_get_obj(callee, T_BYTE, false);
aoqi@0 3442 case vmIntrinsics::_getShort : return append_unsafe_get_obj(callee, T_SHORT, false);
aoqi@0 3443 case vmIntrinsics::_getChar : return append_unsafe_get_obj(callee, T_CHAR, false);
aoqi@0 3444 case vmIntrinsics::_getInt : return append_unsafe_get_obj(callee, T_INT, false);
aoqi@0 3445 case vmIntrinsics::_getLong : return append_unsafe_get_obj(callee, T_LONG, false);
aoqi@0 3446 case vmIntrinsics::_getFloat : return append_unsafe_get_obj(callee, T_FLOAT, false);
aoqi@0 3447 case vmIntrinsics::_getDouble : return append_unsafe_get_obj(callee, T_DOUBLE, false);
aoqi@0 3448
aoqi@0 3449 case vmIntrinsics::_putObject : return append_unsafe_put_obj(callee, T_OBJECT, false);
aoqi@0 3450 case vmIntrinsics::_putBoolean: return append_unsafe_put_obj(callee, T_BOOLEAN, false);
aoqi@0 3451 case vmIntrinsics::_putByte : return append_unsafe_put_obj(callee, T_BYTE, false);
aoqi@0 3452 case vmIntrinsics::_putShort : return append_unsafe_put_obj(callee, T_SHORT, false);
aoqi@0 3453 case vmIntrinsics::_putChar : return append_unsafe_put_obj(callee, T_CHAR, false);
aoqi@0 3454 case vmIntrinsics::_putInt : return append_unsafe_put_obj(callee, T_INT, false);
aoqi@0 3455 case vmIntrinsics::_putLong : return append_unsafe_put_obj(callee, T_LONG, false);
aoqi@0 3456 case vmIntrinsics::_putFloat : return append_unsafe_put_obj(callee, T_FLOAT, false);
aoqi@0 3457 case vmIntrinsics::_putDouble : return append_unsafe_put_obj(callee, T_DOUBLE, false);
aoqi@0 3458
aoqi@0 3459 case vmIntrinsics::_getObjectVolatile : return append_unsafe_get_obj(callee, T_OBJECT, true);
aoqi@0 3460 case vmIntrinsics::_getBooleanVolatile: return append_unsafe_get_obj(callee, T_BOOLEAN, true);
aoqi@0 3461 case vmIntrinsics::_getByteVolatile : return append_unsafe_get_obj(callee, T_BYTE, true);
aoqi@0 3462 case vmIntrinsics::_getShortVolatile : return append_unsafe_get_obj(callee, T_SHORT, true);
aoqi@0 3463 case vmIntrinsics::_getCharVolatile : return append_unsafe_get_obj(callee, T_CHAR, true);
aoqi@0 3464 case vmIntrinsics::_getIntVolatile : return append_unsafe_get_obj(callee, T_INT, true);
aoqi@0 3465 case vmIntrinsics::_getLongVolatile : return append_unsafe_get_obj(callee, T_LONG, true);
aoqi@0 3466 case vmIntrinsics::_getFloatVolatile : return append_unsafe_get_obj(callee, T_FLOAT, true);
aoqi@0 3467 case vmIntrinsics::_getDoubleVolatile : return append_unsafe_get_obj(callee, T_DOUBLE, true);
aoqi@0 3468
aoqi@0 3469 case vmIntrinsics::_putObjectVolatile : return append_unsafe_put_obj(callee, T_OBJECT, true);
aoqi@0 3470 case vmIntrinsics::_putBooleanVolatile: return append_unsafe_put_obj(callee, T_BOOLEAN, true);
aoqi@0 3471 case vmIntrinsics::_putByteVolatile : return append_unsafe_put_obj(callee, T_BYTE, true);
aoqi@0 3472 case vmIntrinsics::_putShortVolatile : return append_unsafe_put_obj(callee, T_SHORT, true);
aoqi@0 3473 case vmIntrinsics::_putCharVolatile : return append_unsafe_put_obj(callee, T_CHAR, true);
aoqi@0 3474 case vmIntrinsics::_putIntVolatile : return append_unsafe_put_obj(callee, T_INT, true);
aoqi@0 3475 case vmIntrinsics::_putLongVolatile : return append_unsafe_put_obj(callee, T_LONG, true);
aoqi@0 3476 case vmIntrinsics::_putFloatVolatile : return append_unsafe_put_obj(callee, T_FLOAT, true);
aoqi@0 3477 case vmIntrinsics::_putDoubleVolatile : return append_unsafe_put_obj(callee, T_DOUBLE, true);
aoqi@0 3478
aoqi@0 3479 case vmIntrinsics::_getByte_raw : return append_unsafe_get_raw(callee, T_BYTE);
aoqi@0 3480 case vmIntrinsics::_getShort_raw : return append_unsafe_get_raw(callee, T_SHORT);
aoqi@0 3481 case vmIntrinsics::_getChar_raw : return append_unsafe_get_raw(callee, T_CHAR);
aoqi@0 3482 case vmIntrinsics::_getInt_raw : return append_unsafe_get_raw(callee, T_INT);
aoqi@0 3483 case vmIntrinsics::_getLong_raw : return append_unsafe_get_raw(callee, T_LONG);
aoqi@0 3484 case vmIntrinsics::_getFloat_raw : return append_unsafe_get_raw(callee, T_FLOAT);
aoqi@0 3485 case vmIntrinsics::_getDouble_raw : return append_unsafe_get_raw(callee, T_DOUBLE);
aoqi@0 3486
aoqi@0 3487 case vmIntrinsics::_putByte_raw : return append_unsafe_put_raw(callee, T_BYTE);
aoqi@0 3488 case vmIntrinsics::_putShort_raw : return append_unsafe_put_raw(callee, T_SHORT);
aoqi@0 3489 case vmIntrinsics::_putChar_raw : return append_unsafe_put_raw(callee, T_CHAR);
aoqi@0 3490 case vmIntrinsics::_putInt_raw : return append_unsafe_put_raw(callee, T_INT);
aoqi@0 3491 case vmIntrinsics::_putLong_raw : return append_unsafe_put_raw(callee, T_LONG);
aoqi@0 3492 case vmIntrinsics::_putFloat_raw : return append_unsafe_put_raw(callee, T_FLOAT);
aoqi@0 3493 case vmIntrinsics::_putDouble_raw : return append_unsafe_put_raw(callee, T_DOUBLE);
aoqi@0 3494
aoqi@0 3495 case vmIntrinsics::_prefetchRead : return append_unsafe_prefetch(callee, false, false);
aoqi@0 3496 case vmIntrinsics::_prefetchWrite : return append_unsafe_prefetch(callee, false, true);
aoqi@0 3497 case vmIntrinsics::_prefetchReadStatic : return append_unsafe_prefetch(callee, true, false);
aoqi@0 3498 case vmIntrinsics::_prefetchWriteStatic : return append_unsafe_prefetch(callee, true, true);
aoqi@0 3499
aoqi@0 3500 case vmIntrinsics::_checkIndex :
aoqi@0 3501 if (!InlineNIOCheckIndex) return false;
aoqi@0 3502 preserves_state = true;
aoqi@0 3503 break;
aoqi@0 3504 case vmIntrinsics::_putOrderedObject : return append_unsafe_put_obj(callee, T_OBJECT, true);
aoqi@0 3505 case vmIntrinsics::_putOrderedInt : return append_unsafe_put_obj(callee, T_INT, true);
aoqi@0 3506 case vmIntrinsics::_putOrderedLong : return append_unsafe_put_obj(callee, T_LONG, true);
aoqi@0 3507
aoqi@0 3508 case vmIntrinsics::_compareAndSwapLong:
aoqi@0 3509 if (!VM_Version::supports_cx8()) return false;
aoqi@0 3510 // fall through
aoqi@0 3511 case vmIntrinsics::_compareAndSwapInt:
aoqi@0 3512 case vmIntrinsics::_compareAndSwapObject:
aoqi@0 3513 append_unsafe_CAS(callee);
aoqi@0 3514 return true;
aoqi@0 3515
aoqi@0 3516 case vmIntrinsics::_getAndAddInt:
aoqi@0 3517 if (!VM_Version::supports_atomic_getadd4()) {
aoqi@0 3518 return false;
aoqi@0 3519 }
aoqi@0 3520 return append_unsafe_get_and_set_obj(callee, true);
aoqi@0 3521 case vmIntrinsics::_getAndAddLong:
aoqi@0 3522 if (!VM_Version::supports_atomic_getadd8()) {
aoqi@0 3523 return false;
aoqi@0 3524 }
aoqi@0 3525 return append_unsafe_get_and_set_obj(callee, true);
aoqi@0 3526 case vmIntrinsics::_getAndSetInt:
aoqi@0 3527 if (!VM_Version::supports_atomic_getset4()) {
aoqi@0 3528 return false;
aoqi@0 3529 }
aoqi@0 3530 return append_unsafe_get_and_set_obj(callee, false);
aoqi@0 3531 case vmIntrinsics::_getAndSetLong:
aoqi@0 3532 if (!VM_Version::supports_atomic_getset8()) {
aoqi@0 3533 return false;
aoqi@0 3534 }
aoqi@0 3535 return append_unsafe_get_and_set_obj(callee, false);
aoqi@0 3536 case vmIntrinsics::_getAndSetObject:
aoqi@0 3537 #ifdef _LP64
aoqi@0 3538 if (!UseCompressedOops && !VM_Version::supports_atomic_getset8()) {
aoqi@0 3539 return false;
aoqi@0 3540 }
aoqi@0 3541 if (UseCompressedOops && !VM_Version::supports_atomic_getset4()) {
aoqi@0 3542 return false;
aoqi@0 3543 }
aoqi@0 3544 #else
aoqi@0 3545 if (!VM_Version::supports_atomic_getset4()) {
aoqi@0 3546 return false;
aoqi@0 3547 }
aoqi@0 3548 #endif
aoqi@0 3549 return append_unsafe_get_and_set_obj(callee, false);
aoqi@0 3550
aoqi@0 3551 case vmIntrinsics::_Reference_get:
aoqi@0 3552 // Use the intrinsic version of Reference.get() so that the value in
aoqi@0 3553 // the referent field can be registered by the G1 pre-barrier code.
aoqi@0 3554 // Also to prevent commoning reads from this field across safepoint
aoqi@0 3555 // since GC can change its value.
aoqi@0 3556 preserves_state = true;
aoqi@0 3557 break;
aoqi@0 3558
aoqi@0 3559 case vmIntrinsics::_updateCRC32:
aoqi@0 3560 case vmIntrinsics::_updateBytesCRC32:
aoqi@0 3561 case vmIntrinsics::_updateByteBufferCRC32:
aoqi@0 3562 if (!UseCRC32Intrinsics) return false;
aoqi@0 3563 cantrap = false;
aoqi@0 3564 preserves_state = true;
aoqi@0 3565 break;
aoqi@0 3566
aoqi@0 3567 case vmIntrinsics::_loadFence :
aoqi@0 3568 case vmIntrinsics::_storeFence:
aoqi@0 3569 case vmIntrinsics::_fullFence :
aoqi@0 3570 break;
aoqi@0 3571
aoqi@0 3572 default : return false; // do not inline
aoqi@0 3573 }
aoqi@0 3574 // create intrinsic node
aoqi@0 3575 const bool has_receiver = !callee->is_static();
aoqi@0 3576 ValueType* result_type = as_ValueType(callee->return_type());
aoqi@0 3577 ValueStack* state_before = copy_state_for_exception();
aoqi@0 3578
aoqi@0 3579 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 3580
aoqi@0 3581 if (is_profiling()) {
aoqi@0 3582 // Don't profile in the special case where the root method
aoqi@0 3583 // is the intrinsic
aoqi@0 3584 if (callee != method()) {
aoqi@0 3585 // Note that we'd collect profile data in this method if we wanted it.
aoqi@0 3586 compilation()->set_would_profile(true);
aoqi@0 3587 if (profile_calls()) {
aoqi@0 3588 Value recv = NULL;
aoqi@0 3589 if (has_receiver) {
aoqi@0 3590 recv = args->at(0);
aoqi@0 3591 null_check(recv);
aoqi@0 3592 }
aoqi@0 3593 profile_call(callee, recv, NULL, collect_args_for_profiling(args, callee, true), true);
aoqi@0 3594 }
aoqi@0 3595 }
aoqi@0 3596 }
aoqi@0 3597
aoqi@0 3598 Intrinsic* result = new Intrinsic(result_type, id, args, has_receiver, state_before,
aoqi@0 3599 preserves_state, cantrap);
aoqi@0 3600 // append instruction & push result
aoqi@0 3601 Value value = append_split(result);
aoqi@0 3602 if (result_type != voidType) push(result_type, value);
aoqi@0 3603
aoqi@0 3604 if (callee != method() && profile_return() && result_type->is_object_kind()) {
aoqi@0 3605 profile_return_type(result, callee);
aoqi@0 3606 }
aoqi@0 3607
aoqi@0 3608 // done
aoqi@0 3609 return true;
aoqi@0 3610 }
aoqi@0 3611
aoqi@0 3612
aoqi@0 3613 bool GraphBuilder::try_inline_jsr(int jsr_dest_bci) {
aoqi@0 3614 // Introduce a new callee continuation point - all Ret instructions
aoqi@0 3615 // will be replaced with Gotos to this point.
aoqi@0 3616 BlockBegin* cont = block_at(next_bci());
aoqi@0 3617 assert(cont != NULL, "continuation must exist (BlockListBuilder starts a new block after a jsr");
aoqi@0 3618
aoqi@0 3619 // Note: can not assign state to continuation yet, as we have to
aoqi@0 3620 // pick up the state from the Ret instructions.
aoqi@0 3621
aoqi@0 3622 // Push callee scope
aoqi@0 3623 push_scope_for_jsr(cont, jsr_dest_bci);
aoqi@0 3624
aoqi@0 3625 // Temporarily set up bytecode stream so we can append instructions
aoqi@0 3626 // (only using the bci of this stream)
aoqi@0 3627 scope_data()->set_stream(scope_data()->parent()->stream());
aoqi@0 3628
aoqi@0 3629 BlockBegin* jsr_start_block = block_at(jsr_dest_bci);
aoqi@0 3630 assert(jsr_start_block != NULL, "jsr start block must exist");
aoqi@0 3631 assert(!jsr_start_block->is_set(BlockBegin::was_visited_flag), "should not have visited jsr yet");
aoqi@0 3632 Goto* goto_sub = new Goto(jsr_start_block, false);
aoqi@0 3633 // Must copy state to avoid wrong sharing when parsing bytecodes
aoqi@0 3634 assert(jsr_start_block->state() == NULL, "should have fresh jsr starting block");
aoqi@0 3635 jsr_start_block->set_state(copy_state_before_with_bci(jsr_dest_bci));
aoqi@0 3636 append(goto_sub);
aoqi@0 3637 _block->set_end(goto_sub);
aoqi@0 3638 _last = _block = jsr_start_block;
aoqi@0 3639
aoqi@0 3640 // Clear out bytecode stream
aoqi@0 3641 scope_data()->set_stream(NULL);
aoqi@0 3642
aoqi@0 3643 scope_data()->add_to_work_list(jsr_start_block);
aoqi@0 3644
aoqi@0 3645 // Ready to resume parsing in subroutine
aoqi@0 3646 iterate_all_blocks();
aoqi@0 3647
aoqi@0 3648 // If we bailed out during parsing, return immediately (this is bad news)
aoqi@0 3649 CHECK_BAILOUT_(false);
aoqi@0 3650
aoqi@0 3651 // Detect whether the continuation can actually be reached. If not,
aoqi@0 3652 // it has not had state set by the join() operations in
aoqi@0 3653 // iterate_bytecodes_for_block()/ret() and we should not touch the
aoqi@0 3654 // iteration state. The calling activation of
aoqi@0 3655 // iterate_bytecodes_for_block will then complete normally.
aoqi@0 3656 if (cont->state() != NULL) {
aoqi@0 3657 if (!cont->is_set(BlockBegin::was_visited_flag)) {
aoqi@0 3658 // add continuation to work list instead of parsing it immediately
aoqi@0 3659 scope_data()->parent()->add_to_work_list(cont);
aoqi@0 3660 }
aoqi@0 3661 }
aoqi@0 3662
aoqi@0 3663 assert(jsr_continuation() == cont, "continuation must not have changed");
aoqi@0 3664 assert(!jsr_continuation()->is_set(BlockBegin::was_visited_flag) ||
aoqi@0 3665 jsr_continuation()->is_set(BlockBegin::parser_loop_header_flag),
aoqi@0 3666 "continuation can only be visited in case of backward branches");
aoqi@0 3667 assert(_last && _last->as_BlockEnd(), "block must have end");
aoqi@0 3668
aoqi@0 3669 // continuation is in work list, so end iteration of current block
aoqi@0 3670 _skip_block = true;
aoqi@0 3671 pop_scope_for_jsr();
aoqi@0 3672
aoqi@0 3673 return true;
aoqi@0 3674 }
aoqi@0 3675
aoqi@0 3676
aoqi@0 3677 // Inline the entry of a synchronized method as a monitor enter and
aoqi@0 3678 // register the exception handler which releases the monitor if an
aoqi@0 3679 // exception is thrown within the callee. Note that the monitor enter
aoqi@0 3680 // cannot throw an exception itself, because the receiver is
aoqi@0 3681 // guaranteed to be non-null by the explicit null check at the
aoqi@0 3682 // beginning of inlining.
aoqi@0 3683 void GraphBuilder::inline_sync_entry(Value lock, BlockBegin* sync_handler) {
aoqi@0 3684 assert(lock != NULL && sync_handler != NULL, "lock or handler missing");
aoqi@0 3685
aoqi@0 3686 monitorenter(lock, SynchronizationEntryBCI);
aoqi@0 3687 assert(_last->as_MonitorEnter() != NULL, "monitor enter expected");
aoqi@0 3688 _last->set_needs_null_check(false);
aoqi@0 3689
aoqi@0 3690 sync_handler->set(BlockBegin::exception_entry_flag);
aoqi@0 3691 sync_handler->set(BlockBegin::is_on_work_list_flag);
aoqi@0 3692
aoqi@0 3693 ciExceptionHandler* desc = new ciExceptionHandler(method()->holder(), 0, method()->code_size(), -1, 0);
aoqi@0 3694 XHandler* h = new XHandler(desc);
aoqi@0 3695 h->set_entry_block(sync_handler);
aoqi@0 3696 scope_data()->xhandlers()->append(h);
aoqi@0 3697 scope_data()->set_has_handler();
aoqi@0 3698 }
aoqi@0 3699
aoqi@0 3700
aoqi@0 3701 // If an exception is thrown and not handled within an inlined
aoqi@0 3702 // synchronized method, the monitor must be released before the
aoqi@0 3703 // exception is rethrown in the outer scope. Generate the appropriate
aoqi@0 3704 // instructions here.
aoqi@0 3705 void GraphBuilder::fill_sync_handler(Value lock, BlockBegin* sync_handler, bool default_handler) {
aoqi@0 3706 BlockBegin* orig_block = _block;
aoqi@0 3707 ValueStack* orig_state = _state;
aoqi@0 3708 Instruction* orig_last = _last;
aoqi@0 3709 _last = _block = sync_handler;
aoqi@0 3710 _state = sync_handler->state()->copy();
aoqi@0 3711
aoqi@0 3712 assert(sync_handler != NULL, "handler missing");
aoqi@0 3713 assert(!sync_handler->is_set(BlockBegin::was_visited_flag), "is visited here");
aoqi@0 3714
aoqi@0 3715 assert(lock != NULL || default_handler, "lock or handler missing");
aoqi@0 3716
aoqi@0 3717 XHandler* h = scope_data()->xhandlers()->remove_last();
aoqi@0 3718 assert(h->entry_block() == sync_handler, "corrupt list of handlers");
aoqi@0 3719
aoqi@0 3720 block()->set(BlockBegin::was_visited_flag);
aoqi@0 3721 Value exception = append_with_bci(new ExceptionObject(), SynchronizationEntryBCI);
aoqi@0 3722 assert(exception->is_pinned(), "must be");
aoqi@0 3723
aoqi@0 3724 int bci = SynchronizationEntryBCI;
aoqi@0 3725 if (compilation()->env()->dtrace_method_probes()) {
aoqi@0 3726 // Report exit from inline methods. We don't have a stream here
aoqi@0 3727 // so pass an explicit bci of SynchronizationEntryBCI.
aoqi@0 3728 Values* args = new Values(1);
aoqi@0 3729 args->push(append_with_bci(new Constant(new MethodConstant(method())), bci));
aoqi@0 3730 append_with_bci(new RuntimeCall(voidType, "dtrace_method_exit", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), args), bci);
aoqi@0 3731 }
aoqi@0 3732
aoqi@0 3733 if (lock) {
aoqi@0 3734 assert(state()->locks_size() > 0 && state()->lock_at(state()->locks_size() - 1) == lock, "lock is missing");
aoqi@0 3735 if (!lock->is_linked()) {
aoqi@0 3736 lock = append_with_bci(lock, bci);
aoqi@0 3737 }
aoqi@0 3738
aoqi@0 3739 // exit the monitor in the context of the synchronized method
aoqi@0 3740 monitorexit(lock, bci);
aoqi@0 3741
aoqi@0 3742 // exit the context of the synchronized method
aoqi@0 3743 if (!default_handler) {
aoqi@0 3744 pop_scope();
aoqi@0 3745 bci = _state->caller_state()->bci();
aoqi@0 3746 _state = _state->caller_state()->copy_for_parsing();
aoqi@0 3747 }
aoqi@0 3748 }
aoqi@0 3749
aoqi@0 3750 // perform the throw as if at the the call site
aoqi@0 3751 apush(exception);
aoqi@0 3752 throw_op(bci);
aoqi@0 3753
aoqi@0 3754 BlockEnd* end = last()->as_BlockEnd();
aoqi@0 3755 block()->set_end(end);
aoqi@0 3756
aoqi@0 3757 _block = orig_block;
aoqi@0 3758 _state = orig_state;
aoqi@0 3759 _last = orig_last;
aoqi@0 3760 }
aoqi@0 3761
aoqi@0 3762
aoqi@0 3763 bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, Bytecodes::Code bc, Value receiver) {
aoqi@0 3764 assert(!callee->is_native(), "callee must not be native");
aoqi@0 3765 if (CompilationPolicy::policy()->should_not_inline(compilation()->env(), callee)) {
aoqi@0 3766 INLINE_BAILOUT("inlining prohibited by policy");
aoqi@0 3767 }
aoqi@0 3768 // first perform tests of things it's not possible to inline
aoqi@0 3769 if (callee->has_exception_handlers() &&
aoqi@0 3770 !InlineMethodsWithExceptionHandlers) INLINE_BAILOUT("callee has exception handlers");
aoqi@0 3771 if (callee->is_synchronized() &&
aoqi@0 3772 !InlineSynchronizedMethods ) INLINE_BAILOUT("callee is synchronized");
aoqi@0 3773 if (!callee->holder()->is_initialized()) INLINE_BAILOUT("callee's klass not initialized yet");
aoqi@0 3774 if (!callee->has_balanced_monitors()) INLINE_BAILOUT("callee's monitors do not match");
aoqi@0 3775
aoqi@0 3776 // Proper inlining of methods with jsrs requires a little more work.
aoqi@0 3777 if (callee->has_jsrs() ) INLINE_BAILOUT("jsrs not handled properly by inliner yet");
aoqi@0 3778
aoqi@0 3779 // When SSE2 is used on intel, then no special handling is needed
aoqi@0 3780 // for strictfp because the enum-constant is fixed at compile time,
aoqi@0 3781 // the check for UseSSE2 is needed here
aoqi@0 3782 if (strict_fp_requires_explicit_rounding && UseSSE < 2 && method()->is_strict() != callee->is_strict()) {
aoqi@0 3783 INLINE_BAILOUT("caller and callee have different strict fp requirements");
aoqi@0 3784 }
aoqi@0 3785
aoqi@0 3786 if (is_profiling() && !callee->ensure_method_data()) {
aoqi@0 3787 INLINE_BAILOUT("mdo allocation failed");
aoqi@0 3788 }
aoqi@0 3789
aoqi@0 3790 // now perform tests that are based on flag settings
aoqi@0 3791 if (callee->force_inline() || callee->should_inline()) {
aoqi@0 3792 if (inline_level() > MaxForceInlineLevel ) INLINE_BAILOUT("MaxForceInlineLevel");
aoqi@0 3793 if (recursive_inline_level(callee) > MaxRecursiveInlineLevel) INLINE_BAILOUT("recursive inlining too deep");
aoqi@0 3794
aoqi@0 3795 const char* msg = "";
aoqi@0 3796 if (callee->force_inline()) msg = "force inline by annotation";
aoqi@0 3797 if (callee->should_inline()) msg = "force inline by CompileOracle";
aoqi@0 3798 print_inlining(callee, msg);
aoqi@0 3799 } else {
aoqi@0 3800 // use heuristic controls on inlining
aoqi@0 3801 if (inline_level() > MaxInlineLevel ) INLINE_BAILOUT("inlining too deep");
aoqi@0 3802 if (recursive_inline_level(callee) > MaxRecursiveInlineLevel) INLINE_BAILOUT("recursive inlining too deep");
aoqi@0 3803 if (callee->code_size_for_inlining() > max_inline_size() ) INLINE_BAILOUT("callee is too large");
aoqi@0 3804
aoqi@0 3805 // don't inline throwable methods unless the inlining tree is rooted in a throwable class
aoqi@0 3806 if (callee->name() == ciSymbol::object_initializer_name() &&
aoqi@0 3807 callee->holder()->is_subclass_of(ciEnv::current()->Throwable_klass())) {
aoqi@0 3808 // Throwable constructor call
aoqi@0 3809 IRScope* top = scope();
aoqi@0 3810 while (top->caller() != NULL) {
aoqi@0 3811 top = top->caller();
aoqi@0 3812 }
aoqi@0 3813 if (!top->method()->holder()->is_subclass_of(ciEnv::current()->Throwable_klass())) {
aoqi@0 3814 INLINE_BAILOUT("don't inline Throwable constructors");
aoqi@0 3815 }
aoqi@0 3816 }
aoqi@0 3817
aoqi@0 3818 if (compilation()->env()->num_inlined_bytecodes() > DesiredMethodLimit) {
aoqi@0 3819 INLINE_BAILOUT("total inlining greater than DesiredMethodLimit");
aoqi@0 3820 }
aoqi@0 3821 // printing
aoqi@0 3822 print_inlining(callee);
aoqi@0 3823 }
aoqi@0 3824
aoqi@0 3825 // NOTE: Bailouts from this point on, which occur at the
aoqi@0 3826 // GraphBuilder level, do not cause bailout just of the inlining but
aoqi@0 3827 // in fact of the entire compilation.
aoqi@0 3828
aoqi@0 3829 BlockBegin* orig_block = block();
aoqi@0 3830
aoqi@0 3831 const bool is_invokedynamic = bc == Bytecodes::_invokedynamic;
aoqi@0 3832 const bool has_receiver = (bc != Bytecodes::_invokestatic && !is_invokedynamic);
aoqi@0 3833
aoqi@0 3834 const int args_base = state()->stack_size() - callee->arg_size();
aoqi@0 3835 assert(args_base >= 0, "stack underflow during inlining");
aoqi@0 3836
aoqi@0 3837 // Insert null check if necessary
aoqi@0 3838 Value recv = NULL;
aoqi@0 3839 if (has_receiver) {
aoqi@0 3840 // note: null check must happen even if first instruction of callee does
aoqi@0 3841 // an implicit null check since the callee is in a different scope
aoqi@0 3842 // and we must make sure exception handling does the right thing
aoqi@0 3843 assert(!callee->is_static(), "callee must not be static");
aoqi@0 3844 assert(callee->arg_size() > 0, "must have at least a receiver");
aoqi@0 3845 recv = state()->stack_at(args_base);
aoqi@0 3846 null_check(recv);
aoqi@0 3847 }
aoqi@0 3848
aoqi@0 3849 if (is_profiling()) {
aoqi@0 3850 // Note that we'd collect profile data in this method if we wanted it.
aoqi@0 3851 // this may be redundant here...
aoqi@0 3852 compilation()->set_would_profile(true);
aoqi@0 3853
aoqi@0 3854 if (profile_calls()) {
aoqi@0 3855 int start = 0;
aoqi@0 3856 Values* obj_args = args_list_for_profiling(callee, start, has_receiver);
aoqi@0 3857 if (obj_args != NULL) {
aoqi@0 3858 int s = obj_args->size();
aoqi@0 3859 // if called through method handle invoke, some arguments may have been popped
aoqi@0 3860 for (int i = args_base+start, j = 0; j < obj_args->size() && i < state()->stack_size(); ) {
aoqi@0 3861 Value v = state()->stack_at_inc(i);
aoqi@0 3862 if (v->type()->is_object_kind()) {
aoqi@0 3863 obj_args->push(v);
aoqi@0 3864 j++;
aoqi@0 3865 }
aoqi@0 3866 }
aoqi@0 3867 check_args_for_profiling(obj_args, s);
aoqi@0 3868 }
aoqi@0 3869 profile_call(callee, recv, holder_known ? callee->holder() : NULL, obj_args, true);
aoqi@0 3870 }
aoqi@0 3871 }
aoqi@0 3872
aoqi@0 3873 // Introduce a new callee continuation point - if the callee has
aoqi@0 3874 // more than one return instruction or the return does not allow
aoqi@0 3875 // fall-through of control flow, all return instructions of the
aoqi@0 3876 // callee will need to be replaced by Goto's pointing to this
aoqi@0 3877 // continuation point.
aoqi@0 3878 BlockBegin* cont = block_at(next_bci());
aoqi@0 3879 bool continuation_existed = true;
aoqi@0 3880 if (cont == NULL) {
aoqi@0 3881 cont = new BlockBegin(next_bci());
aoqi@0 3882 // low number so that continuation gets parsed as early as possible
aoqi@0 3883 cont->set_depth_first_number(0);
aoqi@0 3884 #ifndef PRODUCT
aoqi@0 3885 if (PrintInitialBlockList) {
aoqi@0 3886 tty->print_cr("CFG: created block %d (bci %d) as continuation for inline at bci %d",
aoqi@0 3887 cont->block_id(), cont->bci(), bci());
aoqi@0 3888 }
aoqi@0 3889 #endif
aoqi@0 3890 continuation_existed = false;
aoqi@0 3891 }
aoqi@0 3892 // Record number of predecessors of continuation block before
aoqi@0 3893 // inlining, to detect if inlined method has edges to its
aoqi@0 3894 // continuation after inlining.
aoqi@0 3895 int continuation_preds = cont->number_of_preds();
aoqi@0 3896
aoqi@0 3897 // Push callee scope
aoqi@0 3898 push_scope(callee, cont);
aoqi@0 3899
aoqi@0 3900 // the BlockListBuilder for the callee could have bailed out
aoqi@0 3901 if (bailed_out())
aoqi@0 3902 return false;
aoqi@0 3903
aoqi@0 3904 // Temporarily set up bytecode stream so we can append instructions
aoqi@0 3905 // (only using the bci of this stream)
aoqi@0 3906 scope_data()->set_stream(scope_data()->parent()->stream());
aoqi@0 3907
aoqi@0 3908 // Pass parameters into callee state: add assignments
aoqi@0 3909 // note: this will also ensure that all arguments are computed before being passed
aoqi@0 3910 ValueStack* callee_state = state();
aoqi@0 3911 ValueStack* caller_state = state()->caller_state();
aoqi@0 3912 for (int i = args_base; i < caller_state->stack_size(); ) {
aoqi@0 3913 const int arg_no = i - args_base;
aoqi@0 3914 Value arg = caller_state->stack_at_inc(i);
aoqi@0 3915 store_local(callee_state, arg, arg_no);
aoqi@0 3916 }
aoqi@0 3917
aoqi@0 3918 // Remove args from stack.
aoqi@0 3919 // Note that we preserve locals state in case we can use it later
aoqi@0 3920 // (see use of pop_scope() below)
aoqi@0 3921 caller_state->truncate_stack(args_base);
aoqi@0 3922 assert(callee_state->stack_size() == 0, "callee stack must be empty");
aoqi@0 3923
aoqi@0 3924 Value lock;
aoqi@0 3925 BlockBegin* sync_handler;
aoqi@0 3926
aoqi@0 3927 // Inline the locking of the receiver if the callee is synchronized
aoqi@0 3928 if (callee->is_synchronized()) {
aoqi@0 3929 lock = callee->is_static() ? append(new Constant(new InstanceConstant(callee->holder()->java_mirror())))
aoqi@0 3930 : state()->local_at(0);
aoqi@0 3931 sync_handler = new BlockBegin(SynchronizationEntryBCI);
aoqi@0 3932 inline_sync_entry(lock, sync_handler);
aoqi@0 3933 }
aoqi@0 3934
aoqi@0 3935 if (compilation()->env()->dtrace_method_probes()) {
aoqi@0 3936 Values* args = new Values(1);
aoqi@0 3937 args->push(append(new Constant(new MethodConstant(method()))));
aoqi@0 3938 append(new RuntimeCall(voidType, "dtrace_method_entry", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), args));
aoqi@0 3939 }
aoqi@0 3940
aoqi@0 3941 if (profile_inlined_calls()) {
aoqi@0 3942 profile_invocation(callee, copy_state_before_with_bci(SynchronizationEntryBCI));
aoqi@0 3943 }
aoqi@0 3944
aoqi@0 3945 BlockBegin* callee_start_block = block_at(0);
aoqi@0 3946 if (callee_start_block != NULL) {
aoqi@0 3947 assert(callee_start_block->is_set(BlockBegin::parser_loop_header_flag), "must be loop header");
aoqi@0 3948 Goto* goto_callee = new Goto(callee_start_block, false);
aoqi@0 3949 // The state for this goto is in the scope of the callee, so use
aoqi@0 3950 // the entry bci for the callee instead of the call site bci.
aoqi@0 3951 append_with_bci(goto_callee, 0);
aoqi@0 3952 _block->set_end(goto_callee);
aoqi@0 3953 callee_start_block->merge(callee_state);
aoqi@0 3954
aoqi@0 3955 _last = _block = callee_start_block;
aoqi@0 3956
aoqi@0 3957 scope_data()->add_to_work_list(callee_start_block);
aoqi@0 3958 }
aoqi@0 3959
aoqi@0 3960 // Clear out bytecode stream
aoqi@0 3961 scope_data()->set_stream(NULL);
aoqi@0 3962
aoqi@0 3963 // Ready to resume parsing in callee (either in the same block we
aoqi@0 3964 // were in before or in the callee's start block)
aoqi@0 3965 iterate_all_blocks(callee_start_block == NULL);
aoqi@0 3966
aoqi@0 3967 // If we bailed out during parsing, return immediately (this is bad news)
aoqi@0 3968 if (bailed_out())
aoqi@0 3969 return false;
aoqi@0 3970
aoqi@0 3971 // iterate_all_blocks theoretically traverses in random order; in
aoqi@0 3972 // practice, we have only traversed the continuation if we are
aoqi@0 3973 // inlining into a subroutine
aoqi@0 3974 assert(continuation_existed ||
aoqi@0 3975 !continuation()->is_set(BlockBegin::was_visited_flag),
aoqi@0 3976 "continuation should not have been parsed yet if we created it");
aoqi@0 3977
aoqi@0 3978 // At this point we are almost ready to return and resume parsing of
aoqi@0 3979 // the caller back in the GraphBuilder. The only thing we want to do
aoqi@0 3980 // first is an optimization: during parsing of the callee we
aoqi@0 3981 // generated at least one Goto to the continuation block. If we
aoqi@0 3982 // generated exactly one, and if the inlined method spanned exactly
aoqi@0 3983 // one block (and we didn't have to Goto its entry), then we snip
aoqi@0 3984 // off the Goto to the continuation, allowing control to fall
aoqi@0 3985 // through back into the caller block and effectively performing
aoqi@0 3986 // block merging. This allows load elimination and CSE to take place
aoqi@0 3987 // across multiple callee scopes if they are relatively simple, and
aoqi@0 3988 // is currently essential to making inlining profitable.
aoqi@0 3989 if (num_returns() == 1
aoqi@0 3990 && block() == orig_block
aoqi@0 3991 && block() == inline_cleanup_block()) {
aoqi@0 3992 _last = inline_cleanup_return_prev();
aoqi@0 3993 _state = inline_cleanup_state();
aoqi@0 3994 } else if (continuation_preds == cont->number_of_preds()) {
aoqi@0 3995 // Inlining caused that the instructions after the invoke in the
aoqi@0 3996 // caller are not reachable any more. So skip filling this block
aoqi@0 3997 // with instructions!
aoqi@0 3998 assert(cont == continuation(), "");
aoqi@0 3999 assert(_last && _last->as_BlockEnd(), "");
aoqi@0 4000 _skip_block = true;
aoqi@0 4001 } else {
aoqi@0 4002 // Resume parsing in continuation block unless it was already parsed.
aoqi@0 4003 // Note that if we don't change _last here, iteration in
aoqi@0 4004 // iterate_bytecodes_for_block will stop when we return.
aoqi@0 4005 if (!continuation()->is_set(BlockBegin::was_visited_flag)) {
aoqi@0 4006 // add continuation to work list instead of parsing it immediately
aoqi@0 4007 assert(_last && _last->as_BlockEnd(), "");
aoqi@0 4008 scope_data()->parent()->add_to_work_list(continuation());
aoqi@0 4009 _skip_block = true;
aoqi@0 4010 }
aoqi@0 4011 }
aoqi@0 4012
aoqi@0 4013 // Fill the exception handler for synchronized methods with instructions
aoqi@0 4014 if (callee->is_synchronized() && sync_handler->state() != NULL) {
aoqi@0 4015 fill_sync_handler(lock, sync_handler);
aoqi@0 4016 } else {
aoqi@0 4017 pop_scope();
aoqi@0 4018 }
aoqi@0 4019
aoqi@0 4020 compilation()->notice_inlined_method(callee);
aoqi@0 4021
aoqi@0 4022 return true;
aoqi@0 4023 }
aoqi@0 4024
aoqi@0 4025
aoqi@0 4026 bool GraphBuilder::try_method_handle_inline(ciMethod* callee) {
aoqi@0 4027 ValueStack* state_before = state()->copy_for_parsing();
aoqi@0 4028 vmIntrinsics::ID iid = callee->intrinsic_id();
aoqi@0 4029 switch (iid) {
aoqi@0 4030 case vmIntrinsics::_invokeBasic:
aoqi@0 4031 {
aoqi@0 4032 // get MethodHandle receiver
aoqi@0 4033 const int args_base = state()->stack_size() - callee->arg_size();
aoqi@0 4034 ValueType* type = state()->stack_at(args_base)->type();
aoqi@0 4035 if (type->is_constant()) {
aoqi@0 4036 ciMethod* target = type->as_ObjectType()->constant_value()->as_method_handle()->get_vmtarget();
aoqi@0 4037 // We don't do CHA here so only inline static and statically bindable methods.
aoqi@0 4038 if (target->is_static() || target->can_be_statically_bound()) {
aoqi@0 4039 Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
aoqi@0 4040 if (try_inline(target, /*holder_known*/ true, bc)) {
aoqi@0 4041 return true;
aoqi@0 4042 }
aoqi@0 4043 } else {
aoqi@0 4044 print_inlining(target, "not static or statically bindable", /*success*/ false);
aoqi@0 4045 }
aoqi@0 4046 } else {
aoqi@0 4047 print_inlining(callee, "receiver not constant", /*success*/ false);
aoqi@0 4048 }
aoqi@0 4049 }
aoqi@0 4050 break;
aoqi@0 4051
aoqi@0 4052 case vmIntrinsics::_linkToVirtual:
aoqi@0 4053 case vmIntrinsics::_linkToStatic:
aoqi@0 4054 case vmIntrinsics::_linkToSpecial:
aoqi@0 4055 case vmIntrinsics::_linkToInterface:
aoqi@0 4056 {
aoqi@0 4057 // pop MemberName argument
aoqi@0 4058 const int args_base = state()->stack_size() - callee->arg_size();
aoqi@0 4059 ValueType* type = apop()->type();
aoqi@0 4060 if (type->is_constant()) {
aoqi@0 4061 ciMethod* target = type->as_ObjectType()->constant_value()->as_member_name()->get_vmtarget();
aoqi@0 4062 // If the target is another method handle invoke try recursivly to get
aoqi@0 4063 // a better target.
aoqi@0 4064 if (target->is_method_handle_intrinsic()) {
aoqi@0 4065 if (try_method_handle_inline(target)) {
aoqi@0 4066 return true;
aoqi@0 4067 }
aoqi@0 4068 } else {
aoqi@0 4069 ciSignature* signature = target->signature();
aoqi@0 4070 const int receiver_skip = target->is_static() ? 0 : 1;
aoqi@0 4071 // Cast receiver to its type.
aoqi@0 4072 if (!target->is_static()) {
aoqi@0 4073 ciKlass* tk = signature->accessing_klass();
aoqi@0 4074 Value obj = state()->stack_at(args_base);
aoqi@0 4075 if (obj->exact_type() == NULL &&
aoqi@0 4076 obj->declared_type() != tk && tk != compilation()->env()->Object_klass()) {
aoqi@0 4077 TypeCast* c = new TypeCast(tk, obj, state_before);
aoqi@0 4078 append(c);
aoqi@0 4079 state()->stack_at_put(args_base, c);
aoqi@0 4080 }
aoqi@0 4081 }
aoqi@0 4082 // Cast reference arguments to its type.
aoqi@0 4083 for (int i = 0, j = 0; i < signature->count(); i++) {
aoqi@0 4084 ciType* t = signature->type_at(i);
aoqi@0 4085 if (t->is_klass()) {
aoqi@0 4086 ciKlass* tk = t->as_klass();
aoqi@0 4087 Value obj = state()->stack_at(args_base + receiver_skip + j);
aoqi@0 4088 if (obj->exact_type() == NULL &&
aoqi@0 4089 obj->declared_type() != tk && tk != compilation()->env()->Object_klass()) {
aoqi@0 4090 TypeCast* c = new TypeCast(t, obj, state_before);
aoqi@0 4091 append(c);
aoqi@0 4092 state()->stack_at_put(args_base + receiver_skip + j, c);
aoqi@0 4093 }
aoqi@0 4094 }
aoqi@0 4095 j += t->size(); // long and double take two slots
aoqi@0 4096 }
aoqi@0 4097 // We don't do CHA here so only inline static and statically bindable methods.
aoqi@0 4098 if (target->is_static() || target->can_be_statically_bound()) {
aoqi@0 4099 Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
aoqi@0 4100 if (try_inline(target, /*holder_known*/ true, bc)) {
aoqi@0 4101 return true;
aoqi@0 4102 }
aoqi@0 4103 } else {
aoqi@0 4104 print_inlining(target, "not static or statically bindable", /*success*/ false);
aoqi@0 4105 }
aoqi@0 4106 }
aoqi@0 4107 } else {
aoqi@0 4108 print_inlining(callee, "MemberName not constant", /*success*/ false);
aoqi@0 4109 }
aoqi@0 4110 }
aoqi@0 4111 break;
aoqi@0 4112
aoqi@0 4113 default:
aoqi@0 4114 fatal(err_msg("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)));
aoqi@0 4115 break;
aoqi@0 4116 }
aoqi@0 4117 set_state(state_before);
aoqi@0 4118 return false;
aoqi@0 4119 }
aoqi@0 4120
aoqi@0 4121
aoqi@0 4122 void GraphBuilder::inline_bailout(const char* msg) {
aoqi@0 4123 assert(msg != NULL, "inline bailout msg must exist");
aoqi@0 4124 _inline_bailout_msg = msg;
aoqi@0 4125 }
aoqi@0 4126
aoqi@0 4127
aoqi@0 4128 void GraphBuilder::clear_inline_bailout() {
aoqi@0 4129 _inline_bailout_msg = NULL;
aoqi@0 4130 }
aoqi@0 4131
aoqi@0 4132
aoqi@0 4133 void GraphBuilder::push_root_scope(IRScope* scope, BlockList* bci2block, BlockBegin* start) {
aoqi@0 4134 ScopeData* data = new ScopeData(NULL);
aoqi@0 4135 data->set_scope(scope);
aoqi@0 4136 data->set_bci2block(bci2block);
aoqi@0 4137 _scope_data = data;
aoqi@0 4138 _block = start;
aoqi@0 4139 }
aoqi@0 4140
aoqi@0 4141
aoqi@0 4142 void GraphBuilder::push_scope(ciMethod* callee, BlockBegin* continuation) {
aoqi@0 4143 IRScope* callee_scope = new IRScope(compilation(), scope(), bci(), callee, -1, false);
aoqi@0 4144 scope()->add_callee(callee_scope);
aoqi@0 4145
aoqi@0 4146 BlockListBuilder blb(compilation(), callee_scope, -1);
aoqi@0 4147 CHECK_BAILOUT();
aoqi@0 4148
aoqi@0 4149 if (!blb.bci2block()->at(0)->is_set(BlockBegin::parser_loop_header_flag)) {
aoqi@0 4150 // this scope can be inlined directly into the caller so remove
aoqi@0 4151 // the block at bci 0.
aoqi@0 4152 blb.bci2block()->at_put(0, NULL);
aoqi@0 4153 }
aoqi@0 4154
aoqi@0 4155 set_state(new ValueStack(callee_scope, state()->copy(ValueStack::CallerState, bci())));
aoqi@0 4156
aoqi@0 4157 ScopeData* data = new ScopeData(scope_data());
aoqi@0 4158 data->set_scope(callee_scope);
aoqi@0 4159 data->set_bci2block(blb.bci2block());
aoqi@0 4160 data->set_continuation(continuation);
aoqi@0 4161 _scope_data = data;
aoqi@0 4162 }
aoqi@0 4163
aoqi@0 4164
aoqi@0 4165 void GraphBuilder::push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci) {
aoqi@0 4166 ScopeData* data = new ScopeData(scope_data());
aoqi@0 4167 data->set_parsing_jsr();
aoqi@0 4168 data->set_jsr_entry_bci(jsr_dest_bci);
aoqi@0 4169 data->set_jsr_return_address_local(-1);
aoqi@0 4170 // Must clone bci2block list as we will be mutating it in order to
aoqi@0 4171 // properly clone all blocks in jsr region as well as exception
aoqi@0 4172 // handlers containing rets
aoqi@0 4173 BlockList* new_bci2block = new BlockList(bci2block()->length());
aoqi@0 4174 new_bci2block->push_all(bci2block());
aoqi@0 4175 data->set_bci2block(new_bci2block);
aoqi@0 4176 data->set_scope(scope());
aoqi@0 4177 data->setup_jsr_xhandlers();
aoqi@0 4178 data->set_continuation(continuation());
aoqi@0 4179 data->set_jsr_continuation(jsr_continuation);
aoqi@0 4180 _scope_data = data;
aoqi@0 4181 }
aoqi@0 4182
aoqi@0 4183
aoqi@0 4184 void GraphBuilder::pop_scope() {
aoqi@0 4185 int number_of_locks = scope()->number_of_locks();
aoqi@0 4186 _scope_data = scope_data()->parent();
aoqi@0 4187 // accumulate minimum number of monitor slots to be reserved
aoqi@0 4188 scope()->set_min_number_of_locks(number_of_locks);
aoqi@0 4189 }
aoqi@0 4190
aoqi@0 4191
aoqi@0 4192 void GraphBuilder::pop_scope_for_jsr() {
aoqi@0 4193 _scope_data = scope_data()->parent();
aoqi@0 4194 }
aoqi@0 4195
aoqi@0 4196 bool GraphBuilder::append_unsafe_get_obj(ciMethod* callee, BasicType t, bool is_volatile) {
aoqi@0 4197 if (InlineUnsafeOps) {
aoqi@0 4198 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 4199 null_check(args->at(0));
aoqi@0 4200 Instruction* offset = args->at(2);
aoqi@0 4201 #ifndef _LP64
aoqi@0 4202 offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
aoqi@0 4203 #endif
aoqi@0 4204 Instruction* op = append(new UnsafeGetObject(t, args->at(1), offset, is_volatile));
aoqi@0 4205 push(op->type(), op);
aoqi@0 4206 compilation()->set_has_unsafe_access(true);
aoqi@0 4207 }
aoqi@0 4208 return InlineUnsafeOps;
aoqi@0 4209 }
aoqi@0 4210
aoqi@0 4211
aoqi@0 4212 bool GraphBuilder::append_unsafe_put_obj(ciMethod* callee, BasicType t, bool is_volatile) {
aoqi@0 4213 if (InlineUnsafeOps) {
aoqi@0 4214 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 4215 null_check(args->at(0));
aoqi@0 4216 Instruction* offset = args->at(2);
aoqi@0 4217 #ifndef _LP64
aoqi@0 4218 offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
aoqi@0 4219 #endif
aoqi@0 4220 Instruction* op = append(new UnsafePutObject(t, args->at(1), offset, args->at(3), is_volatile));
aoqi@0 4221 compilation()->set_has_unsafe_access(true);
aoqi@0 4222 kill_all();
aoqi@0 4223 }
aoqi@0 4224 return InlineUnsafeOps;
aoqi@0 4225 }
aoqi@0 4226
aoqi@0 4227
aoqi@0 4228 bool GraphBuilder::append_unsafe_get_raw(ciMethod* callee, BasicType t) {
aoqi@0 4229 if (InlineUnsafeOps) {
aoqi@0 4230 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 4231 null_check(args->at(0));
aoqi@0 4232 Instruction* op = append(new UnsafeGetRaw(t, args->at(1), false));
aoqi@0 4233 push(op->type(), op);
aoqi@0 4234 compilation()->set_has_unsafe_access(true);
aoqi@0 4235 }
aoqi@0 4236 return InlineUnsafeOps;
aoqi@0 4237 }
aoqi@0 4238
aoqi@0 4239
aoqi@0 4240 bool GraphBuilder::append_unsafe_put_raw(ciMethod* callee, BasicType t) {
aoqi@0 4241 if (InlineUnsafeOps) {
aoqi@0 4242 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 4243 null_check(args->at(0));
aoqi@0 4244 Instruction* op = append(new UnsafePutRaw(t, args->at(1), args->at(2)));
aoqi@0 4245 compilation()->set_has_unsafe_access(true);
aoqi@0 4246 }
aoqi@0 4247 return InlineUnsafeOps;
aoqi@0 4248 }
aoqi@0 4249
aoqi@0 4250
aoqi@0 4251 bool GraphBuilder::append_unsafe_prefetch(ciMethod* callee, bool is_static, bool is_store) {
aoqi@0 4252 if (InlineUnsafeOps) {
aoqi@0 4253 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 4254 int obj_arg_index = 1; // Assume non-static case
aoqi@0 4255 if (is_static) {
aoqi@0 4256 obj_arg_index = 0;
aoqi@0 4257 } else {
aoqi@0 4258 null_check(args->at(0));
aoqi@0 4259 }
aoqi@0 4260 Instruction* offset = args->at(obj_arg_index + 1);
aoqi@0 4261 #ifndef _LP64
aoqi@0 4262 offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
aoqi@0 4263 #endif
aoqi@0 4264 Instruction* op = is_store ? append(new UnsafePrefetchWrite(args->at(obj_arg_index), offset))
aoqi@0 4265 : append(new UnsafePrefetchRead (args->at(obj_arg_index), offset));
aoqi@0 4266 compilation()->set_has_unsafe_access(true);
aoqi@0 4267 }
aoqi@0 4268 return InlineUnsafeOps;
aoqi@0 4269 }
aoqi@0 4270
aoqi@0 4271
aoqi@0 4272 void GraphBuilder::append_unsafe_CAS(ciMethod* callee) {
aoqi@0 4273 ValueStack* state_before = copy_state_for_exception();
aoqi@0 4274 ValueType* result_type = as_ValueType(callee->return_type());
aoqi@0 4275 assert(result_type->is_int(), "int result");
aoqi@0 4276 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 4277
aoqi@0 4278 // Pop off some args to speically handle, then push back
aoqi@0 4279 Value newval = args->pop();
aoqi@0 4280 Value cmpval = args->pop();
aoqi@0 4281 Value offset = args->pop();
aoqi@0 4282 Value src = args->pop();
aoqi@0 4283 Value unsafe_obj = args->pop();
aoqi@0 4284
aoqi@0 4285 // Separately handle the unsafe arg. It is not needed for code
aoqi@0 4286 // generation, but must be null checked
aoqi@0 4287 null_check(unsafe_obj);
aoqi@0 4288
aoqi@0 4289 #ifndef _LP64
aoqi@0 4290 offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
aoqi@0 4291 #endif
aoqi@0 4292
aoqi@0 4293 args->push(src);
aoqi@0 4294 args->push(offset);
aoqi@0 4295 args->push(cmpval);
aoqi@0 4296 args->push(newval);
aoqi@0 4297
aoqi@0 4298 // An unsafe CAS can alias with other field accesses, but we don't
aoqi@0 4299 // know which ones so mark the state as no preserved. This will
aoqi@0 4300 // cause CSE to invalidate memory across it.
aoqi@0 4301 bool preserves_state = false;
aoqi@0 4302 Intrinsic* result = new Intrinsic(result_type, callee->intrinsic_id(), args, false, state_before, preserves_state);
aoqi@0 4303 append_split(result);
aoqi@0 4304 push(result_type, result);
aoqi@0 4305 compilation()->set_has_unsafe_access(true);
aoqi@0 4306 }
aoqi@0 4307
aoqi@0 4308
aoqi@0 4309 void GraphBuilder::print_inlining(ciMethod* callee, const char* msg, bool success) {
aoqi@0 4310 CompileLog* log = compilation()->log();
aoqi@0 4311 if (log != NULL) {
aoqi@0 4312 if (success) {
aoqi@0 4313 if (msg != NULL)
aoqi@0 4314 log->inline_success(msg);
aoqi@0 4315 else
aoqi@0 4316 log->inline_success("receiver is statically known");
aoqi@0 4317 } else {
aoqi@0 4318 if (msg != NULL)
aoqi@0 4319 log->inline_fail(msg);
aoqi@0 4320 else
aoqi@0 4321 log->inline_fail("reason unknown");
aoqi@0 4322 }
aoqi@0 4323 }
aoqi@0 4324
aoqi@0 4325 if (!PrintInlining && !compilation()->method()->has_option("PrintInlining")) {
aoqi@0 4326 return;
aoqi@0 4327 }
aoqi@0 4328 CompileTask::print_inlining(callee, scope()->level(), bci(), msg);
aoqi@0 4329 if (success && CIPrintMethodCodes) {
aoqi@0 4330 callee->print_codes();
aoqi@0 4331 }
aoqi@0 4332 }
aoqi@0 4333
aoqi@0 4334 bool GraphBuilder::append_unsafe_get_and_set_obj(ciMethod* callee, bool is_add) {
aoqi@0 4335 if (InlineUnsafeOps) {
aoqi@0 4336 Values* args = state()->pop_arguments(callee->arg_size());
aoqi@0 4337 BasicType t = callee->return_type()->basic_type();
aoqi@0 4338 null_check(args->at(0));
aoqi@0 4339 Instruction* offset = args->at(2);
aoqi@0 4340 #ifndef _LP64
aoqi@0 4341 offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
aoqi@0 4342 #endif
aoqi@0 4343 Instruction* op = append(new UnsafeGetAndSetObject(t, args->at(1), offset, args->at(3), is_add));
aoqi@0 4344 compilation()->set_has_unsafe_access(true);
aoqi@0 4345 kill_all();
aoqi@0 4346 push(op->type(), op);
aoqi@0 4347 }
aoqi@0 4348 return InlineUnsafeOps;
aoqi@0 4349 }
aoqi@0 4350
aoqi@0 4351 #ifndef PRODUCT
aoqi@0 4352 void GraphBuilder::print_stats() {
aoqi@0 4353 vmap()->print();
aoqi@0 4354 }
aoqi@0 4355 #endif // PRODUCT
aoqi@0 4356
aoqi@0 4357 void GraphBuilder::profile_call(ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined) {
aoqi@0 4358 assert(known_holder == NULL || (known_holder->is_instance_klass() &&
aoqi@0 4359 (!known_holder->is_interface() ||
aoqi@0 4360 ((ciInstanceKlass*)known_holder)->has_default_methods())), "should be default method");
aoqi@0 4361 if (known_holder != NULL) {
aoqi@0 4362 if (known_holder->exact_klass() == NULL) {
aoqi@0 4363 known_holder = compilation()->cha_exact_type(known_holder);
aoqi@0 4364 }
aoqi@0 4365 }
aoqi@0 4366
aoqi@0 4367 append(new ProfileCall(method(), bci(), callee, recv, known_holder, obj_args, inlined));
aoqi@0 4368 }
aoqi@0 4369
aoqi@0 4370 void GraphBuilder::profile_return_type(Value ret, ciMethod* callee, ciMethod* m, int invoke_bci) {
aoqi@0 4371 assert((m == NULL) == (invoke_bci < 0), "invalid method and invalid bci together");
aoqi@0 4372 if (m == NULL) {
aoqi@0 4373 m = method();
aoqi@0 4374 }
aoqi@0 4375 if (invoke_bci < 0) {
aoqi@0 4376 invoke_bci = bci();
aoqi@0 4377 }
aoqi@0 4378 ciMethodData* md = m->method_data_or_null();
aoqi@0 4379 ciProfileData* data = md->bci_to_data(invoke_bci);
aoqi@0 4380 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
aoqi@0 4381 append(new ProfileReturnType(m , invoke_bci, callee, ret));
aoqi@0 4382 }
aoqi@0 4383 }
aoqi@0 4384
aoqi@0 4385 void GraphBuilder::profile_invocation(ciMethod* callee, ValueStack* state) {
aoqi@0 4386 append(new ProfileInvoke(callee, state));
aoqi@0 4387 }

mercurial