Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/ci/ciMethod.cpp
64440 views
1
/*
2
* Copyright (c) 1999, 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/ciCallProfile.hpp"
27
#include "ci/ciExceptionHandler.hpp"
28
#include "ci/ciInstanceKlass.hpp"
29
#include "ci/ciMethod.hpp"
30
#include "ci/ciMethodBlocks.hpp"
31
#include "ci/ciMethodData.hpp"
32
#include "ci/ciStreams.hpp"
33
#include "ci/ciSymbol.hpp"
34
#include "ci/ciReplay.hpp"
35
#include "ci/ciSymbols.hpp"
36
#include "ci/ciUtilities.inline.hpp"
37
#include "compiler/abstractCompiler.hpp"
38
#include "compiler/methodLiveness.hpp"
39
#include "interpreter/interpreter.hpp"
40
#include "interpreter/linkResolver.hpp"
41
#include "interpreter/oopMapCache.hpp"
42
#include "memory/allocation.inline.hpp"
43
#include "memory/resourceArea.hpp"
44
#include "oops/generateOopMap.hpp"
45
#include "oops/method.inline.hpp"
46
#include "oops/oop.inline.hpp"
47
#include "prims/methodHandles.hpp"
48
#include "runtime/deoptimization.hpp"
49
#include "runtime/handles.inline.hpp"
50
#include "utilities/bitMap.inline.hpp"
51
#include "utilities/xmlstream.hpp"
52
#ifdef COMPILER2
53
#include "ci/bcEscapeAnalyzer.hpp"
54
#include "ci/ciTypeFlow.hpp"
55
#include "oops/method.hpp"
56
#endif
57
58
// ciMethod
59
//
60
// This class represents a Method* in the HotSpot virtual
61
// machine.
62
63
64
// ------------------------------------------------------------------
65
// ciMethod::ciMethod
66
//
67
// Loaded method.
68
ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
69
ciMetadata(h_m()),
70
_holder(holder)
71
{
72
assert(h_m() != NULL, "no null method");
73
74
if (LogTouchedMethods) {
75
h_m->log_touched(Thread::current());
76
}
77
// These fields are always filled in in loaded methods.
78
_flags = ciFlags(h_m->access_flags());
79
80
// Easy to compute, so fill them in now.
81
_max_stack = h_m->max_stack();
82
_max_locals = h_m->max_locals();
83
_code_size = h_m->code_size();
84
_handler_count = h_m->exception_table_length();
85
_size_of_parameters = h_m->size_of_parameters();
86
_uses_monitors = h_m->access_flags().has_monitor_bytecodes();
87
_balanced_monitors = !_uses_monitors || h_m->access_flags().is_monitor_matching();
88
_is_c1_compilable = !h_m->is_not_c1_compilable();
89
_is_c2_compilable = !h_m->is_not_c2_compilable();
90
_can_be_parsed = true;
91
_has_reserved_stack_access = h_m->has_reserved_stack_access();
92
_is_overpass = h_m->is_overpass();
93
// Lazy fields, filled in on demand. Require allocation.
94
_code = NULL;
95
_exception_handlers = NULL;
96
_liveness = NULL;
97
_method_blocks = NULL;
98
#if defined(COMPILER2)
99
_flow = NULL;
100
_bcea = NULL;
101
#endif // COMPILER2
102
103
// Check for blackhole intrinsic and then populate the intrinsic ID.
104
CompilerOracle::tag_blackhole_if_possible(h_m);
105
_intrinsic_id = h_m->intrinsic_id();
106
107
ciEnv *env = CURRENT_ENV;
108
if (env->jvmti_can_hotswap_or_post_breakpoint()) {
109
// 6328518 check hotswap conditions under the right lock.
110
MutexLocker locker(Compile_lock);
111
if (Dependencies::check_evol_method(h_m()) != NULL) {
112
_is_c1_compilable = false;
113
_is_c2_compilable = false;
114
_can_be_parsed = false;
115
}
116
} else {
117
DEBUG_ONLY(CompilerThread::current()->check_possible_safepoint());
118
}
119
120
if (h_m->method_holder()->is_linked()) {
121
_can_be_statically_bound = h_m->can_be_statically_bound();
122
} else {
123
// Have to use a conservative value in this case.
124
_can_be_statically_bound = false;
125
}
126
127
// Adjust the definition of this condition to be more useful:
128
// %%% take these conditions into account in vtable generation
129
if (!_can_be_statically_bound && h_m->is_private())
130
_can_be_statically_bound = true;
131
if (_can_be_statically_bound && h_m->is_abstract())
132
_can_be_statically_bound = false;
133
134
// generating _signature may allow GC and therefore move m.
135
// These fields are always filled in.
136
_name = env->get_symbol(h_m->name());
137
ciSymbol* sig_symbol = env->get_symbol(h_m->signature());
138
constantPoolHandle cpool(Thread::current(), h_m->constants());
139
_signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol);
140
_method_data = NULL;
141
_nmethod_age = h_m->nmethod_age();
142
// Take a snapshot of these values, so they will be commensurate with the MDO.
143
if (ProfileInterpreter || CompilerConfig::is_c1_profiling()) {
144
int invcnt = h_m->interpreter_invocation_count();
145
// if the value overflowed report it as max int
146
_interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;
147
_interpreter_throwout_count = h_m->interpreter_throwout_count();
148
} else {
149
_interpreter_invocation_count = 0;
150
_interpreter_throwout_count = 0;
151
}
152
if (_interpreter_invocation_count == 0)
153
_interpreter_invocation_count = 1;
154
_instructions_size = -1;
155
#ifdef ASSERT
156
if (ReplayCompiles) {
157
ciReplay::initialize(this);
158
}
159
#endif
160
}
161
162
163
// ------------------------------------------------------------------
164
// ciMethod::ciMethod
165
//
166
// Unloaded method.
167
ciMethod::ciMethod(ciInstanceKlass* holder,
168
ciSymbol* name,
169
ciSymbol* signature,
170
ciInstanceKlass* accessor) :
171
ciMetadata((Metadata*)NULL),
172
_name( name),
173
_holder( holder),
174
_method_data( NULL),
175
_method_blocks( NULL),
176
_intrinsic_id( vmIntrinsics::_none),
177
_instructions_size(-1),
178
_can_be_statically_bound(false),
179
_liveness( NULL)
180
#if defined(COMPILER2)
181
,
182
_flow( NULL),
183
_bcea( NULL)
184
#endif // COMPILER2
185
{
186
// Usually holder and accessor are the same type but in some cases
187
// the holder has the wrong class loader (e.g. invokedynamic call
188
// sites) so we pass the accessor.
189
_signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);
190
}
191
192
193
// ------------------------------------------------------------------
194
// ciMethod::load_code
195
//
196
// Load the bytecodes and exception handler table for this method.
197
void ciMethod::load_code() {
198
VM_ENTRY_MARK;
199
assert(is_loaded(), "only loaded methods have code");
200
201
Method* me = get_Method();
202
Arena* arena = CURRENT_THREAD_ENV->arena();
203
204
// Load the bytecodes.
205
_code = (address)arena->Amalloc(code_size());
206
memcpy(_code, me->code_base(), code_size());
207
208
#if INCLUDE_JVMTI
209
// Revert any breakpoint bytecodes in ci's copy
210
if (me->number_of_breakpoints() > 0) {
211
BreakpointInfo* bp = me->method_holder()->breakpoints();
212
for (; bp != NULL; bp = bp->next()) {
213
if (bp->match(me)) {
214
code_at_put(bp->bci(), bp->orig_bytecode());
215
}
216
}
217
}
218
#endif
219
220
// And load the exception table.
221
ExceptionTable exc_table(me);
222
223
// Allocate one extra spot in our list of exceptions. This
224
// last entry will be used to represent the possibility that
225
// an exception escapes the method. See ciExceptionHandlerStream
226
// for details.
227
_exception_handlers =
228
(ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*)
229
* (_handler_count + 1));
230
if (_handler_count > 0) {
231
for (int i=0; i<_handler_count; i++) {
232
_exception_handlers[i] = new (arena) ciExceptionHandler(
233
holder(),
234
/* start */ exc_table.start_pc(i),
235
/* limit */ exc_table.end_pc(i),
236
/* goto pc */ exc_table.handler_pc(i),
237
/* cp index */ exc_table.catch_type_index(i));
238
}
239
}
240
241
// Put an entry at the end of our list to represent the possibility
242
// of exceptional exit.
243
_exception_handlers[_handler_count] =
244
new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0);
245
246
if (CIPrintMethodCodes) {
247
print_codes();
248
}
249
}
250
251
252
// ------------------------------------------------------------------
253
// ciMethod::has_linenumber_table
254
//
255
// length unknown until decompression
256
bool ciMethod::has_linenumber_table() const {
257
check_is_loaded();
258
VM_ENTRY_MARK;
259
return get_Method()->has_linenumber_table();
260
}
261
262
263
// ------------------------------------------------------------------
264
// ciMethod::line_number_from_bci
265
int ciMethod::line_number_from_bci(int bci) const {
266
check_is_loaded();
267
VM_ENTRY_MARK;
268
return get_Method()->line_number_from_bci(bci);
269
}
270
271
272
// ------------------------------------------------------------------
273
// ciMethod::vtable_index
274
//
275
// Get the position of this method's entry in the vtable, if any.
276
int ciMethod::vtable_index() {
277
check_is_loaded();
278
assert(holder()->is_linked(), "must be linked");
279
VM_ENTRY_MARK;
280
return get_Method()->vtable_index();
281
}
282
283
// ------------------------------------------------------------------
284
// ciMethod::uses_balanced_monitors
285
//
286
// Does this method use monitors in a strict stack-disciplined manner?
287
bool ciMethod::has_balanced_monitors() {
288
check_is_loaded();
289
if (_balanced_monitors) return true;
290
291
// Analyze the method to see if monitors are used properly.
292
VM_ENTRY_MARK;
293
methodHandle method(THREAD, get_Method());
294
assert(method->has_monitor_bytecodes(), "should have checked this");
295
296
// Check to see if a previous compilation computed the
297
// monitor-matching analysis.
298
if (method->guaranteed_monitor_matching()) {
299
_balanced_monitors = true;
300
return true;
301
}
302
303
{
304
ExceptionMark em(THREAD);
305
ResourceMark rm(THREAD);
306
GeneratePairingInfo gpi(method);
307
if (!gpi.compute_map(THREAD)) {
308
fatal("Unrecoverable verification or out-of-memory error");
309
}
310
if (!gpi.monitor_safe()) {
311
return false;
312
}
313
method->set_guaranteed_monitor_matching();
314
_balanced_monitors = true;
315
}
316
return true;
317
}
318
319
320
// ------------------------------------------------------------------
321
// ciMethod::get_flow_analysis
322
ciTypeFlow* ciMethod::get_flow_analysis() {
323
#if defined(COMPILER2)
324
if (_flow == NULL) {
325
ciEnv* env = CURRENT_ENV;
326
_flow = new (env->arena()) ciTypeFlow(env, this);
327
_flow->do_flow();
328
}
329
return _flow;
330
#else // COMPILER2
331
ShouldNotReachHere();
332
return NULL;
333
#endif // COMPILER2
334
}
335
336
337
// ------------------------------------------------------------------
338
// ciMethod::get_osr_flow_analysis
339
ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) {
340
#if defined(COMPILER2)
341
// OSR entry points are always place after a call bytecode of some sort
342
assert(osr_bci >= 0, "must supply valid OSR entry point");
343
ciEnv* env = CURRENT_ENV;
344
ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci);
345
flow->do_flow();
346
return flow;
347
#else // COMPILER2
348
ShouldNotReachHere();
349
return NULL;
350
#endif // COMPILER2
351
}
352
353
// ------------------------------------------------------------------
354
// ciMethod::raw_liveness_at_bci
355
//
356
// Which local variables are live at a specific bci?
357
MethodLivenessResult ciMethod::raw_liveness_at_bci(int bci) {
358
check_is_loaded();
359
if (_liveness == NULL) {
360
// Create the liveness analyzer.
361
Arena* arena = CURRENT_ENV->arena();
362
_liveness = new (arena) MethodLiveness(arena, this);
363
_liveness->compute_liveness();
364
}
365
return _liveness->get_liveness_at(bci);
366
}
367
368
// ------------------------------------------------------------------
369
// ciMethod::liveness_at_bci
370
//
371
// Which local variables are live at a specific bci? When debugging
372
// will return true for all locals in some cases to improve debug
373
// information.
374
MethodLivenessResult ciMethod::liveness_at_bci(int bci) {
375
if (CURRENT_ENV->should_retain_local_variables() || DeoptimizeALot) {
376
// Keep all locals live for the user's edification and amusement.
377
MethodLivenessResult result(_max_locals);
378
result.set_range(0, _max_locals);
379
result.set_is_valid();
380
return result;
381
}
382
return raw_liveness_at_bci(bci);
383
}
384
385
// ciMethod::live_local_oops_at_bci
386
//
387
// find all the live oops in the locals array for a particular bci
388
// Compute what the interpreter believes by using the interpreter
389
// oopmap generator. This is used as a double check during osr to
390
// guard against conservative result from MethodLiveness making us
391
// think a dead oop is live. MethodLiveness is conservative in the
392
// sense that it may consider locals to be live which cannot be live,
393
// like in the case where a local could contain an oop or a primitive
394
// along different paths. In that case the local must be dead when
395
// those paths merge. Since the interpreter's viewpoint is used when
396
// gc'ing an interpreter frame we need to use its viewpoint during
397
// OSR when loading the locals.
398
399
ResourceBitMap ciMethod::live_local_oops_at_bci(int bci) {
400
VM_ENTRY_MARK;
401
InterpreterOopMap mask;
402
OopMapCache::compute_one_oop_map(methodHandle(THREAD, get_Method()), bci, &mask);
403
int mask_size = max_locals();
404
ResourceBitMap result(mask_size);
405
int i;
406
for (i = 0; i < mask_size ; i++ ) {
407
if (mask.is_oop(i)) result.set_bit(i);
408
}
409
return result;
410
}
411
412
413
#ifdef COMPILER1
414
// ------------------------------------------------------------------
415
// ciMethod::bci_block_start
416
//
417
// Marks all bcis where a new basic block starts
418
const BitMap& ciMethod::bci_block_start() {
419
check_is_loaded();
420
if (_liveness == NULL) {
421
// Create the liveness analyzer.
422
Arena* arena = CURRENT_ENV->arena();
423
_liveness = new (arena) MethodLiveness(arena, this);
424
_liveness->compute_liveness();
425
}
426
427
return _liveness->get_bci_block_start();
428
}
429
#endif // COMPILER1
430
431
432
// ------------------------------------------------------------------
433
// ciMethod::check_overflow
434
//
435
// Check whether the profile counter is overflowed and adjust if true.
436
// For invoke* it will turn negative values into max_jint,
437
// and for checkcast/aastore/instanceof turn positive values into min_jint.
438
int ciMethod::check_overflow(int c, Bytecodes::Code code) {
439
switch (code) {
440
case Bytecodes::_aastore: // fall-through
441
case Bytecodes::_checkcast: // fall-through
442
case Bytecodes::_instanceof: {
443
return (c > 0 ? min_jint : c); // always non-positive
444
}
445
default: {
446
assert(Bytecodes::is_invoke(code), "%s", Bytecodes::name(code));
447
return (c < 0 ? max_jint : c); // always non-negative
448
}
449
}
450
}
451
452
453
// ------------------------------------------------------------------
454
// ciMethod::call_profile_at_bci
455
//
456
// Get the ciCallProfile for the invocation of this method.
457
// Also reports receiver types for non-call type checks (if TypeProfileCasts).
458
ciCallProfile ciMethod::call_profile_at_bci(int bci) {
459
ResourceMark rm;
460
ciCallProfile result;
461
if (method_data() != NULL && method_data()->is_mature()) {
462
ciProfileData* data = method_data()->bci_to_data(bci);
463
if (data != NULL && data->is_CounterData()) {
464
// Every profiled call site has a counter.
465
int count = check_overflow(data->as_CounterData()->count(), java_code_at_bci(bci));
466
467
if (!data->is_ReceiverTypeData()) {
468
result._receiver_count[0] = 0; // that's a definite zero
469
} else { // ReceiverTypeData is a subclass of CounterData
470
ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData();
471
// In addition, virtual call sites have receiver type information
472
int receivers_count_total = 0;
473
int morphism = 0;
474
// Precompute morphism for the possible fixup
475
for (uint i = 0; i < call->row_limit(); i++) {
476
ciKlass* receiver = call->receiver(i);
477
if (receiver == NULL) continue;
478
morphism++;
479
}
480
int epsilon = 0;
481
// For a call, it is assumed that either the type of the receiver(s)
482
// is recorded or an associated counter is incremented, but not both. With
483
// tiered compilation, however, both can happen due to the interpreter and
484
// C1 profiling invocations differently. Address that inconsistency here.
485
if (morphism == 1 && count > 0) {
486
epsilon = count;
487
count = 0;
488
}
489
for (uint i = 0; i < call->row_limit(); i++) {
490
ciKlass* receiver = call->receiver(i);
491
if (receiver == NULL) continue;
492
int rcount = saturated_add(call->receiver_count(i), epsilon);
493
if (rcount == 0) rcount = 1; // Should be valid value
494
receivers_count_total = saturated_add(receivers_count_total, rcount);
495
// Add the receiver to result data.
496
result.add_receiver(receiver, rcount);
497
// If we extend profiling to record methods,
498
// we will set result._method also.
499
}
500
// Determine call site's morphism.
501
// The call site count is 0 with known morphism (only 1 or 2 receivers)
502
// or < 0 in the case of a type check failure for checkcast, aastore, instanceof.
503
// The call site count is > 0 in the case of a polymorphic virtual call.
504
if (morphism > 0 && morphism == result._limit) {
505
// The morphism <= MorphismLimit.
506
if ((morphism < ciCallProfile::MorphismLimit) ||
507
(morphism == ciCallProfile::MorphismLimit && count == 0)) {
508
#ifdef ASSERT
509
if (count > 0) {
510
this->print_short_name(tty);
511
tty->print_cr(" @ bci:%d", bci);
512
this->print_codes();
513
assert(false, "this call site should not be polymorphic");
514
}
515
#endif
516
result._morphism = morphism;
517
}
518
}
519
// Make the count consistent if this is a call profile. If count is
520
// zero or less, presume that this is a typecheck profile and
521
// do nothing. Otherwise, increase count to be the sum of all
522
// receiver's counts.
523
if (count >= 0) {
524
count = saturated_add(count, receivers_count_total);
525
}
526
}
527
result._count = count;
528
}
529
}
530
return result;
531
}
532
533
// ------------------------------------------------------------------
534
// Add new receiver and sort data by receiver's profile count.
535
void ciCallProfile::add_receiver(ciKlass* receiver, int receiver_count) {
536
// Add new receiver and sort data by receiver's counts when we have space
537
// for it otherwise replace the less called receiver (less called receiver
538
// is placed to the last array element which is not used).
539
// First array's element contains most called receiver.
540
int i = _limit;
541
for (; i > 0 && receiver_count > _receiver_count[i-1]; i--) {
542
_receiver[i] = _receiver[i-1];
543
_receiver_count[i] = _receiver_count[i-1];
544
}
545
_receiver[i] = receiver;
546
_receiver_count[i] = receiver_count;
547
if (_limit < MorphismLimit) _limit++;
548
}
549
550
551
void ciMethod::assert_virtual_call_type_ok(int bci) {
552
assert(java_code_at_bci(bci) == Bytecodes::_invokevirtual ||
553
java_code_at_bci(bci) == Bytecodes::_invokeinterface, "unexpected bytecode %s", Bytecodes::name(java_code_at_bci(bci)));
554
}
555
556
void ciMethod::assert_call_type_ok(int bci) {
557
assert(java_code_at_bci(bci) == Bytecodes::_invokestatic ||
558
java_code_at_bci(bci) == Bytecodes::_invokespecial ||
559
java_code_at_bci(bci) == Bytecodes::_invokedynamic, "unexpected bytecode %s", Bytecodes::name(java_code_at_bci(bci)));
560
}
561
562
/**
563
* Check whether profiling provides a type for the argument i to the
564
* call at bci bci
565
*
566
* @param [in]bci bci of the call
567
* @param [in]i argument number
568
* @param [out]type profiled type of argument, NULL if none
569
* @param [out]ptr_kind whether always null, never null or maybe null
570
* @return true if profiling exists
571
*
572
*/
573
bool ciMethod::argument_profiled_type(int bci, int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
574
if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) {
575
ciProfileData* data = method_data()->bci_to_data(bci);
576
if (data != NULL) {
577
if (data->is_VirtualCallTypeData()) {
578
assert_virtual_call_type_ok(bci);
579
ciVirtualCallTypeData* call = (ciVirtualCallTypeData*)data->as_VirtualCallTypeData();
580
if (i >= call->number_of_arguments()) {
581
return false;
582
}
583
type = call->valid_argument_type(i);
584
ptr_kind = call->argument_ptr_kind(i);
585
return true;
586
} else if (data->is_CallTypeData()) {
587
assert_call_type_ok(bci);
588
ciCallTypeData* call = (ciCallTypeData*)data->as_CallTypeData();
589
if (i >= call->number_of_arguments()) {
590
return false;
591
}
592
type = call->valid_argument_type(i);
593
ptr_kind = call->argument_ptr_kind(i);
594
return true;
595
}
596
}
597
}
598
return false;
599
}
600
601
/**
602
* Check whether profiling provides a type for the return value from
603
* the call at bci bci
604
*
605
* @param [in]bci bci of the call
606
* @param [out]type profiled type of argument, NULL if none
607
* @param [out]ptr_kind whether always null, never null or maybe null
608
* @return true if profiling exists
609
*
610
*/
611
bool ciMethod::return_profiled_type(int bci, ciKlass*& type, ProfilePtrKind& ptr_kind) {
612
if (MethodData::profile_return() && method_data() != NULL && method_data()->is_mature()) {
613
ciProfileData* data = method_data()->bci_to_data(bci);
614
if (data != NULL) {
615
if (data->is_VirtualCallTypeData()) {
616
assert_virtual_call_type_ok(bci);
617
ciVirtualCallTypeData* call = (ciVirtualCallTypeData*)data->as_VirtualCallTypeData();
618
if (call->has_return()) {
619
type = call->valid_return_type();
620
ptr_kind = call->return_ptr_kind();
621
return true;
622
}
623
} else if (data->is_CallTypeData()) {
624
assert_call_type_ok(bci);
625
ciCallTypeData* call = (ciCallTypeData*)data->as_CallTypeData();
626
if (call->has_return()) {
627
type = call->valid_return_type();
628
ptr_kind = call->return_ptr_kind();
629
}
630
return true;
631
}
632
}
633
}
634
return false;
635
}
636
637
/**
638
* Check whether profiling provides a type for the parameter i
639
*
640
* @param [in]i parameter number
641
* @param [out]type profiled type of parameter, NULL if none
642
* @param [out]ptr_kind whether always null, never null or maybe null
643
* @return true if profiling exists
644
*
645
*/
646
bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
647
if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) {
648
ciParametersTypeData* parameters = method_data()->parameters_type_data();
649
if (parameters != NULL && i < parameters->number_of_parameters()) {
650
type = parameters->valid_parameter_type(i);
651
ptr_kind = parameters->parameter_ptr_kind(i);
652
return true;
653
}
654
}
655
return false;
656
}
657
658
659
// ------------------------------------------------------------------
660
// ciMethod::find_monomorphic_target
661
//
662
// Given a certain calling environment, find the monomorphic target
663
// for the call. Return NULL if the call is not monomorphic in
664
// its calling environment, or if there are only abstract methods.
665
// The returned method is never abstract.
666
// Note: If caller uses a non-null result, it must inform dependencies
667
// via assert_unique_concrete_method or assert_leaf_type.
668
ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
669
ciInstanceKlass* callee_holder,
670
ciInstanceKlass* actual_recv,
671
bool check_access) {
672
check_is_loaded();
673
674
if (actual_recv->is_interface()) {
675
// %%% We cannot trust interface types, yet. See bug 6312651.
676
return NULL;
677
}
678
679
ciMethod* root_m = resolve_invoke(caller, actual_recv, check_access, true /* allow_abstract */);
680
if (root_m == NULL) {
681
// Something went wrong looking up the actual receiver method.
682
return NULL;
683
}
684
685
// Make certain quick checks even if UseCHA is false.
686
687
// Is it private or final?
688
if (root_m->can_be_statically_bound()) {
689
assert(!root_m->is_abstract(), "sanity");
690
return root_m;
691
}
692
693
if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) {
694
// Easy case. There is no other place to put a method, so don't bother
695
// to go through the VM_ENTRY_MARK and all the rest.
696
if (root_m->is_abstract()) {
697
return NULL;
698
}
699
return root_m;
700
}
701
702
// Array methods (clone, hashCode, etc.) are always statically bound.
703
// If we were to see an array type here, we'd return root_m.
704
// However, this method processes only ciInstanceKlasses. (See 4962591.)
705
// The inline_native_clone intrinsic narrows Object to T[] properly,
706
// so there is no need to do the same job here.
707
708
if (!UseCHA) return NULL;
709
710
VM_ENTRY_MARK;
711
712
methodHandle target;
713
{
714
MutexLocker locker(Compile_lock);
715
InstanceKlass* context = actual_recv->get_instanceKlass();
716
if (UseVtableBasedCHA) {
717
target = methodHandle(THREAD, Dependencies::find_unique_concrete_method(context,
718
root_m->get_Method(),
719
callee_holder->get_Klass(),
720
this->get_Method()));
721
} else {
722
if (root_m->is_abstract()) {
723
return NULL; // not supported
724
}
725
target = methodHandle(THREAD, Dependencies::find_unique_concrete_method(context, root_m->get_Method()));
726
}
727
assert(target() == NULL || !target()->is_abstract(), "not allowed");
728
// %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods.
729
}
730
731
#ifndef PRODUCT
732
if (TraceDependencies && target() != NULL && target() != root_m->get_Method()) {
733
tty->print("found a non-root unique target method");
734
tty->print_cr(" context = %s", actual_recv->get_Klass()->external_name());
735
tty->print(" method = ");
736
target->print_short_name(tty);
737
tty->cr();
738
}
739
#endif //PRODUCT
740
741
if (target() == NULL) {
742
return NULL;
743
}
744
if (target() == root_m->get_Method()) {
745
return root_m;
746
}
747
if (!root_m->is_public() &&
748
!root_m->is_protected()) {
749
// If we are going to reason about inheritance, it's easiest
750
// if the method in question is public, protected, or private.
751
// If the answer is not root_m, it is conservatively correct
752
// to return NULL, even if the CHA encountered irrelevant
753
// methods in other packages.
754
// %%% TO DO: Work out logic for package-private methods
755
// with the same name but different vtable indexes.
756
return NULL;
757
}
758
return CURRENT_THREAD_ENV->get_method(target());
759
}
760
761
// ------------------------------------------------------------------
762
// ciMethod::can_be_statically_bound
763
//
764
// Tries to determine whether a method can be statically bound in some context.
765
bool ciMethod::can_be_statically_bound(ciInstanceKlass* context) const {
766
return (holder() == context) && can_be_statically_bound();
767
}
768
769
// ------------------------------------------------------------------
770
// ciMethod::resolve_invoke
771
//
772
// Given a known receiver klass, find the target for the call.
773
// Return NULL if the call has no target or the target is abstract.
774
ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access, bool allow_abstract) {
775
check_is_loaded();
776
VM_ENTRY_MARK;
777
778
Klass* caller_klass = caller->get_Klass();
779
Klass* recv = exact_receiver->get_Klass();
780
Klass* resolved = holder()->get_Klass();
781
Symbol* h_name = name()->get_symbol();
782
Symbol* h_signature = signature()->get_symbol();
783
784
LinkInfo link_info(resolved, h_name, h_signature, caller_klass,
785
check_access ? LinkInfo::AccessCheck::required : LinkInfo::AccessCheck::skip,
786
check_access ? LinkInfo::LoaderConstraintCheck::required : LinkInfo::LoaderConstraintCheck::skip);
787
Method* m = NULL;
788
// Only do exact lookup if receiver klass has been linked. Otherwise,
789
// the vtable has not been setup, and the LinkResolver will fail.
790
if (recv->is_array_klass()
791
||
792
(InstanceKlass::cast(recv)->is_linked() && !exact_receiver->is_interface())) {
793
if (holder()->is_interface()) {
794
m = LinkResolver::resolve_interface_call_or_null(recv, link_info);
795
} else {
796
m = LinkResolver::resolve_virtual_call_or_null(recv, link_info);
797
}
798
}
799
800
if (m == NULL) {
801
// Return NULL only if there was a problem with lookup (uninitialized class, etc.)
802
return NULL;
803
}
804
805
ciMethod* result = this;
806
if (m != get_Method()) {
807
result = CURRENT_THREAD_ENV->get_method(m);
808
}
809
810
if (result->is_abstract() && !allow_abstract) {
811
// Don't return abstract methods because they aren't optimizable or interesting.
812
return NULL;
813
}
814
return result;
815
}
816
817
// ------------------------------------------------------------------
818
// ciMethod::resolve_vtable_index
819
//
820
// Given a known receiver klass, find the vtable index for the call.
821
// Return Method::invalid_vtable_index if the vtable_index is unknown.
822
int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) {
823
check_is_loaded();
824
825
int vtable_index = Method::invalid_vtable_index;
826
// Only do lookup if receiver klass has been linked. Otherwise,
827
// the vtable has not been setup, and the LinkResolver will fail.
828
if (!receiver->is_interface()
829
&& (!receiver->is_instance_klass() ||
830
receiver->as_instance_klass()->is_linked())) {
831
VM_ENTRY_MARK;
832
833
Klass* caller_klass = caller->get_Klass();
834
Klass* recv = receiver->get_Klass();
835
Symbol* h_name = name()->get_symbol();
836
Symbol* h_signature = signature()->get_symbol();
837
838
LinkInfo link_info(recv, h_name, h_signature, caller_klass);
839
vtable_index = LinkResolver::resolve_virtual_vtable_index(recv, link_info);
840
if (vtable_index == Method::nonvirtual_vtable_index) {
841
// A statically bound method. Return "no such index".
842
vtable_index = Method::invalid_vtable_index;
843
}
844
}
845
846
return vtable_index;
847
}
848
849
// ------------------------------------------------------------------
850
// ciMethod::get_field_at_bci
851
ciField* ciMethod::get_field_at_bci(int bci, bool &will_link) {
852
ciBytecodeStream iter(this);
853
iter.reset_to_bci(bci);
854
iter.next();
855
return iter.get_field(will_link);
856
}
857
858
// ------------------------------------------------------------------
859
// ciMethod::get_method_at_bci
860
ciMethod* ciMethod::get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature) {
861
ciBytecodeStream iter(this);
862
iter.reset_to_bci(bci);
863
iter.next();
864
return iter.get_method(will_link, declared_signature);
865
}
866
867
// ------------------------------------------------------------------
868
ciKlass* ciMethod::get_declared_method_holder_at_bci(int bci) {
869
ciBytecodeStream iter(this);
870
iter.reset_to_bci(bci);
871
iter.next();
872
return iter.get_declared_method_holder();
873
}
874
875
// ------------------------------------------------------------------
876
// Adjust a CounterData count to be commensurate with
877
// interpreter_invocation_count. If the MDO exists for
878
// only 25% of the time the method exists, then the
879
// counts in the MDO should be scaled by 4X, so that
880
// they can be usefully and stably compared against the
881
// invocation counts in methods.
882
int ciMethod::scale_count(int count, float prof_factor) {
883
if (count > 0 && method_data() != NULL) {
884
int counter_life;
885
int method_life = interpreter_invocation_count();
886
// In tiered the MDO's life is measured directly, so just use the snapshotted counters
887
counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count());
888
889
// counter_life due to backedge_counter could be > method_life
890
if (counter_life > method_life)
891
counter_life = method_life;
892
if (0 < counter_life && counter_life <= method_life) {
893
count = (int)((double)count * prof_factor * method_life / counter_life + 0.5);
894
count = (count > 0) ? count : 1;
895
}
896
}
897
return count;
898
}
899
900
901
// ------------------------------------------------------------------
902
// ciMethod::is_special_get_caller_class_method
903
//
904
bool ciMethod::is_ignored_by_security_stack_walk() const {
905
check_is_loaded();
906
VM_ENTRY_MARK;
907
return get_Method()->is_ignored_by_security_stack_walk();
908
}
909
910
// ------------------------------------------------------------------
911
// ciMethod::needs_clinit_barrier
912
//
913
bool ciMethod::needs_clinit_barrier() const {
914
check_is_loaded();
915
return is_static() && !holder()->is_initialized();
916
}
917
918
// ------------------------------------------------------------------
919
// invokedynamic support
920
921
// ------------------------------------------------------------------
922
// ciMethod::is_method_handle_intrinsic
923
//
924
// Return true if the method is an instance of the JVM-generated
925
// signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
926
bool ciMethod::is_method_handle_intrinsic() const {
927
vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
928
return (MethodHandles::is_signature_polymorphic(iid) &&
929
MethodHandles::is_signature_polymorphic_intrinsic(iid));
930
}
931
932
// ------------------------------------------------------------------
933
// ciMethod::is_compiled_lambda_form
934
//
935
// Return true if the method is a generated MethodHandle adapter.
936
// These are built by Java code.
937
bool ciMethod::is_compiled_lambda_form() const {
938
vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
939
return iid == vmIntrinsics::_compiledLambdaForm;
940
}
941
942
// ------------------------------------------------------------------
943
// ciMethod::is_object_initializer
944
//
945
bool ciMethod::is_object_initializer() const {
946
return name() == ciSymbols::object_initializer_name();
947
}
948
949
// ------------------------------------------------------------------
950
// ciMethod::has_member_arg
951
//
952
// Return true if the method is a linker intrinsic like _linkToVirtual.
953
// These are built by the JVM.
954
bool ciMethod::has_member_arg() const {
955
vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
956
return (MethodHandles::is_signature_polymorphic(iid) &&
957
MethodHandles::has_member_arg(iid));
958
}
959
960
// ------------------------------------------------------------------
961
// ciMethod::ensure_method_data
962
//
963
// Generate new MethodData* objects at compile time.
964
// Return true if allocation was successful or no MDO is required.
965
bool ciMethod::ensure_method_data(const methodHandle& h_m) {
966
EXCEPTION_CONTEXT;
967
if (is_native() || is_abstract() || h_m()->is_accessor()) {
968
return true;
969
}
970
if (h_m()->method_data() == NULL) {
971
Method::build_interpreter_method_data(h_m, THREAD);
972
if (HAS_PENDING_EXCEPTION) {
973
CLEAR_PENDING_EXCEPTION;
974
}
975
}
976
if (h_m()->method_data() != NULL) {
977
_method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
978
return _method_data->load_data();
979
} else {
980
_method_data = CURRENT_ENV->get_empty_methodData();
981
return false;
982
}
983
}
984
985
// public, retroactive version
986
bool ciMethod::ensure_method_data() {
987
bool result = true;
988
if (_method_data == NULL || _method_data->is_empty()) {
989
GUARDED_VM_ENTRY({
990
methodHandle mh(Thread::current(), get_Method());
991
result = ensure_method_data(mh);
992
});
993
}
994
return result;
995
}
996
997
998
// ------------------------------------------------------------------
999
// ciMethod::method_data
1000
//
1001
ciMethodData* ciMethod::method_data() {
1002
if (_method_data != NULL) {
1003
return _method_data;
1004
}
1005
VM_ENTRY_MARK;
1006
ciEnv* env = CURRENT_ENV;
1007
Thread* my_thread = JavaThread::current();
1008
methodHandle h_m(my_thread, get_Method());
1009
1010
if (h_m()->method_data() != NULL) {
1011
_method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1012
_method_data->load_data();
1013
} else {
1014
_method_data = CURRENT_ENV->get_empty_methodData();
1015
}
1016
return _method_data;
1017
1018
}
1019
1020
// ------------------------------------------------------------------
1021
// ciMethod::method_data_or_null
1022
// Returns a pointer to ciMethodData if MDO exists on the VM side,
1023
// NULL otherwise.
1024
ciMethodData* ciMethod::method_data_or_null() {
1025
ciMethodData *md = method_data();
1026
if (md->is_empty()) {
1027
return NULL;
1028
}
1029
return md;
1030
}
1031
1032
// ------------------------------------------------------------------
1033
// ciMethod::ensure_method_counters
1034
//
1035
MethodCounters* ciMethod::ensure_method_counters() {
1036
check_is_loaded();
1037
VM_ENTRY_MARK;
1038
methodHandle mh(THREAD, get_Method());
1039
MethodCounters* method_counters = mh->get_method_counters(CHECK_NULL);
1040
return method_counters;
1041
}
1042
1043
// ------------------------------------------------------------------
1044
// ciMethod::has_option
1045
//
1046
bool ciMethod::has_option(enum CompileCommand option) {
1047
check_is_loaded();
1048
VM_ENTRY_MARK;
1049
methodHandle mh(THREAD, get_Method());
1050
return CompilerOracle::has_option(mh, option);
1051
}
1052
1053
// ------------------------------------------------------------------
1054
// ciMethod::has_option_value
1055
//
1056
bool ciMethod::has_option_value(enum CompileCommand option, double& value) {
1057
check_is_loaded();
1058
VM_ENTRY_MARK;
1059
methodHandle mh(THREAD, get_Method());
1060
return CompilerOracle::has_option_value(mh, option, value);
1061
}
1062
// ------------------------------------------------------------------
1063
// ciMethod::can_be_compiled
1064
//
1065
// Have previous compilations of this method succeeded?
1066
bool ciMethod::can_be_compiled() {
1067
check_is_loaded();
1068
ciEnv* env = CURRENT_ENV;
1069
if (is_c1_compile(env->comp_level())) {
1070
return _is_c1_compilable;
1071
}
1072
return _is_c2_compilable;
1073
}
1074
1075
// ------------------------------------------------------------------
1076
// ciMethod::has_compiled_code
1077
bool ciMethod::has_compiled_code() {
1078
return instructions_size() > 0;
1079
}
1080
1081
int ciMethod::highest_osr_comp_level() {
1082
check_is_loaded();
1083
VM_ENTRY_MARK;
1084
return get_Method()->highest_osr_comp_level();
1085
}
1086
1087
// ------------------------------------------------------------------
1088
// ciMethod::code_size_for_inlining
1089
//
1090
// Code size for inlining decisions. This method returns a code
1091
// size of 1 for methods which has the ForceInline annotation.
1092
int ciMethod::code_size_for_inlining() {
1093
check_is_loaded();
1094
if (get_Method()->force_inline()) {
1095
return 1;
1096
}
1097
return code_size();
1098
}
1099
1100
// ------------------------------------------------------------------
1101
// ciMethod::instructions_size
1102
//
1103
// This is a rough metric for "fat" methods, compared before inlining
1104
// with InlineSmallCode. The CodeBlob::code_size accessor includes
1105
// junk like exception handler, stubs, and constant table, which are
1106
// not highly relevant to an inlined method. So we use the more
1107
// specific accessor nmethod::insts_size.
1108
int ciMethod::instructions_size() {
1109
if (_instructions_size == -1) {
1110
GUARDED_VM_ENTRY(
1111
CompiledMethod* code = get_Method()->code();
1112
if (code != NULL && (code->comp_level() == CompLevel_full_optimization)) {
1113
_instructions_size = code->insts_end() - code->verified_entry_point();
1114
} else {
1115
_instructions_size = 0;
1116
}
1117
);
1118
}
1119
return _instructions_size;
1120
}
1121
1122
// ------------------------------------------------------------------
1123
// ciMethod::log_nmethod_identity
1124
void ciMethod::log_nmethod_identity(xmlStream* log) {
1125
GUARDED_VM_ENTRY(
1126
CompiledMethod* code = get_Method()->code();
1127
if (code != NULL) {
1128
code->log_identity(log);
1129
}
1130
)
1131
}
1132
1133
// ------------------------------------------------------------------
1134
// ciMethod::is_not_reached
1135
bool ciMethod::is_not_reached(int bci) {
1136
check_is_loaded();
1137
VM_ENTRY_MARK;
1138
return Interpreter::is_not_reached(
1139
methodHandle(THREAD, get_Method()), bci);
1140
}
1141
1142
// ------------------------------------------------------------------
1143
// ciMethod::was_never_executed
1144
bool ciMethod::was_executed_more_than(int times) {
1145
VM_ENTRY_MARK;
1146
return get_Method()->was_executed_more_than(times);
1147
}
1148
1149
// ------------------------------------------------------------------
1150
// ciMethod::has_unloaded_classes_in_signature
1151
bool ciMethod::has_unloaded_classes_in_signature() {
1152
VM_ENTRY_MARK;
1153
{
1154
ExceptionMark em(THREAD);
1155
methodHandle m(THREAD, get_Method());
1156
bool has_unloaded = Method::has_unloaded_classes_in_signature(m, thread);
1157
if( HAS_PENDING_EXCEPTION ) {
1158
CLEAR_PENDING_EXCEPTION;
1159
return true; // Declare that we may have unloaded classes
1160
}
1161
return has_unloaded;
1162
}
1163
}
1164
1165
// ------------------------------------------------------------------
1166
// ciMethod::is_klass_loaded
1167
bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
1168
VM_ENTRY_MARK;
1169
return get_Method()->is_klass_loaded(refinfo_index, must_be_resolved);
1170
}
1171
1172
// ------------------------------------------------------------------
1173
// ciMethod::check_call
1174
bool ciMethod::check_call(int refinfo_index, bool is_static) const {
1175
// This method is used only in C2 from InlineTree::ok_to_inline,
1176
// and is only used under -Xcomp.
1177
// It appears to fail when applied to an invokeinterface call site.
1178
// FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points.
1179
VM_ENTRY_MARK;
1180
{
1181
ExceptionMark em(THREAD);
1182
HandleMark hm(THREAD);
1183
constantPoolHandle pool (THREAD, get_Method()->constants());
1184
Bytecodes::Code code = (is_static ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual);
1185
Method* spec_method = LinkResolver::resolve_method_statically(code, pool, refinfo_index, THREAD);
1186
if (HAS_PENDING_EXCEPTION) {
1187
CLEAR_PENDING_EXCEPTION;
1188
return false;
1189
} else {
1190
return (spec_method->is_static() == is_static);
1191
}
1192
}
1193
return false;
1194
}
1195
1196
// ------------------------------------------------------------------
1197
// ciMethod::profile_aging
1198
//
1199
// Should the method be compiled with an age counter?
1200
bool ciMethod::profile_aging() const {
1201
return UseCodeAging && (!MethodCounters::is_nmethod_hot(nmethod_age()) &&
1202
!MethodCounters::is_nmethod_age_unset(nmethod_age()));
1203
}
1204
// ------------------------------------------------------------------
1205
// ciMethod::print_codes
1206
//
1207
// Print the bytecodes for this method.
1208
void ciMethod::print_codes_on(outputStream* st) {
1209
check_is_loaded();
1210
GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)
1211
}
1212
1213
1214
#define FETCH_FLAG_FROM_VM(flag_accessor) { \
1215
check_is_loaded(); \
1216
VM_ENTRY_MARK; \
1217
return get_Method()->flag_accessor(); \
1218
}
1219
1220
bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); }
1221
bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }
1222
bool ciMethod::is_getter () const { FETCH_FLAG_FROM_VM(is_getter); }
1223
bool ciMethod::is_setter () const { FETCH_FLAG_FROM_VM(is_setter); }
1224
bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
1225
bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); }
1226
bool ciMethod::is_empty () const { FETCH_FLAG_FROM_VM(is_empty_method); }
1227
1228
bool ciMethod::is_boxing_method() const {
1229
if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1230
switch (intrinsic_id()) {
1231
case vmIntrinsics::_Boolean_valueOf:
1232
case vmIntrinsics::_Byte_valueOf:
1233
case vmIntrinsics::_Character_valueOf:
1234
case vmIntrinsics::_Short_valueOf:
1235
case vmIntrinsics::_Integer_valueOf:
1236
case vmIntrinsics::_Long_valueOf:
1237
case vmIntrinsics::_Float_valueOf:
1238
case vmIntrinsics::_Double_valueOf:
1239
return true;
1240
default:
1241
return false;
1242
}
1243
}
1244
return false;
1245
}
1246
1247
bool ciMethod::is_unboxing_method() const {
1248
if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1249
switch (intrinsic_id()) {
1250
case vmIntrinsics::_booleanValue:
1251
case vmIntrinsics::_byteValue:
1252
case vmIntrinsics::_charValue:
1253
case vmIntrinsics::_shortValue:
1254
case vmIntrinsics::_intValue:
1255
case vmIntrinsics::_longValue:
1256
case vmIntrinsics::_floatValue:
1257
case vmIntrinsics::_doubleValue:
1258
return true;
1259
default:
1260
return false;
1261
}
1262
}
1263
return false;
1264
}
1265
1266
bool ciMethod::is_vector_method() const {
1267
return (holder() == ciEnv::current()->vector_VectorSupport_klass()) &&
1268
(intrinsic_id() != vmIntrinsics::_none);
1269
}
1270
1271
BCEscapeAnalyzer *ciMethod::get_bcea() {
1272
#ifdef COMPILER2
1273
if (_bcea == NULL) {
1274
_bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL);
1275
}
1276
return _bcea;
1277
#else // COMPILER2
1278
ShouldNotReachHere();
1279
return NULL;
1280
#endif // COMPILER2
1281
}
1282
1283
ciMethodBlocks *ciMethod::get_method_blocks() {
1284
if (_method_blocks == NULL) {
1285
Arena *arena = CURRENT_ENV->arena();
1286
_method_blocks = new (arena) ciMethodBlocks(arena, this);
1287
}
1288
return _method_blocks;
1289
}
1290
1291
#undef FETCH_FLAG_FROM_VM
1292
1293
void ciMethod::dump_name_as_ascii(outputStream* st) {
1294
Method* method = get_Method();
1295
st->print("%s %s %s",
1296
method->klass_name()->as_quoted_ascii(),
1297
method->name()->as_quoted_ascii(),
1298
method->signature()->as_quoted_ascii());
1299
}
1300
1301
void ciMethod::dump_replay_data(outputStream* st) {
1302
ResourceMark rm;
1303
Method* method = get_Method();
1304
MethodCounters* mcs = method->method_counters();
1305
st->print("ciMethod ");
1306
dump_name_as_ascii(st);
1307
st->print_cr(" %d %d %d %d %d",
1308
mcs == NULL ? 0 : mcs->invocation_counter()->raw_counter(),
1309
mcs == NULL ? 0 : mcs->backedge_counter()->raw_counter(),
1310
interpreter_invocation_count(),
1311
interpreter_throwout_count(),
1312
_instructions_size);
1313
}
1314
1315
// ------------------------------------------------------------------
1316
// ciMethod::print_codes
1317
//
1318
// Print a range of the bytecodes for this method.
1319
void ciMethod::print_codes_on(int from, int to, outputStream* st) {
1320
check_is_loaded();
1321
GUARDED_VM_ENTRY(get_Method()->print_codes_on(from, to, st);)
1322
}
1323
1324
// ------------------------------------------------------------------
1325
// ciMethod::print_name
1326
//
1327
// Print the name of this method, including signature and some flags.
1328
void ciMethod::print_name(outputStream* st) {
1329
check_is_loaded();
1330
GUARDED_VM_ENTRY(get_Method()->print_name(st);)
1331
}
1332
1333
// ------------------------------------------------------------------
1334
// ciMethod::print_short_name
1335
//
1336
// Print the name of this method, without signature.
1337
void ciMethod::print_short_name(outputStream* st) {
1338
if (is_loaded()) {
1339
GUARDED_VM_ENTRY(get_Method()->print_short_name(st););
1340
} else {
1341
// Fall back if method is not loaded.
1342
holder()->print_name_on(st);
1343
st->print("::");
1344
name()->print_symbol_on(st);
1345
if (WizardMode)
1346
signature()->as_symbol()->print_symbol_on(st);
1347
}
1348
}
1349
1350
// ------------------------------------------------------------------
1351
// ciMethod::print_impl
1352
//
1353
// Implementation of the print method.
1354
void ciMethod::print_impl(outputStream* st) {
1355
ciMetadata::print_impl(st);
1356
st->print(" name=");
1357
name()->print_symbol_on(st);
1358
st->print(" holder=");
1359
holder()->print_name_on(st);
1360
st->print(" signature=");
1361
signature()->as_symbol()->print_symbol_on(st);
1362
if (is_loaded()) {
1363
st->print(" loaded=true");
1364
st->print(" arg_size=%d", arg_size());
1365
st->print(" flags=");
1366
flags().print_member_flags(st);
1367
} else {
1368
st->print(" loaded=false");
1369
}
1370
}
1371
1372
// ------------------------------------------------------------------
1373
1374
static BasicType erase_to_word_type(BasicType bt) {
1375
if (is_subword_type(bt)) return T_INT;
1376
if (is_reference_type(bt)) return T_OBJECT;
1377
return bt;
1378
}
1379
1380
static bool basic_types_match(ciType* t1, ciType* t2) {
1381
if (t1 == t2) return true;
1382
return erase_to_word_type(t1->basic_type()) == erase_to_word_type(t2->basic_type());
1383
}
1384
1385
bool ciMethod::is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method) {
1386
bool invoke_through_mh_intrinsic = declared_method->is_method_handle_intrinsic() &&
1387
!resolved_method->is_method_handle_intrinsic();
1388
1389
if (!invoke_through_mh_intrinsic) {
1390
// Method name & descriptor should stay the same.
1391
// Signatures may reference unloaded types and thus they may be not strictly equal.
1392
ciSymbol* declared_signature = declared_method->signature()->as_symbol();
1393
ciSymbol* resolved_signature = resolved_method->signature()->as_symbol();
1394
1395
return (declared_method->name()->equals(resolved_method->name())) &&
1396
(declared_signature->equals(resolved_signature));
1397
}
1398
1399
ciMethod* linker = declared_method;
1400
ciMethod* target = resolved_method;
1401
// Linkers have appendix argument which is not passed to callee.
1402
int has_appendix = MethodHandles::has_member_arg(linker->intrinsic_id()) ? 1 : 0;
1403
if (linker->arg_size() != (target->arg_size() + has_appendix)) {
1404
return false; // argument slot count mismatch
1405
}
1406
1407
ciSignature* linker_sig = linker->signature();
1408
ciSignature* target_sig = target->signature();
1409
1410
if (linker_sig->count() + (linker->is_static() ? 0 : 1) !=
1411
target_sig->count() + (target->is_static() ? 0 : 1) + has_appendix) {
1412
return false; // argument count mismatch
1413
}
1414
1415
int sbase = 0, rbase = 0;
1416
switch (linker->intrinsic_id()) {
1417
case vmIntrinsics::_linkToVirtual:
1418
case vmIntrinsics::_linkToInterface:
1419
case vmIntrinsics::_linkToSpecial: {
1420
if (target->is_static()) {
1421
return false;
1422
}
1423
if (linker_sig->type_at(0)->is_primitive_type()) {
1424
return false; // receiver should be an oop
1425
}
1426
sbase = 1; // skip receiver
1427
break;
1428
}
1429
case vmIntrinsics::_linkToStatic: {
1430
if (!target->is_static()) {
1431
return false;
1432
}
1433
break;
1434
}
1435
case vmIntrinsics::_invokeBasic: {
1436
if (target->is_static()) {
1437
if (target_sig->type_at(0)->is_primitive_type()) {
1438
return false; // receiver should be an oop
1439
}
1440
rbase = 1; // skip receiver
1441
}
1442
break;
1443
}
1444
default:
1445
break;
1446
}
1447
assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1448
int arg_count = target_sig->count() - rbase;
1449
for (int i = 0; i < arg_count; i++) {
1450
if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1451
return false;
1452
}
1453
}
1454
// Only check the return type if the symbolic info has non-void return type.
1455
// I.e. the return value of the resolved method can be dropped.
1456
if (!linker->return_type()->is_void() &&
1457
!basic_types_match(linker->return_type(), target->return_type())) {
1458
return false;
1459
}
1460
return true; // no mismatch found
1461
}
1462
1463
// ------------------------------------------------------------------
1464
1465