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