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