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