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