annotate src/share/vm/ci/ciMethod.cpp @ 2069:3582bf76420e

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