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