Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/opto/doCall.cpp
40930 views
1
/*
2
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "ci/ciCallSite.hpp"
27
#include "ci/ciMethodHandle.hpp"
28
#include "ci/ciSymbols.hpp"
29
#include "classfile/vmSymbols.hpp"
30
#include "compiler/compileBroker.hpp"
31
#include "compiler/compileLog.hpp"
32
#include "interpreter/linkResolver.hpp"
33
#include "opto/addnode.hpp"
34
#include "opto/callGenerator.hpp"
35
#include "opto/castnode.hpp"
36
#include "opto/cfgnode.hpp"
37
#include "opto/mulnode.hpp"
38
#include "opto/parse.hpp"
39
#include "opto/rootnode.hpp"
40
#include "opto/runtime.hpp"
41
#include "opto/subnode.hpp"
42
#include "prims/methodHandles.hpp"
43
#include "runtime/sharedRuntime.hpp"
44
45
void trace_type_profile(Compile* C, ciMethod *method, int depth, int bci, ciMethod *prof_method, ciKlass *prof_klass, int site_count, int receiver_count) {
46
if (TraceTypeProfile || C->print_inlining()) {
47
outputStream* out = tty;
48
if (!C->print_inlining()) {
49
if (!PrintOpto && !PrintCompilation) {
50
method->print_short_name();
51
tty->cr();
52
}
53
CompileTask::print_inlining_tty(prof_method, depth, bci);
54
} else {
55
out = C->print_inlining_stream();
56
}
57
CompileTask::print_inline_indent(depth, out);
58
out->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count);
59
stringStream ss;
60
prof_klass->name()->print_symbol_on(&ss);
61
out->print("%s", ss.as_string());
62
out->cr();
63
}
64
}
65
66
CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool call_does_dispatch,
67
JVMState* jvms, bool allow_inline,
68
float prof_factor, ciKlass* speculative_receiver_type,
69
bool allow_intrinsics) {
70
ciMethod* caller = jvms->method();
71
int bci = jvms->bci();
72
Bytecodes::Code bytecode = caller->java_code_at_bci(bci);
73
guarantee(callee != NULL, "failed method resolution");
74
75
// Dtrace currently doesn't work unless all calls are vanilla
76
if (env()->dtrace_method_probes()) {
77
allow_inline = false;
78
}
79
80
// Note: When we get profiling during stage-1 compiles, we want to pull
81
// from more specific profile data which pertains to this inlining.
82
// Right now, ignore the information in jvms->caller(), and do method[bci].
83
ciCallProfile profile = caller->call_profile_at_bci(bci);
84
85
// See how many times this site has been invoked.
86
int site_count = profile.count();
87
int receiver_count = -1;
88
if (call_does_dispatch && UseTypeProfile && profile.has_receiver(0)) {
89
// Receivers in the profile structure are ordered by call counts
90
// so that the most called (major) receiver is profile.receiver(0).
91
receiver_count = profile.receiver_count(0);
92
}
93
94
CompileLog* log = this->log();
95
if (log != NULL) {
96
int rid = (receiver_count >= 0)? log->identify(profile.receiver(0)): -1;
97
int r2id = (rid != -1 && profile.has_receiver(1))? log->identify(profile.receiver(1)):-1;
98
log->begin_elem("call method='%d' count='%d' prof_factor='%f'",
99
log->identify(callee), site_count, prof_factor);
100
if (call_does_dispatch) log->print(" virtual='1'");
101
if (allow_inline) log->print(" inline='1'");
102
if (receiver_count >= 0) {
103
log->print(" receiver='%d' receiver_count='%d'", rid, receiver_count);
104
if (profile.has_receiver(1)) {
105
log->print(" receiver2='%d' receiver2_count='%d'", r2id, profile.receiver_count(1));
106
}
107
}
108
if (callee->is_method_handle_intrinsic()) {
109
log->print(" method_handle_intrinsic='1'");
110
}
111
log->end_elem();
112
}
113
114
// Special case the handling of certain common, profitable library
115
// methods. If these methods are replaced with specialized code,
116
// then we return it as the inlined version of the call.
117
CallGenerator* cg_intrinsic = NULL;
118
if (allow_inline && allow_intrinsics) {
119
CallGenerator* cg = find_intrinsic(callee, call_does_dispatch);
120
if (cg != NULL) {
121
if (cg->is_predicated()) {
122
// Code without intrinsic but, hopefully, inlined.
123
CallGenerator* inline_cg = this->call_generator(callee,
124
vtable_index, call_does_dispatch, jvms, allow_inline, prof_factor, speculative_receiver_type, false);
125
if (inline_cg != NULL) {
126
cg = CallGenerator::for_predicated_intrinsic(cg, inline_cg);
127
}
128
}
129
130
// If intrinsic does the virtual dispatch, we try to use the type profile
131
// first, and hopefully inline it as the regular virtual call below.
132
// We will retry the intrinsic if nothing had claimed it afterwards.
133
if (cg->does_virtual_dispatch()) {
134
cg_intrinsic = cg;
135
cg = NULL;
136
} else if (should_delay_vector_inlining(callee, jvms)) {
137
return CallGenerator::for_late_inline(callee, cg);
138
} else {
139
return cg;
140
}
141
}
142
}
143
144
// Do method handle calls.
145
// NOTE: This must happen before normal inlining logic below since
146
// MethodHandle.invoke* are native methods which obviously don't
147
// have bytecodes and so normal inlining fails.
148
if (callee->is_method_handle_intrinsic()) {
149
CallGenerator* cg = CallGenerator::for_method_handle_call(jvms, caller, callee, allow_inline);
150
return cg;
151
}
152
153
// Attempt to inline...
154
if (allow_inline) {
155
// The profile data is only partly attributable to this caller,
156
// scale back the call site information.
157
float past_uses = jvms->method()->scale_count(site_count, prof_factor);
158
// This is the number of times we expect the call code to be used.
159
float expected_uses = past_uses;
160
161
// Try inlining a bytecoded method:
162
if (!call_does_dispatch) {
163
InlineTree* ilt = InlineTree::find_subtree_from_root(this->ilt(), jvms->caller(), jvms->method());
164
bool should_delay = false;
165
if (ilt->ok_to_inline(callee, jvms, profile, should_delay)) {
166
CallGenerator* cg = CallGenerator::for_inline(callee, expected_uses);
167
if (cg != NULL) {
168
// Delay the inlining of this method to give us the
169
// opportunity to perform some high level optimizations
170
// first.
171
if (should_delay_string_inlining(callee, jvms)) {
172
return CallGenerator::for_string_late_inline(callee, cg);
173
} else if (should_delay_boxing_inlining(callee, jvms)) {
174
return CallGenerator::for_boxing_late_inline(callee, cg);
175
} else if (should_delay_vector_reboxing_inlining(callee, jvms)) {
176
return CallGenerator::for_vector_reboxing_late_inline(callee, cg);
177
} else if ((should_delay || AlwaysIncrementalInline)) {
178
return CallGenerator::for_late_inline(callee, cg);
179
} else {
180
return cg;
181
}
182
}
183
}
184
}
185
186
// Try using the type profile.
187
if (call_does_dispatch && site_count > 0 && UseTypeProfile) {
188
// The major receiver's count >= TypeProfileMajorReceiverPercent of site_count.
189
bool have_major_receiver = profile.has_receiver(0) && (100.*profile.receiver_prob(0) >= (float)TypeProfileMajorReceiverPercent);
190
ciMethod* receiver_method = NULL;
191
192
int morphism = profile.morphism();
193
if (speculative_receiver_type != NULL) {
194
if (!too_many_traps_or_recompiles(caller, bci, Deoptimization::Reason_speculate_class_check)) {
195
// We have a speculative type, we should be able to resolve
196
// the call. We do that before looking at the profiling at
197
// this invoke because it may lead to bimorphic inlining which
198
// a speculative type should help us avoid.
199
receiver_method = callee->resolve_invoke(jvms->method()->holder(),
200
speculative_receiver_type);
201
if (receiver_method == NULL) {
202
speculative_receiver_type = NULL;
203
} else {
204
morphism = 1;
205
}
206
} else {
207
// speculation failed before. Use profiling at the call
208
// (could allow bimorphic inlining for instance).
209
speculative_receiver_type = NULL;
210
}
211
}
212
if (receiver_method == NULL &&
213
(have_major_receiver || morphism == 1 ||
214
(morphism == 2 && UseBimorphicInlining))) {
215
// receiver_method = profile.method();
216
// Profiles do not suggest methods now. Look it up in the major receiver.
217
receiver_method = callee->resolve_invoke(jvms->method()->holder(),
218
profile.receiver(0));
219
}
220
if (receiver_method != NULL) {
221
// The single majority receiver sufficiently outweighs the minority.
222
CallGenerator* hit_cg = this->call_generator(receiver_method,
223
vtable_index, !call_does_dispatch, jvms, allow_inline, prof_factor);
224
if (hit_cg != NULL) {
225
// Look up second receiver.
226
CallGenerator* next_hit_cg = NULL;
227
ciMethod* next_receiver_method = NULL;
228
if (morphism == 2 && UseBimorphicInlining) {
229
next_receiver_method = callee->resolve_invoke(jvms->method()->holder(),
230
profile.receiver(1));
231
if (next_receiver_method != NULL) {
232
next_hit_cg = this->call_generator(next_receiver_method,
233
vtable_index, !call_does_dispatch, jvms,
234
allow_inline, prof_factor);
235
if (next_hit_cg != NULL && !next_hit_cg->is_inline() &&
236
have_major_receiver && UseOnlyInlinedBimorphic) {
237
// Skip if we can't inline second receiver's method
238
next_hit_cg = NULL;
239
}
240
}
241
}
242
CallGenerator* miss_cg;
243
Deoptimization::DeoptReason reason = (morphism == 2
244
? Deoptimization::Reason_bimorphic
245
: Deoptimization::reason_class_check(speculative_receiver_type != NULL));
246
if ((morphism == 1 || (morphism == 2 && next_hit_cg != NULL)) &&
247
!too_many_traps_or_recompiles(caller, bci, reason)
248
) {
249
// Generate uncommon trap for class check failure path
250
// in case of monomorphic or bimorphic virtual call site.
251
miss_cg = CallGenerator::for_uncommon_trap(callee, reason,
252
Deoptimization::Action_maybe_recompile);
253
} else {
254
// Generate virtual call for class check failure path
255
// in case of polymorphic virtual call site.
256
miss_cg = (IncrementalInlineVirtual ? CallGenerator::for_late_inline_virtual(callee, vtable_index, prof_factor)
257
: CallGenerator::for_virtual_call(callee, vtable_index));
258
}
259
if (miss_cg != NULL) {
260
if (next_hit_cg != NULL) {
261
assert(speculative_receiver_type == NULL, "shouldn't end up here if we used speculation");
262
trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1));
263
// We don't need to record dependency on a receiver here and below.
264
// Whenever we inline, the dependency is added by Parse::Parse().
265
miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX);
266
}
267
if (miss_cg != NULL) {
268
ciKlass* k = speculative_receiver_type != NULL ? speculative_receiver_type : profile.receiver(0);
269
trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, k, site_count, receiver_count);
270
float hit_prob = speculative_receiver_type != NULL ? 1.0 : profile.receiver_prob(0);
271
CallGenerator* cg = CallGenerator::for_predicted_call(k, miss_cg, hit_cg, hit_prob);
272
if (cg != NULL) return cg;
273
}
274
}
275
}
276
}
277
}
278
279
// If there is only one implementor of this interface then we
280
// may be able to bind this invoke directly to the implementing
281
// klass but we need both a dependence on the single interface
282
// and on the method we bind to. Additionally since all we know
283
// about the receiver type is that it's supposed to implement the
284
// interface we have to insert a check that it's the class we
285
// expect. Interface types are not checked by the verifier so
286
// they are roughly equivalent to Object.
287
// The number of implementors for declared_interface is less or
288
// equal to the number of implementors for target->holder() so
289
// if number of implementors of target->holder() == 1 then
290
// number of implementors for decl_interface is 0 or 1. If
291
// it's 0 then no class implements decl_interface and there's
292
// no point in inlining.
293
if (call_does_dispatch && bytecode == Bytecodes::_invokeinterface) {
294
ciInstanceKlass* declared_interface =
295
caller->get_declared_method_holder_at_bci(bci)->as_instance_klass();
296
ciInstanceKlass* singleton = declared_interface->unique_implementor();
297
298
if (singleton != NULL) {
299
assert(singleton != declared_interface, "not a unique implementor");
300
301
ciMethod* cha_monomorphic_target =
302
callee->find_monomorphic_target(caller->holder(), declared_interface, singleton);
303
304
if (cha_monomorphic_target != NULL &&
305
cha_monomorphic_target->holder() != env()->Object_klass()) { // subtype check against Object is useless
306
ciKlass* holder = cha_monomorphic_target->holder();
307
308
// Try to inline the method found by CHA. Inlined method is guarded by the type check.
309
CallGenerator* hit_cg = call_generator(cha_monomorphic_target,
310
vtable_index, !call_does_dispatch, jvms, allow_inline, prof_factor);
311
312
// Deoptimize on type check fail. The interpreter will throw ICCE for us.
313
CallGenerator* miss_cg = CallGenerator::for_uncommon_trap(callee,
314
Deoptimization::Reason_class_check, Deoptimization::Action_none);
315
316
CallGenerator* cg = CallGenerator::for_guarded_call(holder, miss_cg, hit_cg);
317
if (hit_cg != NULL && cg != NULL) {
318
dependencies()->assert_unique_concrete_method(declared_interface, cha_monomorphic_target, declared_interface, callee);
319
return cg;
320
}
321
}
322
}
323
} // call_does_dispatch && bytecode == Bytecodes::_invokeinterface
324
325
// Nothing claimed the intrinsic, we go with straight-forward inlining
326
// for already discovered intrinsic.
327
if (allow_intrinsics && cg_intrinsic != NULL) {
328
assert(cg_intrinsic->does_virtual_dispatch(), "sanity");
329
return cg_intrinsic;
330
}
331
} // allow_inline
332
333
// There was no special inlining tactic, or it bailed out.
334
// Use a more generic tactic, like a simple call.
335
if (call_does_dispatch) {
336
const char* msg = "virtual call";
337
if (C->print_inlining()) {
338
print_inlining(callee, jvms->depth() - 1, jvms->bci(), msg);
339
}
340
C->log_inline_failure(msg);
341
if (IncrementalInlineVirtual && allow_inline) {
342
return CallGenerator::for_late_inline_virtual(callee, vtable_index, prof_factor); // attempt to inline through virtual call later
343
} else {
344
return CallGenerator::for_virtual_call(callee, vtable_index);
345
}
346
} else {
347
// Class Hierarchy Analysis or Type Profile reveals a unique target,
348
// or it is a static or special call.
349
return CallGenerator::for_direct_call(callee, should_delay_inlining(callee, jvms));
350
}
351
}
352
353
// Return true for methods that shouldn't be inlined early so that
354
// they are easier to analyze and optimize as intrinsics.
355
bool Compile::should_delay_string_inlining(ciMethod* call_method, JVMState* jvms) {
356
if (has_stringbuilder()) {
357
358
if ((call_method->holder() == C->env()->StringBuilder_klass() ||
359
call_method->holder() == C->env()->StringBuffer_klass()) &&
360
(jvms->method()->holder() == C->env()->StringBuilder_klass() ||
361
jvms->method()->holder() == C->env()->StringBuffer_klass())) {
362
// Delay SB calls only when called from non-SB code
363
return false;
364
}
365
366
switch (call_method->intrinsic_id()) {
367
case vmIntrinsics::_StringBuilder_void:
368
case vmIntrinsics::_StringBuilder_int:
369
case vmIntrinsics::_StringBuilder_String:
370
case vmIntrinsics::_StringBuilder_append_char:
371
case vmIntrinsics::_StringBuilder_append_int:
372
case vmIntrinsics::_StringBuilder_append_String:
373
case vmIntrinsics::_StringBuilder_toString:
374
case vmIntrinsics::_StringBuffer_void:
375
case vmIntrinsics::_StringBuffer_int:
376
case vmIntrinsics::_StringBuffer_String:
377
case vmIntrinsics::_StringBuffer_append_char:
378
case vmIntrinsics::_StringBuffer_append_int:
379
case vmIntrinsics::_StringBuffer_append_String:
380
case vmIntrinsics::_StringBuffer_toString:
381
case vmIntrinsics::_Integer_toString:
382
return true;
383
384
case vmIntrinsics::_String_String:
385
{
386
Node* receiver = jvms->map()->in(jvms->argoff() + 1);
387
if (receiver->is_Proj() && receiver->in(0)->is_CallStaticJava()) {
388
CallStaticJavaNode* csj = receiver->in(0)->as_CallStaticJava();
389
ciMethod* m = csj->method();
390
if (m != NULL &&
391
(m->intrinsic_id() == vmIntrinsics::_StringBuffer_toString ||
392
m->intrinsic_id() == vmIntrinsics::_StringBuilder_toString))
393
// Delay String.<init>(new SB())
394
return true;
395
}
396
return false;
397
}
398
399
default:
400
return false;
401
}
402
}
403
return false;
404
}
405
406
bool Compile::should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms) {
407
if (eliminate_boxing() && call_method->is_boxing_method()) {
408
set_has_boxed_value(true);
409
return aggressive_unboxing();
410
}
411
return false;
412
}
413
414
bool Compile::should_delay_vector_inlining(ciMethod* call_method, JVMState* jvms) {
415
return EnableVectorSupport && call_method->is_vector_method();
416
}
417
418
bool Compile::should_delay_vector_reboxing_inlining(ciMethod* call_method, JVMState* jvms) {
419
return EnableVectorSupport && (call_method->intrinsic_id() == vmIntrinsics::_VectorRebox);
420
}
421
422
// uncommon-trap call-sites where callee is unloaded, uninitialized or will not link
423
bool Parse::can_not_compile_call_site(ciMethod *dest_method, ciInstanceKlass* klass) {
424
// Additional inputs to consider...
425
// bc = bc()
426
// caller = method()
427
// iter().get_method_holder_index()
428
assert( dest_method->is_loaded(), "ciTypeFlow should not let us get here" );
429
// Interface classes can be loaded & linked and never get around to
430
// being initialized. Uncommon-trap for not-initialized static or
431
// v-calls. Let interface calls happen.
432
ciInstanceKlass* holder_klass = dest_method->holder();
433
if (!holder_klass->is_being_initialized() &&
434
!holder_klass->is_initialized() &&
435
!holder_klass->is_interface()) {
436
uncommon_trap(Deoptimization::Reason_uninitialized,
437
Deoptimization::Action_reinterpret,
438
holder_klass);
439
return true;
440
}
441
442
assert(dest_method->is_loaded(), "dest_method: typeflow responsibility");
443
return false;
444
}
445
446
#ifdef ASSERT
447
static bool check_call_consistency(JVMState* jvms, CallGenerator* cg) {
448
ciMethod* symbolic_info = jvms->method()->get_method_at_bci(jvms->bci());
449
ciMethod* resolved_method = cg->method();
450
if (!ciMethod::is_consistent_info(symbolic_info, resolved_method)) {
451
tty->print_cr("JVMS:");
452
jvms->dump();
453
tty->print_cr("Bytecode info:");
454
jvms->method()->get_method_at_bci(jvms->bci())->print(); tty->cr();
455
tty->print_cr("Resolved method:");
456
cg->method()->print(); tty->cr();
457
return false;
458
}
459
return true;
460
}
461
#endif // ASSERT
462
463
//------------------------------do_call----------------------------------------
464
// Handle your basic call. Inline if we can & want to, else just setup call.
465
void Parse::do_call() {
466
// It's likely we are going to add debug info soon.
467
// Also, if we inline a guy who eventually needs debug info for this JVMS,
468
// our contribution to it is cleaned up right here.
469
kill_dead_locals();
470
471
C->print_inlining_assert_ready();
472
473
// Set frequently used booleans
474
const bool is_virtual = bc() == Bytecodes::_invokevirtual;
475
const bool is_virtual_or_interface = is_virtual || bc() == Bytecodes::_invokeinterface;
476
const bool has_receiver = Bytecodes::has_receiver(bc());
477
478
// Find target being called
479
bool will_link;
480
ciSignature* declared_signature = NULL;
481
ciMethod* orig_callee = iter().get_method(will_link, &declared_signature); // callee in the bytecode
482
ciInstanceKlass* holder_klass = orig_callee->holder();
483
ciKlass* holder = iter().get_declared_method_holder();
484
ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
485
assert(declared_signature != NULL, "cannot be null");
486
487
// Bump max node limit for JSR292 users
488
if (bc() == Bytecodes::_invokedynamic || orig_callee->is_method_handle_intrinsic()) {
489
C->set_max_node_limit(3*MaxNodeLimit);
490
}
491
492
// uncommon-trap when callee is unloaded, uninitialized or will not link
493
// bailout when too many arguments for register representation
494
if (!will_link || can_not_compile_call_site(orig_callee, klass)) {
495
if (PrintOpto && (Verbose || WizardMode)) {
496
method()->print_name(); tty->print_cr(" can not compile call at bci %d to:", bci());
497
orig_callee->print_name(); tty->cr();
498
}
499
return;
500
}
501
assert(holder_klass->is_loaded(), "");
502
//assert((bc_callee->is_static() || is_invokedynamic) == !has_receiver , "must match bc"); // XXX invokehandle (cur_bc_raw)
503
// Note: this takes into account invokeinterface of methods declared in java/lang/Object,
504
// which should be invokevirtuals but according to the VM spec may be invokeinterfaces
505
assert(holder_klass->is_interface() || holder_klass->super() == NULL || (bc() != Bytecodes::_invokeinterface), "must match bc");
506
// Note: In the absence of miranda methods, an abstract class K can perform
507
// an invokevirtual directly on an interface method I.m if K implements I.
508
509
// orig_callee is the resolved callee which's signature includes the
510
// appendix argument.
511
const int nargs = orig_callee->arg_size();
512
const bool is_signature_polymorphic = MethodHandles::is_signature_polymorphic(orig_callee->intrinsic_id());
513
514
// Push appendix argument (MethodType, CallSite, etc.), if one.
515
if (iter().has_appendix()) {
516
ciObject* appendix_arg = iter().get_appendix();
517
const TypeOopPtr* appendix_arg_type = TypeOopPtr::make_from_constant(appendix_arg, /* require_const= */ true);
518
Node* appendix_arg_node = _gvn.makecon(appendix_arg_type);
519
push(appendix_arg_node);
520
}
521
522
// ---------------------
523
// Does Class Hierarchy Analysis reveal only a single target of a v-call?
524
// Then we may inline or make a static call, but become dependent on there being only 1 target.
525
// Does the call-site type profile reveal only one receiver?
526
// Then we may introduce a run-time check and inline on the path where it succeeds.
527
// The other path may uncommon_trap, check for another receiver, or do a v-call.
528
529
// Try to get the most accurate receiver type
530
ciMethod* callee = orig_callee;
531
int vtable_index = Method::invalid_vtable_index;
532
bool call_does_dispatch = false;
533
534
// Speculative type of the receiver if any
535
ciKlass* speculative_receiver_type = NULL;
536
if (is_virtual_or_interface) {
537
Node* receiver_node = stack(sp() - nargs);
538
const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
539
// call_does_dispatch and vtable_index are out-parameters. They might be changed.
540
// For arrays, klass below is Object. When vtable calls are used,
541
// resolving the call with Object would allow an illegal call to
542
// finalize() on an array. We use holder instead: illegal calls to
543
// finalize() won't be compiled as vtable calls (IC call
544
// resolution will catch the illegal call) and the few legal calls
545
// on array types won't be either.
546
callee = C->optimize_virtual_call(method(), klass, holder, orig_callee,
547
receiver_type, is_virtual,
548
call_does_dispatch, vtable_index); // out-parameters
549
speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL;
550
}
551
552
// Additional receiver subtype checks for interface calls via invokespecial or invokeinterface.
553
ciKlass* receiver_constraint = NULL;
554
if (iter().cur_bc_raw() == Bytecodes::_invokespecial && !orig_callee->is_object_initializer()) {
555
ciInstanceKlass* calling_klass = method()->holder();
556
ciInstanceKlass* sender_klass = calling_klass;
557
if (sender_klass->is_interface()) {
558
receiver_constraint = sender_klass;
559
}
560
} else if (iter().cur_bc_raw() == Bytecodes::_invokeinterface && orig_callee->is_private()) {
561
assert(holder->is_interface(), "How did we get a non-interface method here!");
562
receiver_constraint = holder;
563
}
564
565
if (receiver_constraint != NULL) {
566
Node* receiver_node = stack(sp() - nargs);
567
Node* cls_node = makecon(TypeKlassPtr::make(receiver_constraint));
568
Node* bad_type_ctrl = NULL;
569
Node* casted_receiver = gen_checkcast(receiver_node, cls_node, &bad_type_ctrl);
570
if (bad_type_ctrl != NULL) {
571
PreserveJVMState pjvms(this);
572
set_control(bad_type_ctrl);
573
uncommon_trap(Deoptimization::Reason_class_check,
574
Deoptimization::Action_none);
575
}
576
if (stopped()) {
577
return; // MUST uncommon-trap?
578
}
579
set_stack(sp() - nargs, casted_receiver);
580
}
581
582
// Note: It's OK to try to inline a virtual call.
583
// The call generator will not attempt to inline a polymorphic call
584
// unless it knows how to optimize the receiver dispatch.
585
bool try_inline = (C->do_inlining() || InlineAccessors);
586
587
// ---------------------
588
dec_sp(nargs); // Temporarily pop args for JVM state of call
589
JVMState* jvms = sync_jvms();
590
591
// ---------------------
592
// Decide call tactic.
593
// This call checks with CHA, the interpreter profile, intrinsics table, etc.
594
// It decides whether inlining is desirable or not.
595
CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type);
596
597
// NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead.
598
orig_callee = callee = NULL;
599
600
// ---------------------
601
// Round double arguments before call
602
round_double_arguments(cg->method());
603
604
// Feed profiling data for arguments to the type system so it can
605
// propagate it as speculative types
606
record_profiled_arguments_for_speculation(cg->method(), bc());
607
608
#ifndef PRODUCT
609
// bump global counters for calls
610
count_compiled_calls(/*at_method_entry*/ false, cg->is_inline());
611
612
// Record first part of parsing work for this call
613
parse_histogram()->record_change();
614
#endif // not PRODUCT
615
616
assert(jvms == this->jvms(), "still operating on the right JVMS");
617
assert(jvms_in_sync(), "jvms must carry full info into CG");
618
619
// save across call, for a subsequent cast_not_null.
620
Node* receiver = has_receiver ? argument(0) : NULL;
621
622
// The extra CheckCastPPs for speculative types mess with PhaseStringOpts
623
if (receiver != NULL && !call_does_dispatch && !cg->is_string_late_inline()) {
624
// Feed profiling data for a single receiver to the type system so
625
// it can propagate it as a speculative type
626
receiver = record_profiled_receiver_for_speculation(receiver);
627
}
628
629
JVMState* new_jvms = cg->generate(jvms);
630
if (new_jvms == NULL) {
631
// When inlining attempt fails (e.g., too many arguments),
632
// it may contaminate the current compile state, making it
633
// impossible to pull back and try again. Once we call
634
// cg->generate(), we are committed. If it fails, the whole
635
// compilation task is compromised.
636
if (failing()) return;
637
638
// This can happen if a library intrinsic is available, but refuses
639
// the call site, perhaps because it did not match a pattern the
640
// intrinsic was expecting to optimize. Should always be possible to
641
// get a normal java call that may inline in that case
642
cg = C->call_generator(cg->method(), vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type, /* allow_intrinsics= */ false);
643
new_jvms = cg->generate(jvms);
644
if (new_jvms == NULL) {
645
guarantee(failing(), "call failed to generate: calls should work");
646
return;
647
}
648
}
649
650
if (cg->is_inline()) {
651
// Accumulate has_loops estimate
652
C->env()->notice_inlined_method(cg->method());
653
}
654
655
// Reset parser state from [new_]jvms, which now carries results of the call.
656
// Return value (if any) is already pushed on the stack by the cg.
657
add_exception_states_from(new_jvms);
658
if (new_jvms->map()->control() == top()) {
659
stop_and_kill_map();
660
} else {
661
assert(new_jvms->same_calls_as(jvms), "method/bci left unchanged");
662
set_jvms(new_jvms);
663
}
664
665
assert(check_call_consistency(jvms, cg), "inconsistent info");
666
667
if (!stopped()) {
668
// This was some sort of virtual call, which did a null check for us.
669
// Now we can assert receiver-not-null, on the normal return path.
670
if (receiver != NULL && cg->is_virtual()) {
671
Node* cast = cast_not_null(receiver);
672
// %%% assert(receiver == cast, "should already have cast the receiver");
673
}
674
675
ciType* rtype = cg->method()->return_type();
676
ciType* ctype = declared_signature->return_type();
677
678
if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
679
// Be careful here with return types.
680
if (ctype != rtype) {
681
BasicType rt = rtype->basic_type();
682
BasicType ct = ctype->basic_type();
683
if (ct == T_VOID) {
684
// It's OK for a method to return a value that is discarded.
685
// The discarding does not require any special action from the caller.
686
// The Java code knows this, at VerifyType.isNullConversion.
687
pop_node(rt); // whatever it was, pop it
688
} else if (rt == T_INT || is_subword_type(rt)) {
689
// Nothing. These cases are handled in lambda form bytecode.
690
assert(ct == T_INT || is_subword_type(ct), "must match: rt=%s, ct=%s", type2name(rt), type2name(ct));
691
} else if (is_reference_type(rt)) {
692
assert(is_reference_type(ct), "rt=%s, ct=%s", type2name(rt), type2name(ct));
693
if (ctype->is_loaded()) {
694
const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
695
const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
696
if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
697
Node* retnode = pop();
698
Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
699
push(cast_obj);
700
}
701
}
702
} else {
703
assert(rt == ct, "unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct));
704
// push a zero; it's better than getting an oop/int mismatch
705
pop_node(rt);
706
Node* retnode = zerocon(ct);
707
push_node(ct, retnode);
708
}
709
// Now that the value is well-behaved, continue with the call-site type.
710
rtype = ctype;
711
}
712
} else {
713
// Symbolic resolution enforces the types to be the same.
714
// NOTE: We must relax the assert for unloaded types because two
715
// different ciType instances of the same unloaded class type
716
// can appear to be "loaded" by different loaders (depending on
717
// the accessing class).
718
assert(!rtype->is_loaded() || !ctype->is_loaded() || rtype == ctype,
719
"mismatched return types: rtype=%s, ctype=%s", rtype->name(), ctype->name());
720
}
721
722
// If the return type of the method is not loaded, assert that the
723
// value we got is a null. Otherwise, we need to recompile.
724
if (!rtype->is_loaded()) {
725
if (PrintOpto && (Verbose || WizardMode)) {
726
method()->print_name(); tty->print_cr(" asserting nullness of result at bci: %d", bci());
727
cg->method()->print_name(); tty->cr();
728
}
729
if (C->log() != NULL) {
730
C->log()->elem("assert_null reason='return' klass='%d'",
731
C->log()->identify(rtype));
732
}
733
// If there is going to be a trap, put it at the next bytecode:
734
set_bci(iter().next_bci());
735
null_assert(peek());
736
set_bci(iter().cur_bci()); // put it back
737
}
738
BasicType ct = ctype->basic_type();
739
if (is_reference_type(ct)) {
740
record_profiled_return_for_speculation();
741
}
742
}
743
744
// Restart record of parsing work after possible inlining of call
745
#ifndef PRODUCT
746
parse_histogram()->set_initial_state(bc());
747
#endif
748
}
749
750
//---------------------------catch_call_exceptions-----------------------------
751
// Put a Catch and CatchProj nodes behind a just-created call.
752
// Send their caught exceptions to the proper handler.
753
// This may be used after a call to the rethrow VM stub,
754
// when it is needed to process unloaded exception classes.
755
void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
756
// Exceptions are delivered through this channel:
757
Node* i_o = this->i_o();
758
759
// Add a CatchNode.
760
GrowableArray<int>* bcis = new (C->node_arena()) GrowableArray<int>(C->node_arena(), 8, 0, -1);
761
GrowableArray<const Type*>* extypes = new (C->node_arena()) GrowableArray<const Type*>(C->node_arena(), 8, 0, NULL);
762
GrowableArray<int>* saw_unloaded = new (C->node_arena()) GrowableArray<int>(C->node_arena(), 8, 0, 0);
763
764
bool default_handler = false;
765
for (; !handlers.is_done(); handlers.next()) {
766
ciExceptionHandler* h = handlers.handler();
767
int h_bci = h->handler_bci();
768
ciInstanceKlass* h_klass = h->is_catch_all() ? env()->Throwable_klass() : h->catch_klass();
769
// Do not introduce unloaded exception types into the graph:
770
if (!h_klass->is_loaded()) {
771
if (saw_unloaded->contains(h_bci)) {
772
/* We've already seen an unloaded exception with h_bci,
773
so don't duplicate. Duplication will cause the CatchNode to be
774
unnecessarily large. See 4713716. */
775
continue;
776
} else {
777
saw_unloaded->append(h_bci);
778
}
779
}
780
const Type* h_extype = TypeOopPtr::make_from_klass(h_klass);
781
// (We use make_from_klass because it respects UseUniqueSubclasses.)
782
h_extype = h_extype->join(TypeInstPtr::NOTNULL);
783
assert(!h_extype->empty(), "sanity");
784
// Note: It's OK if the BCIs repeat themselves.
785
bcis->append(h_bci);
786
extypes->append(h_extype);
787
if (h_bci == -1) {
788
default_handler = true;
789
}
790
}
791
792
if (!default_handler) {
793
bcis->append(-1);
794
extypes->append(TypeOopPtr::make_from_klass(env()->Throwable_klass())->is_instptr());
795
}
796
797
int len = bcis->length();
798
CatchNode *cn = new CatchNode(control(), i_o, len+1);
799
Node *catch_ = _gvn.transform(cn);
800
801
// now branch with the exception state to each of the (potential)
802
// handlers
803
for(int i=0; i < len; i++) {
804
// Setup JVM state to enter the handler.
805
PreserveJVMState pjvms(this);
806
// Locals are just copied from before the call.
807
// Get control from the CatchNode.
808
int handler_bci = bcis->at(i);
809
Node* ctrl = _gvn.transform( new CatchProjNode(catch_, i+1,handler_bci));
810
// This handler cannot happen?
811
if (ctrl == top()) continue;
812
set_control(ctrl);
813
814
// Create exception oop
815
const TypeInstPtr* extype = extypes->at(i)->is_instptr();
816
Node *ex_oop = _gvn.transform(new CreateExNode(extypes->at(i), ctrl, i_o));
817
818
// Handle unloaded exception classes.
819
if (saw_unloaded->contains(handler_bci)) {
820
// An unloaded exception type is coming here. Do an uncommon trap.
821
#ifndef PRODUCT
822
// We do not expect the same handler bci to take both cold unloaded
823
// and hot loaded exceptions. But, watch for it.
824
if ((Verbose || WizardMode) && extype->is_loaded()) {
825
tty->print("Warning: Handler @%d takes mixed loaded/unloaded exceptions in ", bci());
826
method()->print_name(); tty->cr();
827
} else if (PrintOpto && (Verbose || WizardMode)) {
828
tty->print("Bailing out on unloaded exception type ");
829
extype->klass()->print_name();
830
tty->print(" at bci:%d in ", bci());
831
method()->print_name(); tty->cr();
832
}
833
#endif
834
// Emit an uncommon trap instead of processing the block.
835
set_bci(handler_bci);
836
push_ex_oop(ex_oop);
837
uncommon_trap(Deoptimization::Reason_unloaded,
838
Deoptimization::Action_reinterpret,
839
extype->klass(), "!loaded exception");
840
set_bci(iter().cur_bci()); // put it back
841
continue;
842
}
843
844
// go to the exception handler
845
if (handler_bci < 0) { // merge with corresponding rethrow node
846
throw_to_exit(make_exception_state(ex_oop));
847
} else { // Else jump to corresponding handle
848
push_ex_oop(ex_oop); // Clear stack and push just the oop.
849
merge_exception(handler_bci);
850
}
851
}
852
853
// The first CatchProj is for the normal return.
854
// (Note: If this is a call to rethrow_Java, this node goes dead.)
855
set_control(_gvn.transform( new CatchProjNode(catch_, CatchProjNode::fall_through_index, CatchProjNode::no_handler_bci)));
856
}
857
858
859
//----------------------------catch_inline_exceptions--------------------------
860
// Handle all exceptions thrown by an inlined method or individual bytecode.
861
// Common case 1: we have no handler, so all exceptions merge right into
862
// the rethrow case.
863
// Case 2: we have some handlers, with loaded exception klasses that have
864
// no subklasses. We do a Deutsch-Shiffman style type-check on the incoming
865
// exception oop and branch to the handler directly.
866
// Case 3: We have some handlers with subklasses or are not loaded at
867
// compile-time. We have to call the runtime to resolve the exception.
868
// So we insert a RethrowCall and all the logic that goes with it.
869
void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
870
// Caller is responsible for saving away the map for normal control flow!
871
assert(stopped(), "call set_map(NULL) first");
872
assert(method()->has_exception_handlers(), "don't come here w/o work to do");
873
874
Node* ex_node = saved_ex_oop(ex_map);
875
if (ex_node == top()) {
876
// No action needed.
877
return;
878
}
879
const TypeInstPtr* ex_type = _gvn.type(ex_node)->isa_instptr();
880
NOT_PRODUCT(if (ex_type==NULL) tty->print_cr("*** Exception not InstPtr"));
881
if (ex_type == NULL)
882
ex_type = TypeOopPtr::make_from_klass(env()->Throwable_klass())->is_instptr();
883
884
// determine potential exception handlers
885
ciExceptionHandlerStream handlers(method(), bci(),
886
ex_type->klass()->as_instance_klass(),
887
ex_type->klass_is_exact());
888
889
// Start executing from the given throw state. (Keep its stack, for now.)
890
// Get the exception oop as known at compile time.
891
ex_node = use_exception_state(ex_map);
892
893
// Get the exception oop klass from its header
894
Node* ex_klass_node = NULL;
895
if (has_ex_handler() && !ex_type->klass_is_exact()) {
896
Node* p = basic_plus_adr( ex_node, ex_node, oopDesc::klass_offset_in_bytes());
897
ex_klass_node = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT));
898
899
// Compute the exception klass a little more cleverly.
900
// Obvious solution is to simple do a LoadKlass from the 'ex_node'.
901
// However, if the ex_node is a PhiNode, I'm going to do a LoadKlass for
902
// each arm of the Phi. If I know something clever about the exceptions
903
// I'm loading the class from, I can replace the LoadKlass with the
904
// klass constant for the exception oop.
905
if (ex_node->is_Phi()) {
906
ex_klass_node = new PhiNode(ex_node->in(0), TypeKlassPtr::OBJECT);
907
for (uint i = 1; i < ex_node->req(); i++) {
908
Node* ex_in = ex_node->in(i);
909
if (ex_in == top() || ex_in == NULL) {
910
// This path was not taken.
911
ex_klass_node->init_req(i, top());
912
continue;
913
}
914
Node* p = basic_plus_adr(ex_in, ex_in, oopDesc::klass_offset_in_bytes());
915
Node* k = _gvn.transform( LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT));
916
ex_klass_node->init_req( i, k );
917
}
918
_gvn.set_type(ex_klass_node, TypeKlassPtr::OBJECT);
919
920
}
921
}
922
923
// Scan the exception table for applicable handlers.
924
// If none, we can call rethrow() and be done!
925
// If precise (loaded with no subklasses), insert a D.S. style
926
// pointer compare to the correct handler and loop back.
927
// If imprecise, switch to the Rethrow VM-call style handling.
928
929
int remaining = handlers.count_remaining();
930
931
// iterate through all entries sequentially
932
for (;!handlers.is_done(); handlers.next()) {
933
ciExceptionHandler* handler = handlers.handler();
934
935
if (handler->is_rethrow()) {
936
// If we fell off the end of the table without finding an imprecise
937
// exception klass (and without finding a generic handler) then we
938
// know this exception is not handled in this method. We just rethrow
939
// the exception into the caller.
940
throw_to_exit(make_exception_state(ex_node));
941
return;
942
}
943
944
// exception handler bci range covers throw_bci => investigate further
945
int handler_bci = handler->handler_bci();
946
947
if (remaining == 1) {
948
push_ex_oop(ex_node); // Push exception oop for handler
949
if (PrintOpto && WizardMode) {
950
tty->print_cr(" Catching every inline exception bci:%d -> handler_bci:%d", bci(), handler_bci);
951
}
952
merge_exception(handler_bci); // jump to handler
953
return; // No more handling to be done here!
954
}
955
956
// Get the handler's klass
957
ciInstanceKlass* klass = handler->catch_klass();
958
959
if (!klass->is_loaded()) { // klass is not loaded?
960
// fall through into catch_call_exceptions which will emit a
961
// handler with an uncommon trap.
962
break;
963
}
964
965
if (klass->is_interface()) // should not happen, but...
966
break; // bail out
967
968
// Check the type of the exception against the catch type
969
const TypeKlassPtr *tk = TypeKlassPtr::make(klass);
970
Node* con = _gvn.makecon(tk);
971
Node* not_subtype_ctrl = gen_subtype_check(ex_klass_node, con);
972
if (!stopped()) {
973
PreserveJVMState pjvms(this);
974
const TypeInstPtr* tinst = TypeOopPtr::make_from_klass_unique(klass)->cast_to_ptr_type(TypePtr::NotNull)->is_instptr();
975
assert(klass->has_subklass() || tinst->klass_is_exact(), "lost exactness");
976
Node* ex_oop = _gvn.transform(new CheckCastPPNode(control(), ex_node, tinst));
977
push_ex_oop(ex_oop); // Push exception oop for handler
978
if (PrintOpto && WizardMode) {
979
tty->print(" Catching inline exception bci:%d -> handler_bci:%d -- ", bci(), handler_bci);
980
klass->print_name();
981
tty->cr();
982
}
983
merge_exception(handler_bci);
984
}
985
set_control(not_subtype_ctrl);
986
987
// Come here if exception does not match handler.
988
// Carry on with more handler checks.
989
--remaining;
990
}
991
992
assert(!stopped(), "you should return if you finish the chain");
993
994
// Oops, need to call into the VM to resolve the klasses at runtime.
995
// Note: This call must not deoptimize, since it is not a real at this bci!
996
kill_dead_locals();
997
998
make_runtime_call(RC_NO_LEAF | RC_MUST_THROW,
999
OptoRuntime::rethrow_Type(),
1000
OptoRuntime::rethrow_stub(),
1001
NULL, NULL,
1002
ex_node);
1003
1004
// Rethrow is a pure call, no side effects, only a result.
1005
// The result cannot be allocated, so we use I_O
1006
1007
// Catch exceptions from the rethrow
1008
catch_call_exceptions(handlers);
1009
}
1010
1011
1012
// (Note: Moved add_debug_info into GraphKit::add_safepoint_edges.)
1013
1014
1015
#ifndef PRODUCT
1016
void Parse::count_compiled_calls(bool at_method_entry, bool is_inline) {
1017
if( CountCompiledCalls ) {
1018
if( at_method_entry ) {
1019
// bump invocation counter if top method (for statistics)
1020
if (CountCompiledCalls && depth() == 1) {
1021
const TypePtr* addr_type = TypeMetadataPtr::make(method());
1022
Node* adr1 = makecon(addr_type);
1023
Node* adr2 = basic_plus_adr(adr1, adr1, in_bytes(Method::compiled_invocation_counter_offset()));
1024
increment_counter(adr2);
1025
}
1026
} else if (is_inline) {
1027
switch (bc()) {
1028
case Bytecodes::_invokevirtual: increment_counter(SharedRuntime::nof_inlined_calls_addr()); break;
1029
case Bytecodes::_invokeinterface: increment_counter(SharedRuntime::nof_inlined_interface_calls_addr()); break;
1030
case Bytecodes::_invokestatic:
1031
case Bytecodes::_invokedynamic:
1032
case Bytecodes::_invokespecial: increment_counter(SharedRuntime::nof_inlined_static_calls_addr()); break;
1033
default: fatal("unexpected call bytecode");
1034
}
1035
} else {
1036
switch (bc()) {
1037
case Bytecodes::_invokevirtual: increment_counter(SharedRuntime::nof_normal_calls_addr()); break;
1038
case Bytecodes::_invokeinterface: increment_counter(SharedRuntime::nof_interface_calls_addr()); break;
1039
case Bytecodes::_invokestatic:
1040
case Bytecodes::_invokedynamic:
1041
case Bytecodes::_invokespecial: increment_counter(SharedRuntime::nof_static_calls_addr()); break;
1042
default: fatal("unexpected call bytecode");
1043
}
1044
}
1045
}
1046
}
1047
#endif //PRODUCT
1048
1049
1050
ciMethod* Compile::optimize_virtual_call(ciMethod* caller, ciInstanceKlass* klass,
1051
ciKlass* holder, ciMethod* callee,
1052
const TypeOopPtr* receiver_type, bool is_virtual,
1053
bool& call_does_dispatch, int& vtable_index,
1054
bool check_access) {
1055
// Set default values for out-parameters.
1056
call_does_dispatch = true;
1057
vtable_index = Method::invalid_vtable_index;
1058
1059
// Choose call strategy.
1060
ciMethod* optimized_virtual_method = optimize_inlining(caller, klass, holder, callee,
1061
receiver_type, check_access);
1062
1063
// Have the call been sufficiently improved such that it is no longer a virtual?
1064
if (optimized_virtual_method != NULL) {
1065
callee = optimized_virtual_method;
1066
call_does_dispatch = false;
1067
} else if (!UseInlineCaches && is_virtual && callee->is_loaded()) {
1068
// We can make a vtable call at this site
1069
vtable_index = callee->resolve_vtable_index(caller->holder(), holder);
1070
}
1071
return callee;
1072
}
1073
1074
// Identify possible target method and inlining style
1075
ciMethod* Compile::optimize_inlining(ciMethod* caller, ciInstanceKlass* klass, ciKlass* holder,
1076
ciMethod* callee, const TypeOopPtr* receiver_type,
1077
bool check_access) {
1078
// only use for virtual or interface calls
1079
1080
// If it is obviously final, do not bother to call find_monomorphic_target,
1081
// because the class hierarchy checks are not needed, and may fail due to
1082
// incompletely loaded classes. Since we do our own class loading checks
1083
// in this module, we may confidently bind to any method.
1084
if (callee->can_be_statically_bound()) {
1085
return callee;
1086
}
1087
1088
if (receiver_type == NULL) {
1089
return NULL; // no receiver type info
1090
}
1091
1092
// Attempt to improve the receiver
1093
bool actual_receiver_is_exact = false;
1094
ciInstanceKlass* actual_receiver = klass;
1095
// Array methods are all inherited from Object, and are monomorphic.
1096
// finalize() call on array is not allowed.
1097
if (receiver_type->isa_aryptr() &&
1098
callee->holder() == env()->Object_klass() &&
1099
callee->name() != ciSymbols::finalize_method_name()) {
1100
return callee;
1101
}
1102
1103
// All other interesting cases are instance klasses.
1104
if (!receiver_type->isa_instptr()) {
1105
return NULL;
1106
}
1107
1108
ciInstanceKlass *ikl = receiver_type->klass()->as_instance_klass();
1109
if (ikl->is_loaded() && ikl->is_initialized() && !ikl->is_interface() &&
1110
(ikl == actual_receiver || ikl->is_subtype_of(actual_receiver))) {
1111
// ikl is a same or better type than the original actual_receiver,
1112
// e.g. static receiver from bytecodes.
1113
actual_receiver = ikl;
1114
// Is the actual_receiver exact?
1115
actual_receiver_is_exact = receiver_type->klass_is_exact();
1116
}
1117
1118
ciInstanceKlass* calling_klass = caller->holder();
1119
ciMethod* cha_monomorphic_target = callee->find_monomorphic_target(calling_klass, klass, actual_receiver, check_access);
1120
1121
// Validate receiver info against target method.
1122
if (cha_monomorphic_target != NULL) {
1123
bool has_receiver = !cha_monomorphic_target->is_static();
1124
bool is_interface_holder = cha_monomorphic_target->holder()->is_interface();
1125
if (has_receiver && !is_interface_holder) {
1126
if (!cha_monomorphic_target->holder()->is_subtype_of(receiver_type->klass())) {
1127
cha_monomorphic_target = NULL; // not a subtype
1128
}
1129
}
1130
}
1131
1132
if (cha_monomorphic_target != NULL) {
1133
// Hardwiring a virtual.
1134
assert(!callee->can_be_statically_bound(), "should have been handled earlier");
1135
assert(!cha_monomorphic_target->is_abstract(), "");
1136
if (!cha_monomorphic_target->can_be_statically_bound(actual_receiver)) {
1137
// If we inlined because CHA revealed only a single target method,
1138
// then we are dependent on that target method not getting overridden
1139
// by dynamic class loading. Be sure to test the "static" receiver
1140
// dest_method here, as opposed to the actual receiver, which may
1141
// falsely lead us to believe that the receiver is final or private.
1142
dependencies()->assert_unique_concrete_method(actual_receiver, cha_monomorphic_target, holder, callee);
1143
}
1144
return cha_monomorphic_target;
1145
}
1146
1147
// If the type is exact, we can still bind the method w/o a vcall.
1148
// (This case comes after CHA so we can see how much extra work it does.)
1149
if (actual_receiver_is_exact) {
1150
// In case of evolution, there is a dependence on every inlined method, since each
1151
// such method can be changed when its class is redefined.
1152
ciMethod* exact_method = callee->resolve_invoke(calling_klass, actual_receiver);
1153
if (exact_method != NULL) {
1154
return exact_method;
1155
}
1156
}
1157
1158
return NULL;
1159
}
1160
1161