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