src/share/vm/ci/ciMethod.cpp

Thu, 02 Dec 2010 17:21:12 -0800

author
iveresov
date
Thu, 02 Dec 2010 17:21:12 -0800
changeset 2349
5ddfcf4b079e
parent 2314
f95d63e2154a
child 2497
3582bf76420e
permissions
-rw-r--r--

7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
Summary: C1 with profiling doesn't check whether the MDO has been really allocated, which can silently fail if the perm gen is full. The solution is to check if the allocation failed and bailout out of inlining or compilation.
Reviewed-by: kvn, never

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

mercurial