1 /* 2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "ci/ciCallProfile.hpp" 27 #include "ci/ciExceptionHandler.hpp" 28 #include "ci/ciInstanceKlass.hpp" 29 #include "ci/ciMethod.hpp" 30 #include "ci/ciMethodBlocks.hpp" 31 #include "ci/ciMethodData.hpp" 32 #include "ci/ciStreams.hpp" 33 #include "ci/ciSymbol.hpp" 34 #include "ci/ciReplay.hpp" 35 #include "ci/ciUtilities.hpp" 36 #include "classfile/systemDictionary.hpp" 37 #include "compiler/abstractCompiler.hpp" 38 #include "compiler/methodLiveness.hpp" 39 #include "interpreter/interpreter.hpp" 40 #include "interpreter/linkResolver.hpp" 41 #include "interpreter/oopMapCache.hpp" 42 #include "memory/allocation.inline.hpp" 43 #include "memory/resourceArea.hpp" 44 #include "oops/generateOopMap.hpp" 45 #include "oops/oop.inline.hpp" 46 #include "prims/nativeLookup.hpp" 47 #include "runtime/deoptimization.hpp" 48 #include "utilities/bitMap.inline.hpp" 49 #include "utilities/xmlstream.hpp" 50 #include "trace/tracing.hpp" 51 #ifdef COMPILER2 52 #include "ci/bcEscapeAnalyzer.hpp" 53 #include "ci/ciTypeFlow.hpp" 54 #include "oops/method.hpp" 55 #endif 56 #ifdef SHARK 57 #include "ci/ciTypeFlow.hpp" 58 #include "oops/method.hpp" 59 #endif 60 61 // ciMethod 62 // 63 // This class represents a Method* in the HotSpot virtual 64 // machine. 65 66 67 // ------------------------------------------------------------------ 68 // ciMethod::ciMethod 69 // 70 // Loaded method. 71 ciMethod::ciMethod(methodHandle h_m, ciInstanceKlass* holder) : 72 ciMetadata(h_m()), 73 _holder(holder) 74 { 75 assert(h_m() != NULL, "no null method"); 76 77 if (LogTouchedMethods) { 78 h_m()->log_touched(Thread::current()); 79 } 80 // These fields are always filled in in loaded methods. 81 _flags = ciFlags(h_m()->access_flags()); 82 83 // Easy to compute, so fill them in now. 84 _max_stack = h_m()->max_stack(); 85 _max_locals = h_m()->max_locals(); 86 _code_size = h_m()->code_size(); 87 _intrinsic_id = h_m()->intrinsic_id(); 88 _handler_count = h_m()->exception_table_length(); 89 _size_of_parameters = h_m()->size_of_parameters(); 90 _uses_monitors = h_m()->access_flags().has_monitor_bytecodes(); 91 _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching(); 92 _is_c1_compilable = !h_m()->is_not_c1_compilable(); 93 _is_c2_compilable = !h_m()->is_not_c2_compilable(); 94 // Lazy fields, filled in on demand. Require allocation. 95 _code = NULL; 96 _exception_handlers = NULL; 97 _liveness = NULL; 98 _method_blocks = NULL; 99 #if defined(COMPILER2) || defined(SHARK) 100 _flow = NULL; 101 _bcea = NULL; 102 #endif // COMPILER2 || SHARK 103 104 ciEnv *env = CURRENT_ENV; 105 if (env->jvmti_can_hotswap_or_post_breakpoint() && can_be_compiled()) { 106 // 6328518 check hotswap conditions under the right lock. 107 MutexLocker locker(Compile_lock); 108 if (Dependencies::check_evol_method(h_m()) != NULL) { 109 _is_c1_compilable = false; 110 _is_c2_compilable = false; 111 } 112 } else { 113 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); 114 } 115 116 if (h_m()->method_holder()->is_linked()) { 117 _can_be_statically_bound = h_m()->can_be_statically_bound(); 118 } else { 119 // Have to use a conservative value in this case. 120 _can_be_statically_bound = false; 121 } 122 123 // Adjust the definition of this condition to be more useful: 124 // %%% take these conditions into account in vtable generation 125 if (!_can_be_statically_bound && h_m()->is_private()) 126 _can_be_statically_bound = true; 127 if (_can_be_statically_bound && h_m()->is_abstract()) 128 _can_be_statically_bound = false; 129 130 // generating _signature may allow GC and therefore move m. 131 // These fields are always filled in. 132 _name = env->get_symbol(h_m()->name()); 133 ciSymbol* sig_symbol = env->get_symbol(h_m()->signature()); 134 constantPoolHandle cpool = h_m()->constants(); 135 _signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol); 136 _method_data = NULL; 137 _nmethod_age = h_m()->nmethod_age(); 138 // Take a snapshot of these values, so they will be commensurate with the MDO. 139 if (ProfileInterpreter || TieredCompilation) { 140 int invcnt = h_m()->interpreter_invocation_count(); 141 // if the value overflowed report it as max int 142 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ; 143 _interpreter_throwout_count = h_m()->interpreter_throwout_count(); 144 } else { 145 _interpreter_invocation_count = 0; 146 _interpreter_throwout_count = 0; 147 } 148 if (_interpreter_invocation_count == 0) 149 _interpreter_invocation_count = 1; 150 _instructions_size = -1; 151 #ifdef ASSERT 152 if (ReplayCompiles) { 153 ciReplay::initialize(this); 154 } 155 #endif 156 } 157 158 159 // ------------------------------------------------------------------ 160 // ciMethod::ciMethod 161 // 162 // Unloaded method. 163 ciMethod::ciMethod(ciInstanceKlass* holder, 164 ciSymbol* name, 165 ciSymbol* signature, 166 ciInstanceKlass* accessor) : 167 ciMetadata((Metadata*)NULL), 168 _name( name), 169 _holder( holder), 170 _intrinsic_id( vmIntrinsics::_none), 171 _liveness( NULL), 172 _can_be_statically_bound(false), 173 _method_blocks( NULL), 174 _method_data( NULL) 175 #if defined(COMPILER2) || defined(SHARK) 176 , 177 _flow( NULL), 178 _bcea( NULL), 179 _instructions_size(-1) 180 #endif // COMPILER2 || SHARK 181 { 182 // Usually holder and accessor are the same type but in some cases 183 // the holder has the wrong class loader (e.g. invokedynamic call 184 // sites) so we pass the accessor. 185 _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature); 186 } 187 188 189 // ------------------------------------------------------------------ 190 // ciMethod::load_code 191 // 192 // Load the bytecodes and exception handler table for this method. 193 void ciMethod::load_code() { 194 VM_ENTRY_MARK; 195 assert(is_loaded(), "only loaded methods have code"); 196 197 Method* me = get_Method(); 198 Arena* arena = CURRENT_THREAD_ENV->arena(); 199 200 // Load the bytecodes. 201 _code = (address)arena->Amalloc(code_size()); 202 memcpy(_code, me->code_base(), code_size()); 203 204 // Revert any breakpoint bytecodes in ci's copy 205 if (me->number_of_breakpoints() > 0) { 206 BreakpointInfo* bp = me->method_holder()->breakpoints(); 207 for (; bp != NULL; bp = bp->next()) { 208 if (bp->match(me)) { 209 code_at_put(bp->bci(), bp->orig_bytecode()); 210 } 211 } 212 } 213 214 // And load the exception table. 215 ExceptionTable exc_table(me); 216 217 // Allocate one extra spot in our list of exceptions. This 218 // last entry will be used to represent the possibility that 219 // an exception escapes the method. See ciExceptionHandlerStream 220 // for details. 221 _exception_handlers = 222 (ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*) 223 * (_handler_count + 1)); 224 if (_handler_count > 0) { 225 for (int i=0; i<_handler_count; i++) { 226 _exception_handlers[i] = new (arena) ciExceptionHandler( 227 holder(), 228 /* start */ exc_table.start_pc(i), 229 /* limit */ exc_table.end_pc(i), 230 /* goto pc */ exc_table.handler_pc(i), 231 /* cp index */ exc_table.catch_type_index(i)); 232 } 233 } 234 235 // Put an entry at the end of our list to represent the possibility 236 // of exceptional exit. 237 _exception_handlers[_handler_count] = 238 new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0); 239 240 if (CIPrintMethodCodes) { 241 print_codes(); 242 } 243 } 244 245 246 // ------------------------------------------------------------------ 247 // ciMethod::has_linenumber_table 248 // 249 // length unknown until decompression 250 bool ciMethod::has_linenumber_table() const { 251 check_is_loaded(); 252 VM_ENTRY_MARK; 253 return get_Method()->has_linenumber_table(); 254 } 255 256 257 // ------------------------------------------------------------------ 258 // ciMethod::compressed_linenumber_table 259 u_char* ciMethod::compressed_linenumber_table() const { 260 check_is_loaded(); 261 VM_ENTRY_MARK; 262 return get_Method()->compressed_linenumber_table(); 263 } 264 265 266 // ------------------------------------------------------------------ 267 // ciMethod::line_number_from_bci 268 int ciMethod::line_number_from_bci(int bci) const { 269 check_is_loaded(); 270 VM_ENTRY_MARK; 271 return get_Method()->line_number_from_bci(bci); 272 } 273 274 275 // ------------------------------------------------------------------ 276 // ciMethod::vtable_index 277 // 278 // Get the position of this method's entry in the vtable, if any. 279 int ciMethod::vtable_index() { 280 check_is_loaded(); 281 assert(holder()->is_linked(), "must be linked"); 282 VM_ENTRY_MARK; 283 return get_Method()->vtable_index(); 284 } 285 286 287 #ifdef SHARK 288 // ------------------------------------------------------------------ 289 // ciMethod::itable_index 290 // 291 // Get the position of this method's entry in the itable, if any. 292 int ciMethod::itable_index() { 293 check_is_loaded(); 294 assert(holder()->is_linked(), "must be linked"); 295 VM_ENTRY_MARK; 296 Method* m = get_Method(); 297 if (!m->has_itable_index()) 298 return Method::nonvirtual_vtable_index; 299 return m->itable_index(); 300 } 301 #endif // SHARK 302 303 304 // ------------------------------------------------------------------ 305 // ciMethod::native_entry 306 // 307 // Get the address of this method's native code, if any. 308 address ciMethod::native_entry() { 309 check_is_loaded(); 310 assert(flags().is_native(), "must be native method"); 311 VM_ENTRY_MARK; 312 Method* method = get_Method(); 313 address entry = method->native_function(); 314 assert(entry != NULL, "must be valid entry point"); 315 return entry; 316 } 317 318 319 // ------------------------------------------------------------------ 320 // ciMethod::interpreter_entry 321 // 322 // Get the entry point for running this method in the interpreter. 323 address ciMethod::interpreter_entry() { 324 check_is_loaded(); 325 VM_ENTRY_MARK; 326 methodHandle mh(THREAD, get_Method()); 327 return Interpreter::entry_for_method(mh); 328 } 329 330 331 // ------------------------------------------------------------------ 332 // ciMethod::uses_balanced_monitors 333 // 334 // Does this method use monitors in a strict stack-disciplined manner? 335 bool ciMethod::has_balanced_monitors() { 336 check_is_loaded(); 337 if (_balanced_monitors) return true; 338 339 // Analyze the method to see if monitors are used properly. 340 VM_ENTRY_MARK; 341 methodHandle method(THREAD, get_Method()); 342 assert(method->has_monitor_bytecodes(), "should have checked this"); 343 344 // Check to see if a previous compilation computed the 345 // monitor-matching analysis. 346 if (method->guaranteed_monitor_matching()) { 347 _balanced_monitors = true; 348 return true; 349 } 350 351 { 352 EXCEPTION_MARK; 353 ResourceMark rm(THREAD); 354 GeneratePairingInfo gpi(method); 355 gpi.compute_map(CATCH); 356 if (!gpi.monitor_safe()) { 357 return false; 358 } 359 method->set_guaranteed_monitor_matching(); 360 _balanced_monitors = true; 361 } 362 return true; 363 } 364 365 366 // ------------------------------------------------------------------ 367 // ciMethod::get_flow_analysis 368 ciTypeFlow* ciMethod::get_flow_analysis() { 369 #if defined(COMPILER2) || defined(SHARK) 370 if (_flow == NULL) { 371 ciEnv* env = CURRENT_ENV; 372 _flow = new (env->arena()) ciTypeFlow(env, this); 373 _flow->do_flow(); 374 } 375 return _flow; 376 #else // COMPILER2 || SHARK 377 ShouldNotReachHere(); 378 return NULL; 379 #endif // COMPILER2 || SHARK 380 } 381 382 383 // ------------------------------------------------------------------ 384 // ciMethod::get_osr_flow_analysis 385 ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) { 386 #if defined(COMPILER2) || defined(SHARK) 387 // OSR entry points are always place after a call bytecode of some sort 388 assert(osr_bci >= 0, "must supply valid OSR entry point"); 389 ciEnv* env = CURRENT_ENV; 390 ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci); 391 flow->do_flow(); 392 return flow; 393 #else // COMPILER2 || SHARK 394 ShouldNotReachHere(); 395 return NULL; 396 #endif // COMPILER2 || SHARK 397 } 398 399 // ------------------------------------------------------------------ 400 // ciMethod::raw_liveness_at_bci 401 // 402 // Which local variables are live at a specific bci? 403 MethodLivenessResult ciMethod::raw_liveness_at_bci(int bci) { 404 check_is_loaded(); 405 if (_liveness == NULL) { 406 // Create the liveness analyzer. 407 Arena* arena = CURRENT_ENV->arena(); 408 _liveness = new (arena) MethodLiveness(arena, this); 409 _liveness->compute_liveness(); 410 } 411 return _liveness->get_liveness_at(bci); 412 } 413 414 // ------------------------------------------------------------------ 415 // ciMethod::liveness_at_bci 416 // 417 // Which local variables are live at a specific bci? When debugging 418 // will return true for all locals in some cases to improve debug 419 // information. 420 MethodLivenessResult ciMethod::liveness_at_bci(int bci) { 421 MethodLivenessResult result = raw_liveness_at_bci(bci); 422 if (CURRENT_ENV->should_retain_local_variables() || DeoptimizeALot || CompileTheWorld) { 423 // Keep all locals live for the user's edification and amusement. 424 result.at_put_range(0, result.size(), true); 425 } 426 return result; 427 } 428 429 // ciMethod::live_local_oops_at_bci 430 // 431 // find all the live oops in the locals array for a particular bci 432 // Compute what the interpreter believes by using the interpreter 433 // oopmap generator. This is used as a double check during osr to 434 // guard against conservative result from MethodLiveness making us 435 // think a dead oop is live. MethodLiveness is conservative in the 436 // sense that it may consider locals to be live which cannot be live, 437 // like in the case where a local could contain an oop or a primitive 438 // along different paths. In that case the local must be dead when 439 // those paths merge. Since the interpreter's viewpoint is used when 440 // gc'ing an interpreter frame we need to use its viewpoint during 441 // OSR when loading the locals. 442 443 BitMap ciMethod::live_local_oops_at_bci(int bci) { 444 VM_ENTRY_MARK; 445 InterpreterOopMap mask; 446 OopMapCache::compute_one_oop_map(get_Method(), bci, &mask); 447 int mask_size = max_locals(); 448 BitMap result(mask_size); 449 result.clear(); 450 int i; 451 for (i = 0; i < mask_size ; i++ ) { 452 if (mask.is_oop(i)) result.set_bit(i); 453 } 454 return result; 455 } 456 457 458 #ifdef COMPILER1 459 // ------------------------------------------------------------------ 460 // ciMethod::bci_block_start 461 // 462 // Marks all bcis where a new basic block starts 463 const BitMap ciMethod::bci_block_start() { 464 check_is_loaded(); 465 if (_liveness == NULL) { 466 // Create the liveness analyzer. 467 Arena* arena = CURRENT_ENV->arena(); 468 _liveness = new (arena) MethodLiveness(arena, this); 469 _liveness->compute_liveness(); 470 } 471 472 return _liveness->get_bci_block_start(); 473 } 474 #endif // COMPILER1 475 476 477 // ------------------------------------------------------------------ 478 // ciMethod::call_profile_at_bci 479 // 480 // Get the ciCallProfile for the invocation of this method. 481 // Also reports receiver types for non-call type checks (if TypeProfileCasts). 482 ciCallProfile ciMethod::call_profile_at_bci(int bci) { 483 ResourceMark rm; 484 ciCallProfile result; 485 if (method_data() != NULL && method_data()->is_mature()) { 486 ciProfileData* data = method_data()->bci_to_data(bci); 487 if (data != NULL && data->is_CounterData()) { 488 // Every profiled call site has a counter. 489 int count = data->as_CounterData()->count(); 490 491 if (!data->is_ReceiverTypeData()) { 492 result._receiver_count[0] = 0; // that's a definite zero 493 } else { // ReceiverTypeData is a subclass of CounterData 494 ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData(); 495 // In addition, virtual call sites have receiver type information 496 int receivers_count_total = 0; 497 int morphism = 0; 498 // Precompute morphism for the possible fixup 499 for (uint i = 0; i < call->row_limit(); i++) { 500 ciKlass* receiver = call->receiver(i); 501 if (receiver == NULL) continue; 502 morphism++; 503 } 504 int epsilon = 0; 505 if (TieredCompilation && ProfileInterpreter) { 506 // Interpreter and C1 treat final and special invokes differently. 507 // C1 will record a type, whereas the interpreter will just 508 // increment the count. Detect this case. 509 if (morphism == 1 && count > 0) { 510 epsilon = count; 511 count = 0; 512 } 513 } 514 for (uint i = 0; i < call->row_limit(); i++) { 515 ciKlass* receiver = call->receiver(i); 516 if (receiver == NULL) continue; 517 int rcount = call->receiver_count(i) + epsilon; 518 if (rcount == 0) rcount = 1; // Should be valid value 519 receivers_count_total += rcount; 520 // Add the receiver to result data. 521 result.add_receiver(receiver, rcount); 522 // If we extend profiling to record methods, 523 // we will set result._method also. 524 } 525 // Determine call site's morphism. 526 // The call site count is 0 with known morphism (onlt 1 or 2 receivers) 527 // or < 0 in the case of a type check failured for checkcast, aastore, instanceof. 528 // The call site count is > 0 in the case of a polymorphic virtual call. 529 if (morphism > 0 && morphism == result._limit) { 530 // The morphism <= MorphismLimit. 531 if ((morphism < ciCallProfile::MorphismLimit) || 532 (morphism == ciCallProfile::MorphismLimit && count == 0)) { 533 #ifdef ASSERT 534 if (count > 0) { 535 this->print_short_name(tty); 536 tty->print_cr(" @ bci:%d", bci); 537 this->print_codes(); 538 assert(false, "this call site should not be polymorphic"); 539 } 540 #endif 541 result._morphism = morphism; 542 } 543 } 544 // Make the count consistent if this is a call profile. If count is 545 // zero or less, presume that this is a typecheck profile and 546 // do nothing. Otherwise, increase count to be the sum of all 547 // receiver's counts. 548 if (count >= 0) { 549 count += receivers_count_total; 550 } 551 } 552 result._count = count; 553 } 554 } 555 return result; 556 } 557 558 // ------------------------------------------------------------------ 559 // Add new receiver and sort data by receiver's profile count. 560 void ciCallProfile::add_receiver(ciKlass* receiver, int receiver_count) { 561 // Add new receiver and sort data by receiver's counts when we have space 562 // for it otherwise replace the less called receiver (less called receiver 563 // is placed to the last array element which is not used). 564 // First array's element contains most called receiver. 565 int i = _limit; 566 for (; i > 0 && receiver_count > _receiver_count[i-1]; i--) { 567 _receiver[i] = _receiver[i-1]; 568 _receiver_count[i] = _receiver_count[i-1]; 569 } 570 _receiver[i] = receiver; 571 _receiver_count[i] = receiver_count; 572 if (_limit < MorphismLimit) _limit++; 573 } 574 575 576 void ciMethod::assert_virtual_call_type_ok(int bci) { 577 assert(java_code_at_bci(bci) == Bytecodes::_invokevirtual || 578 java_code_at_bci(bci) == Bytecodes::_invokeinterface, "unexpected bytecode %s", Bytecodes::name(java_code_at_bci(bci))); 579 } 580 581 void ciMethod::assert_call_type_ok(int bci) { 582 assert(java_code_at_bci(bci) == Bytecodes::_invokestatic || 583 java_code_at_bci(bci) == Bytecodes::_invokespecial || 584 java_code_at_bci(bci) == Bytecodes::_invokedynamic, "unexpected bytecode %s", Bytecodes::name(java_code_at_bci(bci))); 585 } 586 587 /** 588 * Check whether profiling provides a type for the argument i to the 589 * call at bci bci 590 * 591 * @param [in]bci bci of the call 592 * @param [in]i argument number 593 * @param [out]type profiled type of argument, NULL if none 594 * @param [out]maybe_null true if null was seen for argument 595 * @return true if profiling exists 596 * 597 */ 598 bool ciMethod::argument_profiled_type(int bci, int i, ciKlass*& type, bool& maybe_null) { 599 if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) { 600 ciProfileData* data = method_data()->bci_to_data(bci); 601 if (data != NULL) { 602 if (data->is_VirtualCallTypeData()) { 603 assert_virtual_call_type_ok(bci); 604 ciVirtualCallTypeData* call = (ciVirtualCallTypeData*)data->as_VirtualCallTypeData(); 605 if (i >= call->number_of_arguments()) { 606 return false; 607 } 608 type = call->valid_argument_type(i); 609 maybe_null = call->argument_maybe_null(i); 610 return true; 611 } else if (data->is_CallTypeData()) { 612 assert_call_type_ok(bci); 613 ciCallTypeData* call = (ciCallTypeData*)data->as_CallTypeData(); 614 if (i >= call->number_of_arguments()) { 615 return false; 616 } 617 type = call->valid_argument_type(i); 618 maybe_null = call->argument_maybe_null(i); 619 return true; 620 } 621 } 622 } 623 return false; 624 } 625 626 /** 627 * Check whether profiling provides a type for the return value from 628 * the call at bci bci 629 * 630 * @param [in]bci bci of the call 631 * @param [out]type profiled type of argument, NULL if none 632 * @param [out]maybe_null true if null was seen for argument 633 * @return true if profiling exists 634 * 635 */ 636 bool ciMethod::return_profiled_type(int bci, ciKlass*& type, bool& maybe_null) { 637 if (MethodData::profile_return() && method_data() != NULL && method_data()->is_mature()) { 638 ciProfileData* data = method_data()->bci_to_data(bci); 639 if (data != NULL) { 640 if (data->is_VirtualCallTypeData()) { 641 assert_virtual_call_type_ok(bci); 642 ciVirtualCallTypeData* call = (ciVirtualCallTypeData*)data->as_VirtualCallTypeData(); 643 type = call->valid_return_type(); 644 maybe_null = call->return_maybe_null(); 645 return true; 646 } else if (data->is_CallTypeData()) { 647 assert_call_type_ok(bci); 648 ciCallTypeData* call = (ciCallTypeData*)data->as_CallTypeData(); 649 type = call->valid_return_type(); 650 maybe_null = call->return_maybe_null(); 651 return true; 652 } 653 } 654 } 655 return false; 656 } 657 658 /** 659 * Check whether profiling provides a type for the parameter i 660 * 661 * @param [in]i parameter number 662 * @param [out]type profiled type of parameter, NULL if none 663 * @param [out]maybe_null true if null was seen for parameter 664 * @return true if profiling exists 665 * 666 */ 667 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, bool& maybe_null) { 668 if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) { 669 ciParametersTypeData* parameters = method_data()->parameters_type_data(); 670 if (parameters != NULL && i < parameters->number_of_parameters()) { 671 type = parameters->valid_parameter_type(i); 672 maybe_null = parameters->parameter_maybe_null(i); 673 return true; 674 } 675 } 676 return false; 677 } 678 679 680 // ------------------------------------------------------------------ 681 // ciMethod::find_monomorphic_target 682 // 683 // Given a certain calling environment, find the monomorphic target 684 // for the call. Return NULL if the call is not monomorphic in 685 // its calling environment, or if there are only abstract methods. 686 // The returned method is never abstract. 687 // Note: If caller uses a non-null result, it must inform dependencies 688 // via assert_unique_concrete_method or assert_leaf_type. 689 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller, 690 ciInstanceKlass* callee_holder, 691 ciInstanceKlass* actual_recv, 692 bool check_access) { 693 check_is_loaded(); 694 695 if (actual_recv->is_interface()) { 696 // %%% We cannot trust interface types, yet. See bug 6312651. 697 return NULL; 698 } 699 700 ciMethod* root_m = resolve_invoke(caller, actual_recv, check_access); 701 if (root_m == NULL) { 702 // Something went wrong looking up the actual receiver method. 703 return NULL; 704 } 705 assert(!root_m->is_abstract(), "resolve_invoke promise"); 706 707 // Make certain quick checks even if UseCHA is false. 708 709 // Is it private or final? 710 if (root_m->can_be_statically_bound()) { 711 return root_m; 712 } 713 714 if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) { 715 // Easy case. There is no other place to put a method, so don't bother 716 // to go through the VM_ENTRY_MARK and all the rest. 717 return root_m; 718 } 719 720 // Array methods (clone, hashCode, etc.) are always statically bound. 721 // If we were to see an array type here, we'd return root_m. 722 // However, this method processes only ciInstanceKlasses. (See 4962591.) 723 // The inline_native_clone intrinsic narrows Object to T[] properly, 724 // so there is no need to do the same job here. 725 726 if (!UseCHA) return NULL; 727 728 VM_ENTRY_MARK; 729 730 // Disable CHA for default methods for now 731 if (root_m->get_Method()->is_default_method()) { 732 return NULL; 733 } 734 735 methodHandle target; 736 { 737 MutexLocker locker(Compile_lock); 738 Klass* context = actual_recv->get_Klass(); 739 target = Dependencies::find_unique_concrete_method(context, 740 root_m->get_Method()); 741 // %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods. 742 } 743 744 #ifndef PRODUCT 745 if (TraceDependencies && target() != NULL && target() != root_m->get_Method()) { 746 tty->print("found a non-root unique target method"); 747 tty->print_cr(" context = %s", InstanceKlass::cast(actual_recv->get_Klass())->external_name()); 748 tty->print(" method = "); 749 target->print_short_name(tty); 750 tty->cr(); 751 } 752 #endif //PRODUCT 753 754 if (target() == NULL) { 755 return NULL; 756 } 757 if (target() == root_m->get_Method()) { 758 return root_m; 759 } 760 if (!root_m->is_public() && 761 !root_m->is_protected()) { 762 // If we are going to reason about inheritance, it's easiest 763 // if the method in question is public, protected, or private. 764 // If the answer is not root_m, it is conservatively correct 765 // to return NULL, even if the CHA encountered irrelevant 766 // methods in other packages. 767 // %%% TO DO: Work out logic for package-private methods 768 // with the same name but different vtable indexes. 769 return NULL; 770 } 771 return CURRENT_THREAD_ENV->get_method(target()); 772 } 773 774 // ------------------------------------------------------------------ 775 // ciMethod::resolve_invoke 776 // 777 // Given a known receiver klass, find the target for the call. 778 // Return NULL if the call has no target or the target is abstract. 779 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access) { 780 check_is_loaded(); 781 VM_ENTRY_MARK; 782 783 KlassHandle caller_klass (THREAD, caller->get_Klass()); 784 KlassHandle h_recv (THREAD, exact_receiver->get_Klass()); 785 KlassHandle h_resolved (THREAD, holder()->get_Klass()); 786 Symbol* h_name = name()->get_symbol(); 787 Symbol* h_signature = signature()->get_symbol(); 788 789 LinkInfo link_info(h_resolved, h_name, h_signature, caller_klass, check_access); 790 methodHandle m; 791 // Only do exact lookup if receiver klass has been linked. Otherwise, 792 // the vtable has not been setup, and the LinkResolver will fail. 793 if (h_recv->oop_is_array() 794 || 795 InstanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) { 796 if (holder()->is_interface()) { 797 m = LinkResolver::resolve_interface_call_or_null(h_recv, link_info); 798 } else { 799 m = LinkResolver::resolve_virtual_call_or_null(h_recv, link_info); 800 } 801 } 802 803 if (m.is_null()) { 804 // Return NULL only if there was a problem with lookup (uninitialized class, etc.) 805 return NULL; 806 } 807 808 ciMethod* result = this; 809 if (m() != get_Method()) { 810 result = CURRENT_THREAD_ENV->get_method(m()); 811 } 812 813 // Don't return abstract methods because they aren't 814 // optimizable or interesting. 815 if (result->is_abstract()) { 816 return NULL; 817 } else { 818 return result; 819 } 820 } 821 822 // ------------------------------------------------------------------ 823 // ciMethod::resolve_vtable_index 824 // 825 // Given a known receiver klass, find the vtable index for the call. 826 // Return Method::invalid_vtable_index if the vtable_index is unknown. 827 int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) { 828 check_is_loaded(); 829 830 int vtable_index = Method::invalid_vtable_index; 831 // Only do lookup if receiver klass has been linked. Otherwise, 832 // the vtable has not been setup, and the LinkResolver will fail. 833 if (!receiver->is_interface() 834 && (!receiver->is_instance_klass() || 835 receiver->as_instance_klass()->is_linked())) { 836 VM_ENTRY_MARK; 837 838 KlassHandle caller_klass (THREAD, caller->get_Klass()); 839 KlassHandle h_recv (THREAD, receiver->get_Klass()); 840 Symbol* h_name = name()->get_symbol(); 841 Symbol* h_signature = signature()->get_symbol(); 842 843 LinkInfo link_info(h_recv, h_name, h_signature, caller_klass); 844 vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, link_info); 845 if (vtable_index == Method::nonvirtual_vtable_index) { 846 // A statically bound method. Return "no such index". 847 vtable_index = Method::invalid_vtable_index; 848 } 849 } 850 851 return vtable_index; 852 } 853 854 // ------------------------------------------------------------------ 855 // ciMethod::interpreter_call_site_count 856 int ciMethod::interpreter_call_site_count(int bci) { 857 if (method_data() != NULL) { 858 ResourceMark rm; 859 ciProfileData* data = method_data()->bci_to_data(bci); 860 if (data != NULL && data->is_CounterData()) { 861 return scale_count(data->as_CounterData()->count()); 862 } 863 } 864 return -1; // unknown 865 } 866 867 // ------------------------------------------------------------------ 868 // ciMethod::get_field_at_bci 869 ciField* ciMethod::get_field_at_bci(int bci, bool &will_link) { 870 ciBytecodeStream iter(this); 871 iter.reset_to_bci(bci); 872 iter.next(); 873 return iter.get_field(will_link); 874 } 875 876 // ------------------------------------------------------------------ 877 // ciMethod::get_method_at_bci 878 ciMethod* ciMethod::get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature) { 879 ciBytecodeStream iter(this); 880 iter.reset_to_bci(bci); 881 iter.next(); 882 return iter.get_method(will_link, declared_signature); 883 } 884 885 // ------------------------------------------------------------------ 886 // Adjust a CounterData count to be commensurate with 887 // interpreter_invocation_count. If the MDO exists for 888 // only 25% of the time the method exists, then the 889 // counts in the MDO should be scaled by 4X, so that 890 // they can be usefully and stably compared against the 891 // invocation counts in methods. 892 int ciMethod::scale_count(int count, float prof_factor) { 893 if (count > 0 && method_data() != NULL) { 894 int counter_life; 895 int method_life = interpreter_invocation_count(); 896 if (TieredCompilation) { 897 // In tiered the MDO's life is measured directly, so just use the snapshotted counters 898 counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count()); 899 } else { 900 int current_mileage = method_data()->current_mileage(); 901 int creation_mileage = method_data()->creation_mileage(); 902 counter_life = current_mileage - creation_mileage; 903 } 904 905 // counter_life due to backedge_counter could be > method_life 906 if (counter_life > method_life) 907 counter_life = method_life; 908 if (0 < counter_life && counter_life <= method_life) { 909 count = (int)((double)count * prof_factor * method_life / counter_life + 0.5); 910 count = (count > 0) ? count : 1; 911 } 912 } 913 return count; 914 } 915 916 917 // ------------------------------------------------------------------ 918 // ciMethod::is_special_get_caller_class_method 919 // 920 bool ciMethod::is_ignored_by_security_stack_walk() const { 921 check_is_loaded(); 922 VM_ENTRY_MARK; 923 return get_Method()->is_ignored_by_security_stack_walk(); 924 } 925 926 927 // ------------------------------------------------------------------ 928 // invokedynamic support 929 930 // ------------------------------------------------------------------ 931 // ciMethod::is_method_handle_intrinsic 932 // 933 // Return true if the method is an instance of the JVM-generated 934 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc. 935 bool ciMethod::is_method_handle_intrinsic() const { 936 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded 937 return (MethodHandles::is_signature_polymorphic(iid) && 938 MethodHandles::is_signature_polymorphic_intrinsic(iid)); 939 } 940 941 // ------------------------------------------------------------------ 942 // ciMethod::is_compiled_lambda_form 943 // 944 // Return true if the method is a generated MethodHandle adapter. 945 // These are built by Java code. 946 bool ciMethod::is_compiled_lambda_form() const { 947 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded 948 return iid == vmIntrinsics::_compiledLambdaForm; 949 } 950 951 // ------------------------------------------------------------------ 952 // ciMethod::has_member_arg 953 // 954 // Return true if the method is a linker intrinsic like _linkToVirtual. 955 // These are built by the JVM. 956 bool ciMethod::has_member_arg() const { 957 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded 958 return (MethodHandles::is_signature_polymorphic(iid) && 959 MethodHandles::has_member_arg(iid)); 960 } 961 962 // ------------------------------------------------------------------ 963 // ciMethod::ensure_method_data 964 // 965 // Generate new MethodData* objects at compile time. 966 // Return true if allocation was successful or no MDO is required. 967 bool ciMethod::ensure_method_data(methodHandle h_m) { 968 EXCEPTION_CONTEXT; 969 if (is_native() || is_abstract() || h_m()->is_accessor()) { 970 return true; 971 } 972 if (h_m()->method_data() == NULL) { 973 Method::build_interpreter_method_data(h_m, THREAD); 974 if (HAS_PENDING_EXCEPTION) { 975 CLEAR_PENDING_EXCEPTION; 976 } 977 } 978 if (h_m()->method_data() != NULL) { 979 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data()); 980 _method_data->load_data(); 981 return true; 982 } else { 983 _method_data = CURRENT_ENV->get_empty_methodData(); 984 return false; 985 } 986 } 987 988 // public, retroactive version 989 bool ciMethod::ensure_method_data() { 990 bool result = true; 991 if (_method_data == NULL || _method_data->is_empty()) { 992 GUARDED_VM_ENTRY({ 993 result = ensure_method_data(get_Method()); 994 }); 995 } 996 return result; 997 } 998 999 1000 // ------------------------------------------------------------------ 1001 // ciMethod::method_data 1002 // 1003 ciMethodData* ciMethod::method_data() { 1004 if (_method_data != NULL) { 1005 return _method_data; 1006 } 1007 VM_ENTRY_MARK; 1008 ciEnv* env = CURRENT_ENV; 1009 Thread* my_thread = JavaThread::current(); 1010 methodHandle h_m(my_thread, get_Method()); 1011 1012 if (h_m()->method_data() != NULL) { 1013 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data()); 1014 _method_data->load_data(); 1015 } else { 1016 _method_data = CURRENT_ENV->get_empty_methodData(); 1017 } 1018 return _method_data; 1019 1020 } 1021 1022 // ------------------------------------------------------------------ 1023 // ciMethod::method_data_or_null 1024 // Returns a pointer to ciMethodData if MDO exists on the VM side, 1025 // NULL otherwise. 1026 ciMethodData* ciMethod::method_data_or_null() { 1027 ciMethodData *md = method_data(); 1028 if (md->is_empty()) { 1029 return NULL; 1030 } 1031 return md; 1032 } 1033 1034 // ------------------------------------------------------------------ 1035 // ciMethod::ensure_method_counters 1036 // 1037 MethodCounters* ciMethod::ensure_method_counters() { 1038 check_is_loaded(); 1039 VM_ENTRY_MARK; 1040 methodHandle mh(THREAD, get_Method()); 1041 MethodCounters* method_counters = mh->get_method_counters(CHECK_NULL); 1042 return method_counters; 1043 } 1044 1045 // ------------------------------------------------------------------ 1046 // ciMethod::has_option 1047 // 1048 bool ciMethod::has_option(const char* option) { 1049 check_is_loaded(); 1050 VM_ENTRY_MARK; 1051 methodHandle mh(THREAD, get_Method()); 1052 return CompilerOracle::has_option_string(mh, option); 1053 } 1054 1055 // ------------------------------------------------------------------ 1056 // ciMethod::has_option_value 1057 // 1058 bool ciMethod::has_option_value(const char* option, double& value) { 1059 check_is_loaded(); 1060 VM_ENTRY_MARK; 1061 methodHandle mh(THREAD, get_Method()); 1062 return CompilerOracle::has_option_value(mh, option, value); 1063 } 1064 // ------------------------------------------------------------------ 1065 // ciMethod::can_be_compiled 1066 // 1067 // Have previous compilations of this method succeeded? 1068 bool ciMethod::can_be_compiled() { 1069 check_is_loaded(); 1070 ciEnv* env = CURRENT_ENV; 1071 if (is_c1_compile(env->comp_level())) { 1072 return _is_c1_compilable; 1073 } 1074 return _is_c2_compilable; 1075 } 1076 1077 // ------------------------------------------------------------------ 1078 // ciMethod::set_not_compilable 1079 // 1080 // Tell the VM that this method cannot be compiled at all. 1081 void ciMethod::set_not_compilable(const char* reason) { 1082 check_is_loaded(); 1083 VM_ENTRY_MARK; 1084 ciEnv* env = CURRENT_ENV; 1085 if (is_c1_compile(env->comp_level())) { 1086 _is_c1_compilable = false; 1087 } else { 1088 _is_c2_compilable = false; 1089 } 1090 get_Method()->set_not_compilable(env->comp_level(), true, reason); 1091 } 1092 1093 // ------------------------------------------------------------------ 1094 // ciMethod::can_be_osr_compiled 1095 // 1096 // Have previous compilations of this method succeeded? 1097 // 1098 // Implementation note: the VM does not currently keep track 1099 // of failed OSR compilations per bci. The entry_bci parameter 1100 // is currently unused. 1101 bool ciMethod::can_be_osr_compiled(int entry_bci) { 1102 check_is_loaded(); 1103 VM_ENTRY_MARK; 1104 ciEnv* env = CURRENT_ENV; 1105 return !get_Method()->is_not_osr_compilable(env->comp_level()); 1106 } 1107 1108 // ------------------------------------------------------------------ 1109 // ciMethod::has_compiled_code 1110 bool ciMethod::has_compiled_code() { 1111 return instructions_size() > 0; 1112 } 1113 1114 int ciMethod::comp_level() { 1115 check_is_loaded(); 1116 VM_ENTRY_MARK; 1117 nmethod* nm = get_Method()->code(); 1118 if (nm != NULL) return nm->comp_level(); 1119 return 0; 1120 } 1121 1122 int ciMethod::highest_osr_comp_level() { 1123 check_is_loaded(); 1124 VM_ENTRY_MARK; 1125 return get_Method()->highest_osr_comp_level(); 1126 } 1127 1128 // ------------------------------------------------------------------ 1129 // ciMethod::code_size_for_inlining 1130 // 1131 // Code size for inlining decisions. This method returns a code 1132 // size of 1 for methods which has the ForceInline annotation. 1133 int ciMethod::code_size_for_inlining() { 1134 check_is_loaded(); 1135 if (get_Method()->force_inline()) { 1136 return 1; 1137 } 1138 return code_size(); 1139 } 1140 1141 // ------------------------------------------------------------------ 1142 // ciMethod::instructions_size 1143 // 1144 // This is a rough metric for "fat" methods, compared before inlining 1145 // with InlineSmallCode. The CodeBlob::code_size accessor includes 1146 // junk like exception handler, stubs, and constant table, which are 1147 // not highly relevant to an inlined method. So we use the more 1148 // specific accessor nmethod::insts_size. 1149 int ciMethod::instructions_size() { 1150 if (_instructions_size == -1) { 1151 GUARDED_VM_ENTRY( 1152 nmethod* code = get_Method()->code(); 1153 if (code != NULL && (code->comp_level() == CompLevel_full_optimization)) { 1154 _instructions_size = code->insts_end() - code->verified_entry_point(); 1155 } else { 1156 _instructions_size = 0; 1157 } 1158 ); 1159 } 1160 return _instructions_size; 1161 } 1162 1163 // ------------------------------------------------------------------ 1164 // ciMethod::log_nmethod_identity 1165 void ciMethod::log_nmethod_identity(xmlStream* log) { 1166 GUARDED_VM_ENTRY( 1167 nmethod* code = get_Method()->code(); 1168 if (code != NULL) { 1169 code->log_identity(log); 1170 } 1171 ) 1172 } 1173 1174 // ------------------------------------------------------------------ 1175 // ciMethod::is_not_reached 1176 bool ciMethod::is_not_reached(int bci) { 1177 check_is_loaded(); 1178 VM_ENTRY_MARK; 1179 return Interpreter::is_not_reached( 1180 methodHandle(THREAD, get_Method()), bci); 1181 } 1182 1183 // ------------------------------------------------------------------ 1184 // ciMethod::was_never_executed 1185 bool ciMethod::was_executed_more_than(int times) { 1186 VM_ENTRY_MARK; 1187 return get_Method()->was_executed_more_than(times); 1188 } 1189 1190 // ------------------------------------------------------------------ 1191 // ciMethod::has_unloaded_classes_in_signature 1192 bool ciMethod::has_unloaded_classes_in_signature() { 1193 VM_ENTRY_MARK; 1194 { 1195 EXCEPTION_MARK; 1196 methodHandle m(THREAD, get_Method()); 1197 bool has_unloaded = Method::has_unloaded_classes_in_signature(m, (JavaThread *)THREAD); 1198 if( HAS_PENDING_EXCEPTION ) { 1199 CLEAR_PENDING_EXCEPTION; 1200 return true; // Declare that we may have unloaded classes 1201 } 1202 return has_unloaded; 1203 } 1204 } 1205 1206 // ------------------------------------------------------------------ 1207 // ciMethod::is_klass_loaded 1208 bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { 1209 VM_ENTRY_MARK; 1210 return get_Method()->is_klass_loaded(refinfo_index, must_be_resolved); 1211 } 1212 1213 // ------------------------------------------------------------------ 1214 // ciMethod::check_call 1215 bool ciMethod::check_call(int refinfo_index, bool is_static) const { 1216 // This method is used only in C2 from InlineTree::ok_to_inline, 1217 // and is only used under -Xcomp or -XX:CompileTheWorld. 1218 // It appears to fail when applied to an invokeinterface call site. 1219 // FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points. 1220 VM_ENTRY_MARK; 1221 { 1222 EXCEPTION_MARK; 1223 HandleMark hm(THREAD); 1224 constantPoolHandle pool (THREAD, get_Method()->constants()); 1225 Bytecodes::Code code = (is_static ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual); 1226 methodHandle spec_method = LinkResolver::resolve_method_statically(code, pool, refinfo_index, THREAD); 1227 if (HAS_PENDING_EXCEPTION) { 1228 CLEAR_PENDING_EXCEPTION; 1229 return false; 1230 } else { 1231 return (spec_method->is_static() == is_static); 1232 } 1233 } 1234 return false; 1235 } 1236 1237 // ------------------------------------------------------------------ 1238 // ciMethod::profile_aging 1239 // 1240 // Should the method be compiled with an age counter? 1241 bool ciMethod::profile_aging() const { 1242 return UseCodeAging && (!MethodCounters::is_nmethod_hot(nmethod_age()) && 1243 !MethodCounters::is_nmethod_age_unset(nmethod_age())); 1244 } 1245 // ------------------------------------------------------------------ 1246 // ciMethod::print_codes 1247 // 1248 // Print the bytecodes for this method. 1249 void ciMethod::print_codes_on(outputStream* st) { 1250 check_is_loaded(); 1251 GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);) 1252 } 1253 1254 1255 #define FETCH_FLAG_FROM_VM(flag_accessor) { \ 1256 check_is_loaded(); \ 1257 VM_ENTRY_MARK; \ 1258 return get_Method()->flag_accessor(); \ 1259 } 1260 1261 bool ciMethod::is_empty_method() const { FETCH_FLAG_FROM_VM(is_empty_method); } 1262 bool ciMethod::is_vanilla_constructor() const { FETCH_FLAG_FROM_VM(is_vanilla_constructor); } 1263 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); } 1264 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); } 1265 bool ciMethod::is_getter () const { FETCH_FLAG_FROM_VM(is_getter); } 1266 bool ciMethod::is_setter () const { FETCH_FLAG_FROM_VM(is_setter); } 1267 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); } 1268 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); } 1269 1270 bool ciMethod::is_boxing_method() const { 1271 if (holder()->is_box_klass()) { 1272 switch (intrinsic_id()) { 1273 case vmIntrinsics::_Boolean_valueOf: 1274 case vmIntrinsics::_Byte_valueOf: 1275 case vmIntrinsics::_Character_valueOf: 1276 case vmIntrinsics::_Short_valueOf: 1277 case vmIntrinsics::_Integer_valueOf: 1278 case vmIntrinsics::_Long_valueOf: 1279 case vmIntrinsics::_Float_valueOf: 1280 case vmIntrinsics::_Double_valueOf: 1281 return true; 1282 default: 1283 return false; 1284 } 1285 } 1286 return false; 1287 } 1288 1289 bool ciMethod::is_unboxing_method() const { 1290 if (holder()->is_box_klass()) { 1291 switch (intrinsic_id()) { 1292 case vmIntrinsics::_booleanValue: 1293 case vmIntrinsics::_byteValue: 1294 case vmIntrinsics::_charValue: 1295 case vmIntrinsics::_shortValue: 1296 case vmIntrinsics::_intValue: 1297 case vmIntrinsics::_longValue: 1298 case vmIntrinsics::_floatValue: 1299 case vmIntrinsics::_doubleValue: 1300 return true; 1301 default: 1302 return false; 1303 } 1304 } 1305 return false; 1306 } 1307 1308 BCEscapeAnalyzer *ciMethod::get_bcea() { 1309 #ifdef COMPILER2 1310 if (_bcea == NULL) { 1311 _bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL); 1312 } 1313 return _bcea; 1314 #else // COMPILER2 1315 ShouldNotReachHere(); 1316 return NULL; 1317 #endif // COMPILER2 1318 } 1319 1320 ciMethodBlocks *ciMethod::get_method_blocks() { 1321 Arena *arena = CURRENT_ENV->arena(); 1322 if (_method_blocks == NULL) { 1323 _method_blocks = new (arena) ciMethodBlocks(arena, this); 1324 } 1325 return _method_blocks; 1326 } 1327 1328 #undef FETCH_FLAG_FROM_VM 1329 1330 void ciMethod::dump_name_as_ascii(outputStream* st) { 1331 Method* method = get_Method(); 1332 st->print("%s %s %s", 1333 method->klass_name()->as_quoted_ascii(), 1334 method->name()->as_quoted_ascii(), 1335 method->signature()->as_quoted_ascii()); 1336 } 1337 1338 void ciMethod::dump_replay_data(outputStream* st) { 1339 ResourceMark rm; 1340 Method* method = get_Method(); 1341 MethodCounters* mcs = method->method_counters(); 1342 st->print("ciMethod "); 1343 dump_name_as_ascii(st); 1344 st->print_cr(" %d %d %d %d %d", 1345 mcs == NULL ? 0 : mcs->invocation_counter()->raw_counter(), 1346 mcs == NULL ? 0 : mcs->backedge_counter()->raw_counter(), 1347 interpreter_invocation_count(), 1348 interpreter_throwout_count(), 1349 _instructions_size); 1350 } 1351 1352 // ------------------------------------------------------------------ 1353 // ciMethod::print_codes 1354 // 1355 // Print a range of the bytecodes for this method. 1356 void ciMethod::print_codes_on(int from, int to, outputStream* st) { 1357 check_is_loaded(); 1358 GUARDED_VM_ENTRY(get_Method()->print_codes_on(from, to, st);) 1359 } 1360 1361 // ------------------------------------------------------------------ 1362 // ciMethod::print_name 1363 // 1364 // Print the name of this method, including signature and some flags. 1365 void ciMethod::print_name(outputStream* st) { 1366 check_is_loaded(); 1367 GUARDED_VM_ENTRY(get_Method()->print_name(st);) 1368 } 1369 1370 // ------------------------------------------------------------------ 1371 // ciMethod::print_short_name 1372 // 1373 // Print the name of this method, without signature. 1374 void ciMethod::print_short_name(outputStream* st) { 1375 if (is_loaded()) { 1376 GUARDED_VM_ENTRY(get_Method()->print_short_name(st);); 1377 } else { 1378 // Fall back if method is not loaded. 1379 holder()->print_name_on(st); 1380 st->print("::"); 1381 name()->print_symbol_on(st); 1382 if (WizardMode) 1383 signature()->as_symbol()->print_symbol_on(st); 1384 } 1385 } 1386 1387 // ------------------------------------------------------------------ 1388 // ciMethod::print_impl 1389 // 1390 // Implementation of the print method. 1391 void ciMethod::print_impl(outputStream* st) { 1392 ciMetadata::print_impl(st); 1393 st->print(" name="); 1394 name()->print_symbol_on(st); 1395 st->print(" holder="); 1396 holder()->print_name_on(st); 1397 st->print(" signature="); 1398 signature()->as_symbol()->print_symbol_on(st); 1399 if (is_loaded()) { 1400 st->print(" loaded=true"); 1401 st->print(" arg_size=%d", arg_size()); 1402 st->print(" flags="); 1403 flags().print_member_flags(st); 1404 } else { 1405 st->print(" loaded=false"); 1406 } 1407 } 1408 1409 #if INCLUDE_TRACE 1410 TraceStructCiMethod ciMethod::to_trace_struct() const { 1411 TraceStructCiMethod result; 1412 result.set_class(holder()->name()->as_utf8()); 1413 result.set_name(name()->as_utf8()); 1414 result.set_signature(signature()->as_symbol()->as_utf8()); 1415 return result; 1416 } 1417 #endif