330 int l = sw.length(); 331 for (int i = 0; i < l; i++) { 332 make_block_at(cur_bci + sw.dest_offset_at(i), current); 333 } 334 make_block_at(cur_bci + sw.default_offset(), current); 335 current = NULL; 336 break; 337 } 338 339 case Bytecodes::_lookupswitch: { 340 // set block for each case 341 Bytecode_lookupswitch sw(&s); 342 int l = sw.number_of_pairs(); 343 for (int i = 0; i < l; i++) { 344 make_block_at(cur_bci + sw.pair_at(i).offset(), current); 345 } 346 make_block_at(cur_bci + sw.default_offset(), current); 347 current = NULL; 348 break; 349 } 350 } 351 } 352 } 353 354 355 void BlockListBuilder::mark_loops() { 356 ResourceMark rm; 357 358 _active.initialize(BlockBegin::number_of_blocks()); 359 _visited.initialize(BlockBegin::number_of_blocks()); 360 _loop_map = intArray(BlockBegin::number_of_blocks(), BlockBegin::number_of_blocks(), 0); 361 _next_loop_index = 0; 362 _next_block_number = _blocks.length(); 363 364 // recursively iterate the control flow graph 365 mark_loops(_bci2block->at(0), false); 366 assert(_next_block_number >= 0, "invalid block numbers"); 367 368 // Remove dangling Resource pointers before the ResourceMark goes out-of-scope. 369 _active.resize(0); 1471 } 1472 case T_SHORT: 1473 { 1474 Value shift = append(new Constant(new IntConstant(16))); 1475 x = append(new ShiftOp(Bytecodes::_ishl, x, shift)); 1476 x = append(new ShiftOp(Bytecodes::_ishr, x, shift)); 1477 break; 1478 } 1479 case T_CHAR: 1480 { 1481 Value mask = append(new Constant(new IntConstant(0xFFFF))); 1482 x = append(new LogicOp(Bytecodes::_iand, x, mask)); 1483 break; 1484 } 1485 case T_BOOLEAN: 1486 { 1487 Value mask = append(new Constant(new IntConstant(1))); 1488 x = append(new LogicOp(Bytecodes::_iand, x, mask)); 1489 break; 1490 } 1491 } 1492 1493 // Check to see whether we are inlining. If so, Return 1494 // instructions become Gotos to the continuation point. 1495 if (continuation() != NULL) { 1496 1497 int invoke_bci = state()->caller_state()->bci(); 1498 1499 if (x != NULL && !ignore_return) { 1500 ciMethod* caller = state()->scope()->caller()->method(); 1501 Bytecodes::Code invoke_raw_bc = caller->raw_code_at_bci(invoke_bci); 1502 if (invoke_raw_bc == Bytecodes::_invokehandle || invoke_raw_bc == Bytecodes::_invokedynamic) { 1503 ciType* declared_ret_type = caller->get_declared_signature_at_bci(invoke_bci)->return_type(); 1504 if (declared_ret_type->is_klass() && x->exact_type() == NULL && 1505 x->declared_type() != declared_ret_type && declared_ret_type != compilation()->env()->Object_klass()) { 1506 x = append(new TypeCast(declared_ret_type->as_klass(), x, copy_state_before())); 1507 } 1508 } 1509 } 1510 1830 calling_klass; 1831 if (sender_klass->is_interface()) { 1832 int index = state()->stack_size() - (target->arg_size_no_receiver() + 1); 1833 Value receiver = state()->stack_at(index); 1834 CheckCast* c = new CheckCast(sender_klass, receiver, copy_state_before()); 1835 c->set_invokespecial_receiver_check(); 1836 state()->stack_at_put(index, append_split(c)); 1837 } 1838 } 1839 1840 // Some methods are obviously bindable without any type checks so 1841 // convert them directly to an invokespecial or invokestatic. 1842 if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) { 1843 switch (bc_raw) { 1844 case Bytecodes::_invokevirtual: 1845 code = Bytecodes::_invokespecial; 1846 break; 1847 case Bytecodes::_invokehandle: 1848 code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial; 1849 break; 1850 } 1851 } else { 1852 if (bc_raw == Bytecodes::_invokehandle) { 1853 assert(!will_link, "should come here only for unlinked call"); 1854 code = Bytecodes::_invokespecial; 1855 } 1856 } 1857 1858 // Push appendix argument (MethodType, CallSite, etc.), if one. 1859 bool patch_for_appendix = false; 1860 int patching_appendix_arg = 0; 1861 if (Bytecodes::has_optional_appendix(bc_raw) && (!will_link || PatchALot)) { 1862 Value arg = append(new Constant(new ObjectConstant(compilation()->env()->unloaded_ciinstance()), copy_state_before())); 1863 apush(arg); 1864 patch_for_appendix = true; 1865 patching_appendix_arg = (will_link && stream()->has_appendix()) ? 0 : 1; 1866 } else if (stream()->has_appendix()) { 1867 ciObject* appendix = stream()->get_appendix(); 1868 Value arg = append(new Constant(new ObjectConstant(appendix))); 1869 apush(arg); 1976 if (cha_monomorphic_target->is_abstract()) { 1977 // Do not optimize for abstract methods 1978 cha_monomorphic_target = NULL; 1979 } 1980 } 1981 1982 if (cha_monomorphic_target != NULL) { 1983 if (!(target->is_final_method())) { 1984 // If we inlined because CHA revealed only a single target method, 1985 // then we are dependent on that target method not getting overridden 1986 // by dynamic class loading. Be sure to test the "static" receiver 1987 // dest_method here, as opposed to the actual receiver, which may 1988 // falsely lead us to believe that the receiver is final or private. 1989 dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target); 1990 } 1991 code = Bytecodes::_invokespecial; 1992 } 1993 1994 // check if we could do inlining 1995 if (!PatchALot && Inline && target->is_loaded() && 1996 (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized()) 1997 && !patch_for_appendix) { 1998 // callee is known => check if we have static binding 1999 if (code == Bytecodes::_invokestatic || 2000 code == Bytecodes::_invokespecial || 2001 code == Bytecodes::_invokevirtual && target->is_final_method() || 2002 code == Bytecodes::_invokedynamic) { 2003 ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target; 2004 // static binding => check if callee is ok 2005 bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), false, code, better_receiver); 2006 2007 CHECK_BAILOUT(); 2008 clear_inline_bailout(); 2009 2010 if (success) { 2011 // Register dependence if JVMTI has either breakpoint 2012 // setting or hotswapping of methods capabilities since they may 2013 // cause deoptimization. 2014 if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) { 2015 dependency_recorder()->assert_evol_method(inline_target); 2016 } 2017 return; 2018 } 2019 } else { 2020 print_inlining(target, "no static binding", /*success*/ false); 2021 } | 330 int l = sw.length(); 331 for (int i = 0; i < l; i++) { 332 make_block_at(cur_bci + sw.dest_offset_at(i), current); 333 } 334 make_block_at(cur_bci + sw.default_offset(), current); 335 current = NULL; 336 break; 337 } 338 339 case Bytecodes::_lookupswitch: { 340 // set block for each case 341 Bytecode_lookupswitch sw(&s); 342 int l = sw.number_of_pairs(); 343 for (int i = 0; i < l; i++) { 344 make_block_at(cur_bci + sw.pair_at(i).offset(), current); 345 } 346 make_block_at(cur_bci + sw.default_offset(), current); 347 current = NULL; 348 break; 349 } 350 351 default: 352 break; 353 } 354 } 355 } 356 357 358 void BlockListBuilder::mark_loops() { 359 ResourceMark rm; 360 361 _active.initialize(BlockBegin::number_of_blocks()); 362 _visited.initialize(BlockBegin::number_of_blocks()); 363 _loop_map = intArray(BlockBegin::number_of_blocks(), BlockBegin::number_of_blocks(), 0); 364 _next_loop_index = 0; 365 _next_block_number = _blocks.length(); 366 367 // recursively iterate the control flow graph 368 mark_loops(_bci2block->at(0), false); 369 assert(_next_block_number >= 0, "invalid block numbers"); 370 371 // Remove dangling Resource pointers before the ResourceMark goes out-of-scope. 372 _active.resize(0); 1474 } 1475 case T_SHORT: 1476 { 1477 Value shift = append(new Constant(new IntConstant(16))); 1478 x = append(new ShiftOp(Bytecodes::_ishl, x, shift)); 1479 x = append(new ShiftOp(Bytecodes::_ishr, x, shift)); 1480 break; 1481 } 1482 case T_CHAR: 1483 { 1484 Value mask = append(new Constant(new IntConstant(0xFFFF))); 1485 x = append(new LogicOp(Bytecodes::_iand, x, mask)); 1486 break; 1487 } 1488 case T_BOOLEAN: 1489 { 1490 Value mask = append(new Constant(new IntConstant(1))); 1491 x = append(new LogicOp(Bytecodes::_iand, x, mask)); 1492 break; 1493 } 1494 default: 1495 break; 1496 } 1497 1498 // Check to see whether we are inlining. If so, Return 1499 // instructions become Gotos to the continuation point. 1500 if (continuation() != NULL) { 1501 1502 int invoke_bci = state()->caller_state()->bci(); 1503 1504 if (x != NULL && !ignore_return) { 1505 ciMethod* caller = state()->scope()->caller()->method(); 1506 Bytecodes::Code invoke_raw_bc = caller->raw_code_at_bci(invoke_bci); 1507 if (invoke_raw_bc == Bytecodes::_invokehandle || invoke_raw_bc == Bytecodes::_invokedynamic) { 1508 ciType* declared_ret_type = caller->get_declared_signature_at_bci(invoke_bci)->return_type(); 1509 if (declared_ret_type->is_klass() && x->exact_type() == NULL && 1510 x->declared_type() != declared_ret_type && declared_ret_type != compilation()->env()->Object_klass()) { 1511 x = append(new TypeCast(declared_ret_type->as_klass(), x, copy_state_before())); 1512 } 1513 } 1514 } 1515 1835 calling_klass; 1836 if (sender_klass->is_interface()) { 1837 int index = state()->stack_size() - (target->arg_size_no_receiver() + 1); 1838 Value receiver = state()->stack_at(index); 1839 CheckCast* c = new CheckCast(sender_klass, receiver, copy_state_before()); 1840 c->set_invokespecial_receiver_check(); 1841 state()->stack_at_put(index, append_split(c)); 1842 } 1843 } 1844 1845 // Some methods are obviously bindable without any type checks so 1846 // convert them directly to an invokespecial or invokestatic. 1847 if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) { 1848 switch (bc_raw) { 1849 case Bytecodes::_invokevirtual: 1850 code = Bytecodes::_invokespecial; 1851 break; 1852 case Bytecodes::_invokehandle: 1853 code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial; 1854 break; 1855 default: 1856 break; 1857 } 1858 } else { 1859 if (bc_raw == Bytecodes::_invokehandle) { 1860 assert(!will_link, "should come here only for unlinked call"); 1861 code = Bytecodes::_invokespecial; 1862 } 1863 } 1864 1865 // Push appendix argument (MethodType, CallSite, etc.), if one. 1866 bool patch_for_appendix = false; 1867 int patching_appendix_arg = 0; 1868 if (Bytecodes::has_optional_appendix(bc_raw) && (!will_link || PatchALot)) { 1869 Value arg = append(new Constant(new ObjectConstant(compilation()->env()->unloaded_ciinstance()), copy_state_before())); 1870 apush(arg); 1871 patch_for_appendix = true; 1872 patching_appendix_arg = (will_link && stream()->has_appendix()) ? 0 : 1; 1873 } else if (stream()->has_appendix()) { 1874 ciObject* appendix = stream()->get_appendix(); 1875 Value arg = append(new Constant(new ObjectConstant(appendix))); 1876 apush(arg); 1983 if (cha_monomorphic_target->is_abstract()) { 1984 // Do not optimize for abstract methods 1985 cha_monomorphic_target = NULL; 1986 } 1987 } 1988 1989 if (cha_monomorphic_target != NULL) { 1990 if (!(target->is_final_method())) { 1991 // If we inlined because CHA revealed only a single target method, 1992 // then we are dependent on that target method not getting overridden 1993 // by dynamic class loading. Be sure to test the "static" receiver 1994 // dest_method here, as opposed to the actual receiver, which may 1995 // falsely lead us to believe that the receiver is final or private. 1996 dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target); 1997 } 1998 code = Bytecodes::_invokespecial; 1999 } 2000 2001 // check if we could do inlining 2002 if (!PatchALot && Inline && target->is_loaded() && 2003 (klass->is_initialized() || (klass->is_interface() && target->holder()->is_initialized())) 2004 && !patch_for_appendix) { 2005 // callee is known => check if we have static binding 2006 if (code == Bytecodes::_invokestatic || 2007 code == Bytecodes::_invokespecial || 2008 (code == Bytecodes::_invokevirtual && target->is_final_method()) || 2009 code == Bytecodes::_invokedynamic) { 2010 ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target; 2011 // static binding => check if callee is ok 2012 bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), false, code, better_receiver); 2013 2014 CHECK_BAILOUT(); 2015 clear_inline_bailout(); 2016 2017 if (success) { 2018 // Register dependence if JVMTI has either breakpoint 2019 // setting or hotswapping of methods capabilities since they may 2020 // cause deoptimization. 2021 if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) { 2022 dependency_recorder()->assert_evol_method(inline_target); 2023 } 2024 return; 2025 } 2026 } else { 2027 print_inlining(target, "no static binding", /*success*/ false); 2028 } |