src/share/vm/ci/ciMethod.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 8856
ac27a9c85bea
child 10015
eb7ce841ccec
permissions
-rw-r--r--

Merge

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

mercurial