1 /* 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2008, 2009, 2010 Red Hat, Inc. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "incls/_precompiled.incl" 27 #include "incls/_sharkBlock.cpp.incl" 28 29 using namespace llvm; 30 31 void SharkBlock::parse_bytecode(int start, int limit) { 32 SharkValue *a, *b, *c, *d; 33 int i; 34 35 // Ensure the current state is initialized before we emit any code, 36 // so that any setup code for the state is at the start of the block 37 current_state(); 38 39 // Parse the bytecodes 40 iter()->reset_to_bci(start); 41 while (iter()->next_bci() < limit) { 42 NOT_PRODUCT(a = b = c = d = NULL); 43 iter()->next(); 44 45 if (SharkTraceBytecodes) 46 tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc())); 47 48 if (has_trap() && trap_bci() == bci()) { 49 do_trap(trap_request()); 50 return; 51 } 52 53 if (UseLoopSafepoints) { 54 // XXX if a lcmp is followed by an if_?? then C2 maybe-inserts 55 // the safepoint before the lcmp rather than before the if. 56 // Maybe we should do this too. See parse2.cpp for details. 57 switch (bc()) { 58 case Bytecodes::_goto: 59 case Bytecodes::_ifnull: 60 case Bytecodes::_ifnonnull: 61 case Bytecodes::_if_acmpeq: 62 case Bytecodes::_if_acmpne: 63 case Bytecodes::_ifeq: 64 case Bytecodes::_ifne: 65 case Bytecodes::_iflt: 66 case Bytecodes::_ifle: 67 case Bytecodes::_ifgt: 68 case Bytecodes::_ifge: 69 case Bytecodes::_if_icmpeq: 70 case Bytecodes::_if_icmpne: 71 case Bytecodes::_if_icmplt: 72 case Bytecodes::_if_icmple: 73 case Bytecodes::_if_icmpgt: 74 case Bytecodes::_if_icmpge: 75 if (iter()->get_dest() <= bci()) 76 maybe_add_backedge_safepoint(); 77 break; 78 79 case Bytecodes::_goto_w: 80 if (iter()->get_far_dest() <= bci()) 81 maybe_add_backedge_safepoint(); 82 break; 83 84 case Bytecodes::_tableswitch: 85 case Bytecodes::_lookupswitch: 86 if (switch_default_dest() <= bci()) { 87 maybe_add_backedge_safepoint(); 88 break; 89 } 90 int len = switch_table_length(); 91 for (int i = 0; i < len; i++) { 92 if (switch_dest(i) <= bci()) { 93 maybe_add_backedge_safepoint(); 94 break; 95 } 96 } 97 break; 98 } 99 } 100 101 switch (bc()) { 102 case Bytecodes::_nop: 103 break; 104 105 case Bytecodes::_aconst_null: 106 push(SharkValue::null()); 107 break; 108 109 case Bytecodes::_iconst_m1: 110 push(SharkValue::jint_constant(-1)); 111 break; 112 case Bytecodes::_iconst_0: 113 push(SharkValue::jint_constant(0)); 114 break; 115 case Bytecodes::_iconst_1: 116 push(SharkValue::jint_constant(1)); 117 break; 118 case Bytecodes::_iconst_2: 119 push(SharkValue::jint_constant(2)); 120 break; 121 case Bytecodes::_iconst_3: 122 push(SharkValue::jint_constant(3)); 123 break; 124 case Bytecodes::_iconst_4: 125 push(SharkValue::jint_constant(4)); 126 break; 127 case Bytecodes::_iconst_5: 128 push(SharkValue::jint_constant(5)); 129 break; 130 131 case Bytecodes::_lconst_0: 132 push(SharkValue::jlong_constant(0)); 133 break; 134 case Bytecodes::_lconst_1: 135 push(SharkValue::jlong_constant(1)); 136 break; 137 138 case Bytecodes::_fconst_0: 139 push(SharkValue::jfloat_constant(0)); 140 break; 141 case Bytecodes::_fconst_1: 142 push(SharkValue::jfloat_constant(1)); 143 break; 144 case Bytecodes::_fconst_2: 145 push(SharkValue::jfloat_constant(2)); 146 break; 147 148 case Bytecodes::_dconst_0: 149 push(SharkValue::jdouble_constant(0)); 150 break; 151 case Bytecodes::_dconst_1: 152 push(SharkValue::jdouble_constant(1)); 153 break; 154 155 case Bytecodes::_bipush: 156 push(SharkValue::jint_constant(iter()->get_constant_u1())); 157 break; 158 case Bytecodes::_sipush: 159 push(SharkValue::jint_constant(iter()->get_constant_u2())); 160 break; 161 162 case Bytecodes::_ldc: 163 case Bytecodes::_ldc_w: 164 case Bytecodes::_ldc2_w: 165 push(SharkConstant::for_ldc(iter())->value(builder())); 166 break; 167 168 case Bytecodes::_iload_0: 169 case Bytecodes::_lload_0: 170 case Bytecodes::_fload_0: 171 case Bytecodes::_dload_0: 172 case Bytecodes::_aload_0: 173 push(local(0)); 174 break; 175 case Bytecodes::_iload_1: 176 case Bytecodes::_lload_1: 177 case Bytecodes::_fload_1: 178 case Bytecodes::_dload_1: 179 case Bytecodes::_aload_1: 180 push(local(1)); 181 break; 182 case Bytecodes::_iload_2: 183 case Bytecodes::_lload_2: 184 case Bytecodes::_fload_2: 185 case Bytecodes::_dload_2: 186 case Bytecodes::_aload_2: 187 push(local(2)); 188 break; 189 case Bytecodes::_iload_3: 190 case Bytecodes::_lload_3: 191 case Bytecodes::_fload_3: 192 case Bytecodes::_dload_3: 193 case Bytecodes::_aload_3: 194 push(local(3)); 195 break; 196 case Bytecodes::_iload: 197 case Bytecodes::_lload: 198 case Bytecodes::_fload: 199 case Bytecodes::_dload: 200 case Bytecodes::_aload: 201 push(local(iter()->get_index())); 202 break; 203 204 case Bytecodes::_baload: 205 do_aload(T_BYTE); 206 break; 207 case Bytecodes::_caload: 208 do_aload(T_CHAR); 209 break; 210 case Bytecodes::_saload: 211 do_aload(T_SHORT); 212 break; 213 case Bytecodes::_iaload: 214 do_aload(T_INT); 215 break; 216 case Bytecodes::_laload: 217 do_aload(T_LONG); 218 break; 219 case Bytecodes::_faload: 220 do_aload(T_FLOAT); 221 break; 222 case Bytecodes::_daload: 223 do_aload(T_DOUBLE); 224 break; 225 case Bytecodes::_aaload: 226 do_aload(T_OBJECT); 227 break; 228 229 case Bytecodes::_istore_0: 230 case Bytecodes::_lstore_0: 231 case Bytecodes::_fstore_0: 232 case Bytecodes::_dstore_0: 233 case Bytecodes::_astore_0: 234 set_local(0, pop()); 235 break; 236 case Bytecodes::_istore_1: 237 case Bytecodes::_lstore_1: 238 case Bytecodes::_fstore_1: 239 case Bytecodes::_dstore_1: 240 case Bytecodes::_astore_1: 241 set_local(1, pop()); 242 break; 243 case Bytecodes::_istore_2: 244 case Bytecodes::_lstore_2: 245 case Bytecodes::_fstore_2: 246 case Bytecodes::_dstore_2: 247 case Bytecodes::_astore_2: 248 set_local(2, pop()); 249 break; 250 case Bytecodes::_istore_3: 251 case Bytecodes::_lstore_3: 252 case Bytecodes::_fstore_3: 253 case Bytecodes::_dstore_3: 254 case Bytecodes::_astore_3: 255 set_local(3, pop()); 256 break; 257 case Bytecodes::_istore: 258 case Bytecodes::_lstore: 259 case Bytecodes::_fstore: 260 case Bytecodes::_dstore: 261 case Bytecodes::_astore: 262 set_local(iter()->get_index(), pop()); 263 break; 264 265 case Bytecodes::_bastore: 266 do_astore(T_BYTE); 267 break; 268 case Bytecodes::_castore: 269 do_astore(T_CHAR); 270 break; 271 case Bytecodes::_sastore: 272 do_astore(T_SHORT); 273 break; 274 case Bytecodes::_iastore: 275 do_astore(T_INT); 276 break; 277 case Bytecodes::_lastore: 278 do_astore(T_LONG); 279 break; 280 case Bytecodes::_fastore: 281 do_astore(T_FLOAT); 282 break; 283 case Bytecodes::_dastore: 284 do_astore(T_DOUBLE); 285 break; 286 case Bytecodes::_aastore: 287 do_astore(T_OBJECT); 288 break; 289 290 case Bytecodes::_pop: 291 xpop(); 292 break; 293 case Bytecodes::_pop2: 294 xpop(); 295 xpop(); 296 break; 297 case Bytecodes::_swap: 298 a = xpop(); 299 b = xpop(); 300 xpush(a); 301 xpush(b); 302 break; 303 case Bytecodes::_dup: 304 a = xpop(); 305 xpush(a); 306 xpush(a); 307 break; 308 case Bytecodes::_dup_x1: 309 a = xpop(); 310 b = xpop(); 311 xpush(a); 312 xpush(b); 313 xpush(a); 314 break; 315 case Bytecodes::_dup_x2: 316 a = xpop(); 317 b = xpop(); 318 c = xpop(); 319 xpush(a); 320 xpush(c); 321 xpush(b); 322 xpush(a); 323 break; 324 case Bytecodes::_dup2: 325 a = xpop(); 326 b = xpop(); 327 xpush(b); 328 xpush(a); 329 xpush(b); 330 xpush(a); 331 break; 332 case Bytecodes::_dup2_x1: 333 a = xpop(); 334 b = xpop(); 335 c = xpop(); 336 xpush(b); 337 xpush(a); 338 xpush(c); 339 xpush(b); 340 xpush(a); 341 break; 342 case Bytecodes::_dup2_x2: 343 a = xpop(); 344 b = xpop(); 345 c = xpop(); 346 d = xpop(); 347 xpush(b); 348 xpush(a); 349 xpush(d); 350 xpush(c); 351 xpush(b); 352 xpush(a); 353 break; 354 355 case Bytecodes::_arraylength: 356 do_arraylength(); 357 break; 358 359 case Bytecodes::_getfield: 360 do_getfield(); 361 break; 362 case Bytecodes::_getstatic: 363 do_getstatic(); 364 break; 365 case Bytecodes::_putfield: 366 do_putfield(); 367 break; 368 case Bytecodes::_putstatic: 369 do_putstatic(); 370 break; 371 372 case Bytecodes::_iadd: 373 b = pop(); 374 a = pop(); 375 push(SharkValue::create_jint( 376 builder()->CreateAdd(a->jint_value(), b->jint_value()), false)); 377 break; 378 case Bytecodes::_isub: 379 b = pop(); 380 a = pop(); 381 push(SharkValue::create_jint( 382 builder()->CreateSub(a->jint_value(), b->jint_value()), false)); 383 break; 384 case Bytecodes::_imul: 385 b = pop(); 386 a = pop(); 387 push(SharkValue::create_jint( 388 builder()->CreateMul(a->jint_value(), b->jint_value()), false)); 389 break; 390 case Bytecodes::_idiv: 391 do_idiv(); 392 break; 393 case Bytecodes::_irem: 394 do_irem(); 395 break; 396 case Bytecodes::_ineg: 397 a = pop(); 398 push(SharkValue::create_jint( 399 builder()->CreateNeg(a->jint_value()), a->zero_checked())); 400 break; 401 case Bytecodes::_ishl: 402 b = pop(); 403 a = pop(); 404 push(SharkValue::create_jint( 405 builder()->CreateShl( 406 a->jint_value(), 407 builder()->CreateAnd( 408 b->jint_value(), LLVMValue::jint_constant(0x1f))), false)); 409 break; 410 case Bytecodes::_ishr: 411 b = pop(); 412 a = pop(); 413 push(SharkValue::create_jint( 414 builder()->CreateAShr( 415 a->jint_value(), 416 builder()->CreateAnd( 417 b->jint_value(), LLVMValue::jint_constant(0x1f))), false)); 418 break; 419 case Bytecodes::_iushr: 420 b = pop(); 421 a = pop(); 422 push(SharkValue::create_jint( 423 builder()->CreateLShr( 424 a->jint_value(), 425 builder()->CreateAnd( 426 b->jint_value(), LLVMValue::jint_constant(0x1f))), false)); 427 break; 428 case Bytecodes::_iand: 429 b = pop(); 430 a = pop(); 431 push(SharkValue::create_jint( 432 builder()->CreateAnd(a->jint_value(), b->jint_value()), false)); 433 break; 434 case Bytecodes::_ior: 435 b = pop(); 436 a = pop(); 437 push(SharkValue::create_jint( 438 builder()->CreateOr(a->jint_value(), b->jint_value()), 439 a->zero_checked() && b->zero_checked())); 440 break; 441 case Bytecodes::_ixor: 442 b = pop(); 443 a = pop(); 444 push(SharkValue::create_jint( 445 builder()->CreateXor(a->jint_value(), b->jint_value()), false)); 446 break; 447 448 case Bytecodes::_ladd: 449 b = pop(); 450 a = pop(); 451 push(SharkValue::create_jlong( 452 builder()->CreateAdd(a->jlong_value(), b->jlong_value()), false)); 453 break; 454 case Bytecodes::_lsub: 455 b = pop(); 456 a = pop(); 457 push(SharkValue::create_jlong( 458 builder()->CreateSub(a->jlong_value(), b->jlong_value()), false)); 459 break; 460 case Bytecodes::_lmul: 461 b = pop(); 462 a = pop(); 463 push(SharkValue::create_jlong( 464 builder()->CreateMul(a->jlong_value(), b->jlong_value()), false)); 465 break; 466 case Bytecodes::_ldiv: 467 do_ldiv(); 468 break; 469 case Bytecodes::_lrem: 470 do_lrem(); 471 break; 472 case Bytecodes::_lneg: 473 a = pop(); 474 push(SharkValue::create_jlong( 475 builder()->CreateNeg(a->jlong_value()), a->zero_checked())); 476 break; 477 case Bytecodes::_lshl: 478 b = pop(); 479 a = pop(); 480 push(SharkValue::create_jlong( 481 builder()->CreateShl( 482 a->jlong_value(), 483 builder()->CreateIntCast( 484 builder()->CreateAnd( 485 b->jint_value(), LLVMValue::jint_constant(0x3f)), 486 SharkType::jlong_type(), true)), false)); 487 break; 488 case Bytecodes::_lshr: 489 b = pop(); 490 a = pop(); 491 push(SharkValue::create_jlong( 492 builder()->CreateAShr( 493 a->jlong_value(), 494 builder()->CreateIntCast( 495 builder()->CreateAnd( 496 b->jint_value(), LLVMValue::jint_constant(0x3f)), 497 SharkType::jlong_type(), true)), false)); 498 break; 499 case Bytecodes::_lushr: 500 b = pop(); 501 a = pop(); 502 push(SharkValue::create_jlong( 503 builder()->CreateLShr( 504 a->jlong_value(), 505 builder()->CreateIntCast( 506 builder()->CreateAnd( 507 b->jint_value(), LLVMValue::jint_constant(0x3f)), 508 SharkType::jlong_type(), true)), false)); 509 break; 510 case Bytecodes::_land: 511 b = pop(); 512 a = pop(); 513 push(SharkValue::create_jlong( 514 builder()->CreateAnd(a->jlong_value(), b->jlong_value()), false)); 515 break; 516 case Bytecodes::_lor: 517 b = pop(); 518 a = pop(); 519 push(SharkValue::create_jlong( 520 builder()->CreateOr(a->jlong_value(), b->jlong_value()), 521 a->zero_checked() && b->zero_checked())); 522 break; 523 case Bytecodes::_lxor: 524 b = pop(); 525 a = pop(); 526 push(SharkValue::create_jlong( 527 builder()->CreateXor(a->jlong_value(), b->jlong_value()), false)); 528 break; 529 530 case Bytecodes::_fadd: 531 b = pop(); 532 a = pop(); 533 push(SharkValue::create_jfloat( 534 builder()->CreateFAdd(a->jfloat_value(), b->jfloat_value()))); 535 break; 536 case Bytecodes::_fsub: 537 b = pop(); 538 a = pop(); 539 push(SharkValue::create_jfloat( 540 builder()->CreateFSub(a->jfloat_value(), b->jfloat_value()))); 541 break; 542 case Bytecodes::_fmul: 543 b = pop(); 544 a = pop(); 545 push(SharkValue::create_jfloat( 546 builder()->CreateFMul(a->jfloat_value(), b->jfloat_value()))); 547 break; 548 case Bytecodes::_fdiv: 549 b = pop(); 550 a = pop(); 551 push(SharkValue::create_jfloat( 552 builder()->CreateFDiv(a->jfloat_value(), b->jfloat_value()))); 553 break; 554 case Bytecodes::_frem: 555 b = pop(); 556 a = pop(); 557 push(SharkValue::create_jfloat( 558 builder()->CreateFRem(a->jfloat_value(), b->jfloat_value()))); 559 break; 560 case Bytecodes::_fneg: 561 a = pop(); 562 push(SharkValue::create_jfloat( 563 builder()->CreateFNeg(a->jfloat_value()))); 564 break; 565 566 case Bytecodes::_dadd: 567 b = pop(); 568 a = pop(); 569 push(SharkValue::create_jdouble( 570 builder()->CreateFAdd(a->jdouble_value(), b->jdouble_value()))); 571 break; 572 case Bytecodes::_dsub: 573 b = pop(); 574 a = pop(); 575 push(SharkValue::create_jdouble( 576 builder()->CreateFSub(a->jdouble_value(), b->jdouble_value()))); 577 break; 578 case Bytecodes::_dmul: 579 b = pop(); 580 a = pop(); 581 push(SharkValue::create_jdouble( 582 builder()->CreateFMul(a->jdouble_value(), b->jdouble_value()))); 583 break; 584 case Bytecodes::_ddiv: 585 b = pop(); 586 a = pop(); 587 push(SharkValue::create_jdouble( 588 builder()->CreateFDiv(a->jdouble_value(), b->jdouble_value()))); 589 break; 590 case Bytecodes::_drem: 591 b = pop(); 592 a = pop(); 593 push(SharkValue::create_jdouble( 594 builder()->CreateFRem(a->jdouble_value(), b->jdouble_value()))); 595 break; 596 case Bytecodes::_dneg: 597 a = pop(); 598 push(SharkValue::create_jdouble( 599 builder()->CreateFNeg(a->jdouble_value()))); 600 break; 601 602 case Bytecodes::_iinc: 603 i = iter()->get_index(); 604 set_local( 605 i, 606 SharkValue::create_jint( 607 builder()->CreateAdd( 608 LLVMValue::jint_constant(iter()->get_iinc_con()), 609 local(i)->jint_value()), false)); 610 break; 611 612 case Bytecodes::_lcmp: 613 do_lcmp(); 614 break; 615 616 case Bytecodes::_fcmpl: 617 do_fcmp(false, false); 618 break; 619 case Bytecodes::_fcmpg: 620 do_fcmp(false, true); 621 break; 622 case Bytecodes::_dcmpl: 623 do_fcmp(true, false); 624 break; 625 case Bytecodes::_dcmpg: 626 do_fcmp(true, true); 627 break; 628 629 case Bytecodes::_i2l: 630 a = pop(); 631 push(SharkValue::create_jlong( 632 builder()->CreateIntCast( 633 a->jint_value(), SharkType::jlong_type(), true), a->zero_checked())); 634 break; 635 case Bytecodes::_i2f: 636 push(SharkValue::create_jfloat( 637 builder()->CreateSIToFP( 638 pop()->jint_value(), SharkType::jfloat_type()))); 639 break; 640 case Bytecodes::_i2d: 641 push(SharkValue::create_jdouble( 642 builder()->CreateSIToFP( 643 pop()->jint_value(), SharkType::jdouble_type()))); 644 break; 645 646 case Bytecodes::_l2i: 647 push(SharkValue::create_jint( 648 builder()->CreateIntCast( 649 pop()->jlong_value(), SharkType::jint_type(), true), false)); 650 break; 651 case Bytecodes::_l2f: 652 push(SharkValue::create_jfloat( 653 builder()->CreateSIToFP( 654 pop()->jlong_value(), SharkType::jfloat_type()))); 655 break; 656 case Bytecodes::_l2d: 657 push(SharkValue::create_jdouble( 658 builder()->CreateSIToFP( 659 pop()->jlong_value(), SharkType::jdouble_type()))); 660 break; 661 662 case Bytecodes::_f2i: 663 push(SharkValue::create_jint( 664 builder()->CreateCall( 665 builder()->f2i(), pop()->jfloat_value()), false)); 666 break; 667 case Bytecodes::_f2l: 668 push(SharkValue::create_jlong( 669 builder()->CreateCall( 670 builder()->f2l(), pop()->jfloat_value()), false)); 671 break; 672 case Bytecodes::_f2d: 673 push(SharkValue::create_jdouble( 674 builder()->CreateFPExt( 675 pop()->jfloat_value(), SharkType::jdouble_type()))); 676 break; 677 678 case Bytecodes::_d2i: 679 push(SharkValue::create_jint( 680 builder()->CreateCall( 681 builder()->d2i(), pop()->jdouble_value()), false)); 682 break; 683 case Bytecodes::_d2l: 684 push(SharkValue::create_jlong( 685 builder()->CreateCall( 686 builder()->d2l(), pop()->jdouble_value()), false)); 687 break; 688 case Bytecodes::_d2f: 689 push(SharkValue::create_jfloat( 690 builder()->CreateFPTrunc( 691 pop()->jdouble_value(), SharkType::jfloat_type()))); 692 break; 693 694 case Bytecodes::_i2b: 695 push(SharkValue::create_jint( 696 builder()->CreateAShr( 697 builder()->CreateShl( 698 pop()->jint_value(), 699 LLVMValue::jint_constant(24)), 700 LLVMValue::jint_constant(24)), false)); 701 break; 702 case Bytecodes::_i2c: 703 push(SharkValue::create_jint( 704 builder()->CreateAnd( 705 pop()->jint_value(), 706 LLVMValue::jint_constant(0xffff)), false)); 707 break; 708 case Bytecodes::_i2s: 709 push(SharkValue::create_jint( 710 builder()->CreateAShr( 711 builder()->CreateShl( 712 pop()->jint_value(), 713 LLVMValue::jint_constant(16)), 714 LLVMValue::jint_constant(16)), false)); 715 break; 716 717 case Bytecodes::_return: 718 do_return(T_VOID); 719 break; 720 case Bytecodes::_ireturn: 721 do_return(T_INT); 722 break; 723 case Bytecodes::_lreturn: 724 do_return(T_LONG); 725 break; 726 case Bytecodes::_freturn: 727 do_return(T_FLOAT); 728 break; 729 case Bytecodes::_dreturn: 730 do_return(T_DOUBLE); 731 break; 732 case Bytecodes::_areturn: 733 do_return(T_OBJECT); 734 break; 735 736 case Bytecodes::_athrow: 737 do_athrow(); 738 break; 739 740 case Bytecodes::_goto: 741 case Bytecodes::_goto_w: 742 do_goto(); 743 break; 744 745 case Bytecodes::_jsr: 746 case Bytecodes::_jsr_w: 747 do_jsr(); 748 break; 749 750 case Bytecodes::_ret: 751 do_ret(); 752 break; 753 754 case Bytecodes::_ifnull: 755 do_if(ICmpInst::ICMP_EQ, SharkValue::null(), pop()); 756 break; 757 case Bytecodes::_ifnonnull: 758 do_if(ICmpInst::ICMP_NE, SharkValue::null(), pop()); 759 break; 760 case Bytecodes::_if_acmpeq: 761 b = pop(); 762 a = pop(); 763 do_if(ICmpInst::ICMP_EQ, b, a); 764 break; 765 case Bytecodes::_if_acmpne: 766 b = pop(); 767 a = pop(); 768 do_if(ICmpInst::ICMP_NE, b, a); 769 break; 770 case Bytecodes::_ifeq: 771 do_if(ICmpInst::ICMP_EQ, SharkValue::jint_constant(0), pop()); 772 break; 773 case Bytecodes::_ifne: 774 do_if(ICmpInst::ICMP_NE, SharkValue::jint_constant(0), pop()); 775 break; 776 case Bytecodes::_iflt: 777 do_if(ICmpInst::ICMP_SLT, SharkValue::jint_constant(0), pop()); 778 break; 779 case Bytecodes::_ifle: 780 do_if(ICmpInst::ICMP_SLE, SharkValue::jint_constant(0), pop()); 781 break; 782 case Bytecodes::_ifgt: 783 do_if(ICmpInst::ICMP_SGT, SharkValue::jint_constant(0), pop()); 784 break; 785 case Bytecodes::_ifge: 786 do_if(ICmpInst::ICMP_SGE, SharkValue::jint_constant(0), pop()); 787 break; 788 case Bytecodes::_if_icmpeq: 789 b = pop(); 790 a = pop(); 791 do_if(ICmpInst::ICMP_EQ, b, a); 792 break; 793 case Bytecodes::_if_icmpne: 794 b = pop(); 795 a = pop(); 796 do_if(ICmpInst::ICMP_NE, b, a); 797 break; 798 case Bytecodes::_if_icmplt: 799 b = pop(); 800 a = pop(); 801 do_if(ICmpInst::ICMP_SLT, b, a); 802 break; 803 case Bytecodes::_if_icmple: 804 b = pop(); 805 a = pop(); 806 do_if(ICmpInst::ICMP_SLE, b, a); 807 break; 808 case Bytecodes::_if_icmpgt: 809 b = pop(); 810 a = pop(); 811 do_if(ICmpInst::ICMP_SGT, b, a); 812 break; 813 case Bytecodes::_if_icmpge: 814 b = pop(); 815 a = pop(); 816 do_if(ICmpInst::ICMP_SGE, b, a); 817 break; 818 819 case Bytecodes::_tableswitch: 820 case Bytecodes::_lookupswitch: 821 do_switch(); 822 break; 823 824 case Bytecodes::_invokestatic: 825 case Bytecodes::_invokespecial: 826 case Bytecodes::_invokevirtual: 827 case Bytecodes::_invokeinterface: 828 do_call(); 829 break; 830 831 case Bytecodes::_instanceof: 832 // This is a very common construct: 833 // 834 // if (object instanceof Klass) { 835 // something = (Klass) object; 836 // ... 837 // } 838 // 839 // which gets compiled to something like this: 840 // 841 // 28: aload 9 842 // 30: instanceof <Class Klass> 843 // 33: ifeq 52 844 // 36: aload 9 845 // 38: checkcast <Class Klass> 846 // 847 // Handling both bytecodes at once allows us 848 // to eliminate the checkcast. 849 if (iter()->next_bci() < limit && 850 (iter()->next_bc() == Bytecodes::_ifeq || 851 iter()->next_bc() == Bytecodes::_ifne) && 852 (!UseLoopSafepoints || 853 iter()->next_get_dest() > iter()->next_bci())) { 854 if (maybe_do_instanceof_if()) { 855 iter()->next(); 856 if (SharkTraceBytecodes) 857 tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc())); 858 break; 859 } 860 } 861 // fall through 862 case Bytecodes::_checkcast: 863 do_instance_check(); 864 break; 865 866 case Bytecodes::_new: 867 do_new(); 868 break; 869 case Bytecodes::_newarray: 870 do_newarray(); 871 break; 872 case Bytecodes::_anewarray: 873 do_anewarray(); 874 break; 875 case Bytecodes::_multianewarray: 876 do_multianewarray(); 877 break; 878 879 case Bytecodes::_monitorenter: 880 do_monitorenter(); 881 break; 882 case Bytecodes::_monitorexit: 883 do_monitorexit(); 884 break; 885 886 default: 887 ShouldNotReachHere(); 888 } 889 } 890 } 891 892 SharkState* SharkBlock::initial_current_state() { 893 return entry_state()->copy(); 894 } 895 896 int SharkBlock::switch_default_dest() { 897 return iter()->get_dest_table(0); 898 } 899 900 int SharkBlock::switch_table_length() { 901 switch(bc()) { 902 case Bytecodes::_tableswitch: 903 return iter()->get_int_table(2) - iter()->get_int_table(1) + 1; 904 905 case Bytecodes::_lookupswitch: 906 return iter()->get_int_table(1); 907 908 default: 909 ShouldNotReachHere(); 910 } 911 } 912 913 int SharkBlock::switch_key(int i) { 914 switch(bc()) { 915 case Bytecodes::_tableswitch: 916 return iter()->get_int_table(1) + i; 917 918 case Bytecodes::_lookupswitch: 919 return iter()->get_int_table(2 + 2 * i); 920 921 default: 922 ShouldNotReachHere(); 923 } 924 } 925 926 int SharkBlock::switch_dest(int i) { 927 switch(bc()) { 928 case Bytecodes::_tableswitch: 929 return iter()->get_dest_table(i + 3); 930 931 case Bytecodes::_lookupswitch: 932 return iter()->get_dest_table(2 + 2 * i + 1); 933 934 default: 935 ShouldNotReachHere(); 936 } 937 } 938 939 void SharkBlock::do_div_or_rem(bool is_long, bool is_rem) { 940 SharkValue *sb = pop(); 941 SharkValue *sa = pop(); 942 943 check_divide_by_zero(sb); 944 945 Value *a, *b, *p, *q; 946 if (is_long) { 947 a = sa->jlong_value(); 948 b = sb->jlong_value(); 949 p = LLVMValue::jlong_constant(0x8000000000000000LL); 950 q = LLVMValue::jlong_constant(-1); 951 } 952 else { 953 a = sa->jint_value(); 954 b = sb->jint_value(); 955 p = LLVMValue::jint_constant(0x80000000); 956 q = LLVMValue::jint_constant(-1); 957 } 958 959 BasicBlock *ip = builder()->GetBlockInsertionPoint(); 960 BasicBlock *special_case = builder()->CreateBlock(ip, "special_case"); 961 BasicBlock *general_case = builder()->CreateBlock(ip, "general_case"); 962 BasicBlock *done = builder()->CreateBlock(ip, "done"); 963 964 builder()->CreateCondBr( 965 builder()->CreateAnd( 966 builder()->CreateICmpEQ(a, p), 967 builder()->CreateICmpEQ(b, q)), 968 special_case, general_case); 969 970 builder()->SetInsertPoint(special_case); 971 Value *special_result; 972 if (is_rem) { 973 if (is_long) 974 special_result = LLVMValue::jlong_constant(0); 975 else 976 special_result = LLVMValue::jint_constant(0); 977 } 978 else { 979 special_result = a; 980 } 981 builder()->CreateBr(done); 982 983 builder()->SetInsertPoint(general_case); 984 Value *general_result; 985 if (is_rem) 986 general_result = builder()->CreateSRem(a, b); 987 else 988 general_result = builder()->CreateSDiv(a, b); 989 builder()->CreateBr(done); 990 991 builder()->SetInsertPoint(done); 992 PHINode *result; 993 if (is_long) 994 result = builder()->CreatePHI(SharkType::jlong_type(), "result"); 995 else 996 result = builder()->CreatePHI(SharkType::jint_type(), "result"); 997 result->addIncoming(special_result, special_case); 998 result->addIncoming(general_result, general_case); 999 1000 if (is_long) 1001 push(SharkValue::create_jlong(result, false)); 1002 else 1003 push(SharkValue::create_jint(result, false)); 1004 } 1005 1006 void SharkBlock::do_field_access(bool is_get, bool is_field) { 1007 bool will_link; 1008 ciField *field = iter()->get_field(will_link); 1009 assert(will_link, "typeflow responsibility"); 1010 assert(is_field != field->is_static(), "mismatch"); 1011 1012 // Pop the value off the stack where necessary 1013 SharkValue *value = NULL; 1014 if (!is_get) 1015 value = pop(); 1016 1017 // Find the object we're accessing, if necessary 1018 Value *object = NULL; 1019 if (is_field) { 1020 SharkValue *value = pop(); 1021 check_null(value); 1022 object = value->generic_value(); 1023 } 1024 if (is_get && field->is_constant()) { 1025 SharkConstant *constant = SharkConstant::for_field(iter()); 1026 if (constant->is_loaded()) 1027 value = constant->value(builder()); 1028 } 1029 if (!is_get || value == NULL) { 1030 if (!is_field) 1031 object = builder()->CreateInlineOop(field->holder()); 1032 1033 BasicType basic_type = field->type()->basic_type(); 1034 const Type *stack_type = SharkType::to_stackType(basic_type); 1035 const Type *field_type = SharkType::to_arrayType(basic_type); 1036 1037 Value *addr = builder()->CreateAddressOfStructEntry( 1038 object, in_ByteSize(field->offset_in_bytes()), 1039 PointerType::getUnqual(field_type), 1040 "addr"); 1041 1042 // Do the access 1043 if (is_get) { 1044 Value *field_value = builder()->CreateLoad(addr); 1045 1046 if (field_type != stack_type) { 1047 field_value = builder()->CreateIntCast( 1048 field_value, stack_type, basic_type != T_CHAR); 1049 } 1050 1051 value = SharkValue::create_generic(field->type(), field_value, false); 1052 } 1053 else { 1054 Value *field_value = value->generic_value(); 1055 1056 if (field_type != stack_type) { 1057 field_value = builder()->CreateIntCast( 1058 field_value, field_type, basic_type != T_CHAR); 1059 } 1060 1061 builder()->CreateStore(field_value, addr); 1062 1063 if (!field->type()->is_primitive_type()) 1064 builder()->CreateUpdateBarrierSet(oopDesc::bs(), addr); 1065 1066 if (field->is_volatile()) 1067 builder()->CreateMemoryBarrier(SharkBuilder::BARRIER_STORELOAD); 1068 } 1069 } 1070 1071 // Push the value onto the stack where necessary 1072 if (is_get) 1073 push(value); 1074 } 1075 1076 void SharkBlock::do_lcmp() { 1077 Value *b = pop()->jlong_value(); 1078 Value *a = pop()->jlong_value(); 1079 1080 BasicBlock *ip = builder()->GetBlockInsertionPoint(); 1081 BasicBlock *ne = builder()->CreateBlock(ip, "lcmp_ne"); 1082 BasicBlock *lt = builder()->CreateBlock(ip, "lcmp_lt"); 1083 BasicBlock *gt = builder()->CreateBlock(ip, "lcmp_gt"); 1084 BasicBlock *done = builder()->CreateBlock(ip, "done"); 1085 1086 BasicBlock *eq = builder()->GetInsertBlock(); 1087 builder()->CreateCondBr(builder()->CreateICmpEQ(a, b), done, ne); 1088 1089 builder()->SetInsertPoint(ne); 1090 builder()->CreateCondBr(builder()->CreateICmpSLT(a, b), lt, gt); 1091 1092 builder()->SetInsertPoint(lt); 1093 builder()->CreateBr(done); 1094 1095 builder()->SetInsertPoint(gt); 1096 builder()->CreateBr(done); 1097 1098 builder()->SetInsertPoint(done); 1099 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), "result"); 1100 result->addIncoming(LLVMValue::jint_constant(-1), lt); 1101 result->addIncoming(LLVMValue::jint_constant(0), eq); 1102 result->addIncoming(LLVMValue::jint_constant(1), gt); 1103 1104 push(SharkValue::create_jint(result, false)); 1105 } 1106 1107 void SharkBlock::do_fcmp(bool is_double, bool unordered_is_greater) { 1108 Value *a, *b; 1109 if (is_double) { 1110 b = pop()->jdouble_value(); 1111 a = pop()->jdouble_value(); 1112 } 1113 else { 1114 b = pop()->jfloat_value(); 1115 a = pop()->jfloat_value(); 1116 } 1117 1118 BasicBlock *ip = builder()->GetBlockInsertionPoint(); 1119 BasicBlock *ordered = builder()->CreateBlock(ip, "ordered"); 1120 BasicBlock *ge = builder()->CreateBlock(ip, "fcmp_ge"); 1121 BasicBlock *lt = builder()->CreateBlock(ip, "fcmp_lt"); 1122 BasicBlock *eq = builder()->CreateBlock(ip, "fcmp_eq"); 1123 BasicBlock *gt = builder()->CreateBlock(ip, "fcmp_gt"); 1124 BasicBlock *done = builder()->CreateBlock(ip, "done"); 1125 1126 builder()->CreateCondBr( 1127 builder()->CreateFCmpUNO(a, b), 1128 unordered_is_greater ? gt : lt, ordered); 1129 1130 builder()->SetInsertPoint(ordered); 1131 builder()->CreateCondBr(builder()->CreateFCmpULT(a, b), lt, ge); 1132 1133 builder()->SetInsertPoint(ge); 1134 builder()->CreateCondBr(builder()->CreateFCmpUGT(a, b), gt, eq); 1135 1136 builder()->SetInsertPoint(lt); 1137 builder()->CreateBr(done); 1138 1139 builder()->SetInsertPoint(gt); 1140 builder()->CreateBr(done); 1141 1142 builder()->SetInsertPoint(eq); 1143 builder()->CreateBr(done); 1144 1145 builder()->SetInsertPoint(done); 1146 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), "result"); 1147 result->addIncoming(LLVMValue::jint_constant(-1), lt); 1148 result->addIncoming(LLVMValue::jint_constant(0), eq); 1149 result->addIncoming(LLVMValue::jint_constant(1), gt); 1150 1151 push(SharkValue::create_jint(result, false)); 1152 } 1153 1154 void SharkBlock::emit_IR() { 1155 ShouldNotCallThis(); 1156 } 1157 1158 SharkState* SharkBlock::entry_state() { 1159 ShouldNotCallThis(); 1160 } 1161 1162 void SharkBlock::do_zero_check(SharkValue* value) { 1163 ShouldNotCallThis(); 1164 } 1165 1166 void SharkBlock::maybe_add_backedge_safepoint() { 1167 ShouldNotCallThis(); 1168 } 1169 1170 bool SharkBlock::has_trap() { 1171 return false; 1172 } 1173 1174 int SharkBlock::trap_request() { 1175 ShouldNotCallThis(); 1176 } 1177 1178 int SharkBlock::trap_bci() { 1179 ShouldNotCallThis(); 1180 } 1181 1182 void SharkBlock::do_trap(int trap_request) { 1183 ShouldNotCallThis(); 1184 } 1185 1186 void SharkBlock::do_arraylength() { 1187 ShouldNotCallThis(); 1188 } 1189 1190 void SharkBlock::do_aload(BasicType basic_type) { 1191 ShouldNotCallThis(); 1192 } 1193 1194 void SharkBlock::do_astore(BasicType basic_type) { 1195 ShouldNotCallThis(); 1196 } 1197 1198 void SharkBlock::do_return(BasicType type) { 1199 ShouldNotCallThis(); 1200 } 1201 1202 void SharkBlock::do_athrow() { 1203 ShouldNotCallThis(); 1204 } 1205 1206 void SharkBlock::do_goto() { 1207 ShouldNotCallThis(); 1208 } 1209 1210 void SharkBlock::do_jsr() { 1211 ShouldNotCallThis(); 1212 } 1213 1214 void SharkBlock::do_ret() { 1215 ShouldNotCallThis(); 1216 } 1217 1218 void SharkBlock::do_if(ICmpInst::Predicate p, SharkValue* b, SharkValue* a) { 1219 ShouldNotCallThis(); 1220 } 1221 1222 void SharkBlock::do_switch() { 1223 ShouldNotCallThis(); 1224 } 1225 1226 void SharkBlock::do_call() { 1227 ShouldNotCallThis(); 1228 } 1229 1230 void SharkBlock::do_instance_check() { 1231 ShouldNotCallThis(); 1232 } 1233 1234 bool SharkBlock::maybe_do_instanceof_if() { 1235 ShouldNotCallThis(); 1236 } 1237 1238 void SharkBlock::do_new() { 1239 ShouldNotCallThis(); 1240 } 1241 1242 void SharkBlock::do_newarray() { 1243 ShouldNotCallThis(); 1244 } 1245 1246 void SharkBlock::do_anewarray() { 1247 ShouldNotCallThis(); 1248 } 1249 1250 void SharkBlock::do_multianewarray() { 1251 ShouldNotCallThis(); 1252 } 1253 1254 void SharkBlock::do_monitorenter() { 1255 ShouldNotCallThis(); 1256 } 1257 1258 void SharkBlock::do_monitorexit() { 1259 ShouldNotCallThis(); 1260 }