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