src/share/vm/ci/ciMethod.cpp

Wed, 25 Aug 2010 05:27:54 -0700

author
twisti
date
Wed, 25 Aug 2010 05:27:54 -0700
changeset 2103
3e8fbc61cee8
parent 2047
d2ede61b7a12
child 2138
d5d065957597
permissions
-rw-r--r--

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

mercurial