annotate src/share/vm/ci/ciMethod.cpp @ 5589:5cc2d82aa82a

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