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