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