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