src/share/vm/ci/ciMethod.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial