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