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