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