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