src/share/vm/ci/ciMethod.cpp

Tue, 06 Nov 2012 15:09:37 -0500

author
coleenp
date
Tue, 06 Nov 2012 15:09:37 -0500
changeset 4251
18fb7da42534
parent 4037
da91efe96a93
child 4267
bd7a7ce2e264
permissions
-rw-r--r--

8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
Summary: Change types of above methods and field to InstanceKlass and remove unneeded casts from the source files.
Reviewed-by: dholmes, coleenp, zgu
Contributed-by: harold.seigel@oracle.com

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

mercurial