Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
40930 views
1
/*
2
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
27
#include "precompiled.hpp"
28
#include "asm/macroAssembler.inline.hpp"
29
#include "gc/shared/barrierSet.hpp"
30
#include "gc/shared/barrierSetAssembler.hpp"
31
#include "interp_masm_ppc.hpp"
32
#include "interpreter/interpreterRuntime.hpp"
33
#include "oops/methodData.hpp"
34
#include "prims/jvmtiExport.hpp"
35
#include "prims/jvmtiThreadState.hpp"
36
#include "runtime/frame.inline.hpp"
37
#include "runtime/safepointMechanism.hpp"
38
#include "runtime/sharedRuntime.hpp"
39
#include "runtime/vm_version.hpp"
40
#include "utilities/powerOfTwo.hpp"
41
42
// Implementation of InterpreterMacroAssembler.
43
44
// This file specializes the assembler with interpreter-specific macros.
45
46
#ifdef PRODUCT
47
#define BLOCK_COMMENT(str) // nothing
48
#else
49
#define BLOCK_COMMENT(str) block_comment(str)
50
#endif
51
52
void InterpreterMacroAssembler::null_check_throw(Register a, int offset, Register temp_reg) {
53
address exception_entry = Interpreter::throw_NullPointerException_entry();
54
MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry);
55
}
56
57
void InterpreterMacroAssembler::jump_to_entry(address entry, Register Rscratch) {
58
assert(entry, "Entry must have been generated by now");
59
if (is_within_range_of_b(entry, pc())) {
60
b(entry);
61
} else {
62
load_const_optimized(Rscratch, entry, R0);
63
mtctr(Rscratch);
64
bctr();
65
}
66
}
67
68
void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) {
69
Register bytecode = R12_scratch2;
70
if (bcp_incr != 0) {
71
lbzu(bytecode, bcp_incr, R14_bcp);
72
} else {
73
lbz(bytecode, 0, R14_bcp);
74
}
75
76
dispatch_Lbyte_code(state, bytecode, Interpreter::dispatch_table(state), generate_poll);
77
}
78
79
void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
80
// Load current bytecode.
81
Register bytecode = R12_scratch2;
82
lbz(bytecode, 0, R14_bcp);
83
dispatch_Lbyte_code(state, bytecode, table);
84
}
85
86
// Dispatch code executed in the prolog of a bytecode which does not do it's
87
// own dispatch. The dispatch address is computed and placed in R24_dispatch_addr.
88
void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) {
89
Register bytecode = R12_scratch2;
90
lbz(bytecode, bcp_incr, R14_bcp);
91
92
load_dispatch_table(R24_dispatch_addr, Interpreter::dispatch_table(state));
93
94
sldi(bytecode, bytecode, LogBytesPerWord);
95
ldx(R24_dispatch_addr, R24_dispatch_addr, bytecode);
96
}
97
98
// Dispatch code executed in the epilog of a bytecode which does not do it's
99
// own dispatch. The dispatch address in R24_dispatch_addr is used for the
100
// dispatch.
101
void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) {
102
if (bcp_incr) { addi(R14_bcp, R14_bcp, bcp_incr); }
103
mtctr(R24_dispatch_addr);
104
bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);
105
}
106
107
void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) {
108
assert(scratch_reg != R0, "can't use R0 as scratch_reg here");
109
if (JvmtiExport::can_pop_frame()) {
110
Label L;
111
112
// Check the "pending popframe condition" flag in the current thread.
113
lwz(scratch_reg, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
114
115
// Initiate popframe handling only if it is not already being
116
// processed. If the flag has the popframe_processing bit set, it
117
// means that this code is called *during* popframe handling - we
118
// don't want to reenter.
119
andi_(R0, scratch_reg, JavaThread::popframe_pending_bit);
120
beq(CCR0, L);
121
122
andi_(R0, scratch_reg, JavaThread::popframe_processing_bit);
123
bne(CCR0, L);
124
125
// Call the Interpreter::remove_activation_preserving_args_entry()
126
// func to get the address of the same-named entrypoint in the
127
// generated interpreter code.
128
#if defined(ABI_ELFv2)
129
call_c(CAST_FROM_FN_PTR(address,
130
Interpreter::remove_activation_preserving_args_entry),
131
relocInfo::none);
132
#else
133
call_c(CAST_FROM_FN_PTR(FunctionDescriptor*,
134
Interpreter::remove_activation_preserving_args_entry),
135
relocInfo::none);
136
#endif
137
138
// Jump to Interpreter::_remove_activation_preserving_args_entry.
139
mtctr(R3_RET);
140
bctr();
141
142
align(32, 12);
143
bind(L);
144
}
145
}
146
147
void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) {
148
const Register Rthr_state_addr = scratch_reg;
149
if (JvmtiExport::can_force_early_return()) {
150
Label Lno_early_ret;
151
ld(Rthr_state_addr, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
152
cmpdi(CCR0, Rthr_state_addr, 0);
153
beq(CCR0, Lno_early_ret);
154
155
lwz(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rthr_state_addr);
156
cmpwi(CCR0, R0, JvmtiThreadState::earlyret_pending);
157
bne(CCR0, Lno_early_ret);
158
159
// Jump to Interpreter::_earlyret_entry.
160
lwz(R3_ARG1, in_bytes(JvmtiThreadState::earlyret_tos_offset()), Rthr_state_addr);
161
call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry));
162
mtlr(R3_RET);
163
blr();
164
165
align(32, 12);
166
bind(Lno_early_ret);
167
}
168
}
169
170
void InterpreterMacroAssembler::load_earlyret_value(TosState state, Register Rscratch1) {
171
const Register RjvmtiState = Rscratch1;
172
const Register Rscratch2 = R0;
173
174
ld(RjvmtiState, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
175
li(Rscratch2, 0);
176
177
switch (state) {
178
case atos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
179
std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
180
break;
181
case ltos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
182
break;
183
case btos: // fall through
184
case ztos: // fall through
185
case ctos: // fall through
186
case stos: // fall through
187
case itos: lwz(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
188
break;
189
case ftos: lfs(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
190
break;
191
case dtos: lfd(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
192
break;
193
case vtos: break;
194
default : ShouldNotReachHere();
195
}
196
197
// Clean up tos value in the jvmti thread state.
198
std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
199
// Set tos state field to illegal value.
200
li(Rscratch2, ilgl);
201
stw(Rscratch2, in_bytes(JvmtiThreadState::earlyret_tos_offset()), RjvmtiState);
202
}
203
204
// Common code to dispatch and dispatch_only.
205
// Dispatch value in Lbyte_code and increment Lbcp.
206
207
void InterpreterMacroAssembler::load_dispatch_table(Register dst, address* table) {
208
address table_base = (address)Interpreter::dispatch_table((TosState)0);
209
intptr_t table_offs = (intptr_t)table - (intptr_t)table_base;
210
if (is_simm16(table_offs)) {
211
addi(dst, R25_templateTableBase, (int)table_offs);
212
} else {
213
load_const_optimized(dst, table, R0);
214
}
215
}
216
217
void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register bytecode,
218
address* table, bool generate_poll) {
219
assert_different_registers(bytecode, R11_scratch1);
220
221
// Calc dispatch table address.
222
load_dispatch_table(R11_scratch1, table);
223
224
if (generate_poll) {
225
address *sfpt_tbl = Interpreter::safept_table(state);
226
if (table != sfpt_tbl) {
227
Label dispatch;
228
ld(R0, in_bytes(JavaThread::polling_word_offset()), R16_thread);
229
// Armed page has poll_bit set, if poll bit is cleared just continue.
230
andi_(R0, R0, SafepointMechanism::poll_bit());
231
beq(CCR0, dispatch);
232
load_dispatch_table(R11_scratch1, sfpt_tbl);
233
align(32, 16);
234
bind(dispatch);
235
}
236
}
237
238
sldi(R12_scratch2, bytecode, LogBytesPerWord);
239
ldx(R11_scratch1, R11_scratch1, R12_scratch2);
240
241
// Jump off!
242
mtctr(R11_scratch1);
243
bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);
244
}
245
246
void InterpreterMacroAssembler::load_receiver(Register Rparam_count, Register Rrecv_dst) {
247
sldi(Rrecv_dst, Rparam_count, Interpreter::logStackElementSize);
248
ldx(Rrecv_dst, Rrecv_dst, R15_esp);
249
}
250
251
// helpers for expression stack
252
253
void InterpreterMacroAssembler::pop_i(Register r) {
254
lwzu(r, Interpreter::stackElementSize, R15_esp);
255
}
256
257
void InterpreterMacroAssembler::pop_ptr(Register r) {
258
ldu(r, Interpreter::stackElementSize, R15_esp);
259
}
260
261
void InterpreterMacroAssembler::pop_l(Register r) {
262
ld(r, Interpreter::stackElementSize, R15_esp);
263
addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
264
}
265
266
void InterpreterMacroAssembler::pop_f(FloatRegister f) {
267
lfsu(f, Interpreter::stackElementSize, R15_esp);
268
}
269
270
void InterpreterMacroAssembler::pop_d(FloatRegister f) {
271
lfd(f, Interpreter::stackElementSize, R15_esp);
272
addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
273
}
274
275
void InterpreterMacroAssembler::push_i(Register r) {
276
stw(r, 0, R15_esp);
277
addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
278
}
279
280
void InterpreterMacroAssembler::push_ptr(Register r) {
281
std(r, 0, R15_esp);
282
addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
283
}
284
285
void InterpreterMacroAssembler::push_l(Register r) {
286
// Clear unused slot.
287
load_const_optimized(R0, 0L);
288
std(R0, 0, R15_esp);
289
std(r, - Interpreter::stackElementSize, R15_esp);
290
addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
291
}
292
293
void InterpreterMacroAssembler::push_f(FloatRegister f) {
294
stfs(f, 0, R15_esp);
295
addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
296
}
297
298
void InterpreterMacroAssembler::push_d(FloatRegister f) {
299
stfd(f, - Interpreter::stackElementSize, R15_esp);
300
addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
301
}
302
303
void InterpreterMacroAssembler::push_2ptrs(Register first, Register second) {
304
std(first, 0, R15_esp);
305
std(second, -Interpreter::stackElementSize, R15_esp);
306
addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
307
}
308
309
void InterpreterMacroAssembler::move_l_to_d(Register l, FloatRegister d) {
310
if (VM_Version::has_mtfprd()) {
311
mtfprd(d, l);
312
} else {
313
std(l, 0, R15_esp);
314
lfd(d, 0, R15_esp);
315
}
316
}
317
318
void InterpreterMacroAssembler::move_d_to_l(FloatRegister d, Register l) {
319
if (VM_Version::has_mtfprd()) {
320
mffprd(l, d);
321
} else {
322
stfd(d, 0, R15_esp);
323
ld(l, 0, R15_esp);
324
}
325
}
326
327
void InterpreterMacroAssembler::push(TosState state) {
328
switch (state) {
329
case atos: push_ptr(); break;
330
case btos:
331
case ztos:
332
case ctos:
333
case stos:
334
case itos: push_i(); break;
335
case ltos: push_l(); break;
336
case ftos: push_f(); break;
337
case dtos: push_d(); break;
338
case vtos: /* nothing to do */ break;
339
default : ShouldNotReachHere();
340
}
341
}
342
343
void InterpreterMacroAssembler::pop(TosState state) {
344
switch (state) {
345
case atos: pop_ptr(); break;
346
case btos:
347
case ztos:
348
case ctos:
349
case stos:
350
case itos: pop_i(); break;
351
case ltos: pop_l(); break;
352
case ftos: pop_f(); break;
353
case dtos: pop_d(); break;
354
case vtos: /* nothing to do */ break;
355
default : ShouldNotReachHere();
356
}
357
verify_oop(R17_tos, state);
358
}
359
360
void InterpreterMacroAssembler::empty_expression_stack() {
361
addi(R15_esp, R26_monitor, - Interpreter::stackElementSize);
362
}
363
364
void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(int bcp_offset,
365
Register Rdst,
366
signedOrNot is_signed) {
367
#if defined(VM_LITTLE_ENDIAN)
368
if (bcp_offset) {
369
load_const_optimized(Rdst, bcp_offset);
370
lhbrx(Rdst, R14_bcp, Rdst);
371
} else {
372
lhbrx(Rdst, R14_bcp);
373
}
374
if (is_signed == Signed) {
375
extsh(Rdst, Rdst);
376
}
377
#else
378
// Read Java big endian format.
379
if (is_signed == Signed) {
380
lha(Rdst, bcp_offset, R14_bcp);
381
} else {
382
lhz(Rdst, bcp_offset, R14_bcp);
383
}
384
#endif
385
}
386
387
void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(int bcp_offset,
388
Register Rdst,
389
signedOrNot is_signed) {
390
#if defined(VM_LITTLE_ENDIAN)
391
if (bcp_offset) {
392
load_const_optimized(Rdst, bcp_offset);
393
lwbrx(Rdst, R14_bcp, Rdst);
394
} else {
395
lwbrx(Rdst, R14_bcp);
396
}
397
if (is_signed == Signed) {
398
extsw(Rdst, Rdst);
399
}
400
#else
401
// Read Java big endian format.
402
if (bcp_offset & 3) { // Offset unaligned?
403
load_const_optimized(Rdst, bcp_offset);
404
if (is_signed == Signed) {
405
lwax(Rdst, R14_bcp, Rdst);
406
} else {
407
lwzx(Rdst, R14_bcp, Rdst);
408
}
409
} else {
410
if (is_signed == Signed) {
411
lwa(Rdst, bcp_offset, R14_bcp);
412
} else {
413
lwz(Rdst, bcp_offset, R14_bcp);
414
}
415
}
416
#endif
417
}
418
419
420
// Load the constant pool cache index from the bytecode stream.
421
//
422
// Kills / writes:
423
// - Rdst, Rscratch
424
void InterpreterMacroAssembler::get_cache_index_at_bcp(Register Rdst, int bcp_offset,
425
size_t index_size) {
426
assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
427
// Cache index is always in the native format, courtesy of Rewriter.
428
if (index_size == sizeof(u2)) {
429
lhz(Rdst, bcp_offset, R14_bcp);
430
} else if (index_size == sizeof(u4)) {
431
if (bcp_offset & 3) {
432
load_const_optimized(Rdst, bcp_offset);
433
lwax(Rdst, R14_bcp, Rdst);
434
} else {
435
lwa(Rdst, bcp_offset, R14_bcp);
436
}
437
assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
438
nand(Rdst, Rdst, Rdst); // convert to plain index
439
} else if (index_size == sizeof(u1)) {
440
lbz(Rdst, bcp_offset, R14_bcp);
441
} else {
442
ShouldNotReachHere();
443
}
444
// Rdst now contains cp cache index.
445
}
446
447
void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, int bcp_offset,
448
size_t index_size) {
449
get_cache_index_at_bcp(cache, bcp_offset, index_size);
450
sldi(cache, cache, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord));
451
add(cache, R27_constPoolCache, cache);
452
}
453
454
// Load 4-byte signed or unsigned integer in Java format (that is, big-endian format)
455
// from (Rsrc)+offset.
456
void InterpreterMacroAssembler::get_u4(Register Rdst, Register Rsrc, int offset,
457
signedOrNot is_signed) {
458
#if defined(VM_LITTLE_ENDIAN)
459
if (offset) {
460
load_const_optimized(Rdst, offset);
461
lwbrx(Rdst, Rdst, Rsrc);
462
} else {
463
lwbrx(Rdst, Rsrc);
464
}
465
if (is_signed == Signed) {
466
extsw(Rdst, Rdst);
467
}
468
#else
469
if (is_signed == Signed) {
470
lwa(Rdst, offset, Rsrc);
471
} else {
472
lwz(Rdst, offset, Rsrc);
473
}
474
#endif
475
}
476
477
// Load object from cpool->resolved_references(index).
478
// Kills:
479
// - index
480
void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index,
481
Register tmp1, Register tmp2,
482
Label *L_handle_null) {
483
assert_different_registers(result, index, tmp1, tmp2);
484
assert(index->is_nonvolatile(), "needs to survive C-call in resolve_oop_handle");
485
get_constant_pool(result);
486
487
// Convert from field index to resolved_references() index and from
488
// word index to byte offset. Since this is a java object, it can be compressed.
489
sldi(index, index, LogBytesPerHeapOop);
490
// Load pointer for resolved_references[] objArray.
491
ld(result, ConstantPool::cache_offset_in_bytes(), result);
492
ld(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
493
resolve_oop_handle(result, tmp1, tmp2, MacroAssembler::PRESERVATION_NONE);
494
#ifdef ASSERT
495
Label index_ok;
496
lwa(R0, arrayOopDesc::length_offset_in_bytes(), result);
497
sldi(R0, R0, LogBytesPerHeapOop);
498
cmpd(CCR0, index, R0);
499
blt(CCR0, index_ok);
500
stop("resolved reference index out of bounds");
501
bind(index_ok);
502
#endif
503
// Add in the index.
504
add(result, index, result);
505
load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result,
506
tmp1, tmp2,
507
MacroAssembler::PRESERVATION_NONE,
508
0, L_handle_null);
509
}
510
511
// load cpool->resolved_klass_at(index)
512
void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register Rcpool, Register Roffset, Register Rklass) {
513
// int value = *(Rcpool->int_at_addr(which));
514
// int resolved_klass_index = extract_low_short_from_int(value);
515
add(Roffset, Rcpool, Roffset);
516
#if defined(VM_LITTLE_ENDIAN)
517
lhz(Roffset, sizeof(ConstantPool), Roffset); // Roffset = resolved_klass_index
518
#else
519
lhz(Roffset, sizeof(ConstantPool) + 2, Roffset); // Roffset = resolved_klass_index
520
#endif
521
522
ld(Rklass, ConstantPool::resolved_klasses_offset_in_bytes(), Rcpool); // Rklass = Rcpool->_resolved_klasses
523
524
sldi(Roffset, Roffset, LogBytesPerWord);
525
addi(Roffset, Roffset, Array<Klass*>::base_offset_in_bytes());
526
isync(); // Order load of instance Klass wrt. tags.
527
ldx(Rklass, Rklass, Roffset);
528
}
529
530
void InterpreterMacroAssembler::load_resolved_method_at_index(int byte_no,
531
Register cache,
532
Register method) {
533
const int method_offset = in_bytes(
534
ConstantPoolCache::base_offset() +
535
((byte_no == TemplateTable::f2_byte)
536
? ConstantPoolCacheEntry::f2_offset()
537
: ConstantPoolCacheEntry::f1_offset()));
538
539
ld(method, method_offset, cache); // get f1 Method*
540
}
541
542
// Generate a subtype check: branch to ok_is_subtype if sub_klass is
543
// a subtype of super_klass. Blows registers Rsub_klass, tmp1, tmp2.
544
void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, Register Rsuper_klass, Register Rtmp1,
545
Register Rtmp2, Register Rtmp3, Label &ok_is_subtype) {
546
// Profile the not-null value's klass.
547
profile_typecheck(Rsub_klass, Rtmp1, Rtmp2);
548
check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype);
549
profile_typecheck_failed(Rtmp1, Rtmp2);
550
}
551
552
// Separate these two to allow for delay slot in middle.
553
// These are used to do a test and full jump to exception-throwing code.
554
555
// Check that index is in range for array, then shift index by index_shift,
556
// and put arrayOop + shifted_index into res.
557
// Note: res is still shy of address by array offset into object.
558
559
void InterpreterMacroAssembler::index_check_without_pop(Register Rarray, Register Rindex,
560
int index_shift, Register Rtmp, Register Rres) {
561
// Check that index is in range for array, then shift index by index_shift,
562
// and put arrayOop + shifted_index into res.
563
// Note: res is still shy of address by array offset into object.
564
// Kills:
565
// - Rindex
566
// Writes:
567
// - Rres: Address that corresponds to the array index if check was successful.
568
verify_oop(Rarray);
569
const Register Rlength = R0;
570
const Register RsxtIndex = Rtmp;
571
Label LisNull, LnotOOR;
572
573
// Array nullcheck
574
if (!ImplicitNullChecks) {
575
cmpdi(CCR0, Rarray, 0);
576
beq(CCR0, LisNull);
577
} else {
578
null_check_throw(Rarray, arrayOopDesc::length_offset_in_bytes(), /*temp*/RsxtIndex);
579
}
580
581
// Rindex might contain garbage in upper bits (remember that we don't sign extend
582
// during integer arithmetic operations). So kill them and put value into same register
583
// where ArrayIndexOutOfBounds would expect the index in.
584
rldicl(RsxtIndex, Rindex, 0, 32); // zero extend 32 bit -> 64 bit
585
586
// Index check
587
lwz(Rlength, arrayOopDesc::length_offset_in_bytes(), Rarray);
588
cmplw(CCR0, Rindex, Rlength);
589
sldi(RsxtIndex, RsxtIndex, index_shift);
590
blt(CCR0, LnotOOR);
591
// Index should be in R17_tos, array should be in R4_ARG2.
592
mr_if_needed(R17_tos, Rindex);
593
mr_if_needed(R4_ARG2, Rarray);
594
load_dispatch_table(Rtmp, (address*)Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
595
mtctr(Rtmp);
596
bctr();
597
598
if (!ImplicitNullChecks) {
599
bind(LisNull);
600
load_dispatch_table(Rtmp, (address*)Interpreter::_throw_NullPointerException_entry);
601
mtctr(Rtmp);
602
bctr();
603
}
604
605
align(32, 16);
606
bind(LnotOOR);
607
608
// Calc address
609
add(Rres, RsxtIndex, Rarray);
610
}
611
612
void InterpreterMacroAssembler::index_check(Register array, Register index,
613
int index_shift, Register tmp, Register res) {
614
// pop array
615
pop_ptr(array);
616
617
// check array
618
index_check_without_pop(array, index, index_shift, tmp, res);
619
}
620
621
void InterpreterMacroAssembler::get_const(Register Rdst) {
622
ld(Rdst, in_bytes(Method::const_offset()), R19_method);
623
}
624
625
void InterpreterMacroAssembler::get_constant_pool(Register Rdst) {
626
get_const(Rdst);
627
ld(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst);
628
}
629
630
void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) {
631
get_constant_pool(Rdst);
632
ld(Rdst, ConstantPool::cache_offset_in_bytes(), Rdst);
633
}
634
635
void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) {
636
get_constant_pool(Rcpool);
637
ld(Rtags, ConstantPool::tags_offset_in_bytes(), Rcpool);
638
}
639
640
// Unlock if synchronized method.
641
//
642
// Unlock the receiver if this is a synchronized method.
643
// Unlock any Java monitors from synchronized blocks.
644
//
645
// If there are locked Java monitors
646
// If throw_monitor_exception
647
// throws IllegalMonitorStateException
648
// Else if install_monitor_exception
649
// installs IllegalMonitorStateException
650
// Else
651
// no error processing
652
void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,
653
bool throw_monitor_exception,
654
bool install_monitor_exception) {
655
Label Lunlocked, Lno_unlock;
656
{
657
Register Rdo_not_unlock_flag = R11_scratch1;
658
Register Raccess_flags = R12_scratch2;
659
660
// Check if synchronized method or unlocking prevented by
661
// JavaThread::do_not_unlock_if_synchronized flag.
662
lbz(Rdo_not_unlock_flag, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
663
lwz(Raccess_flags, in_bytes(Method::access_flags_offset()), R19_method);
664
li(R0, 0);
665
stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); // reset flag
666
667
push(state);
668
669
// Skip if we don't have to unlock.
670
rldicl_(R0, Raccess_flags, 64-JVM_ACC_SYNCHRONIZED_BIT, 63); // Extract bit and compare to 0.
671
beq(CCR0, Lunlocked);
672
673
cmpwi(CCR0, Rdo_not_unlock_flag, 0);
674
bne(CCR0, Lno_unlock);
675
}
676
677
// Unlock
678
{
679
Register Rmonitor_base = R11_scratch1;
680
681
Label Lunlock;
682
// If it's still locked, everything is ok, unlock it.
683
ld(Rmonitor_base, 0, R1_SP);
684
addi(Rmonitor_base, Rmonitor_base,
685
-(frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base
686
687
ld(R0, BasicObjectLock::obj_offset_in_bytes(), Rmonitor_base);
688
cmpdi(CCR0, R0, 0);
689
bne(CCR0, Lunlock);
690
691
// If it's already unlocked, throw exception.
692
if (throw_monitor_exception) {
693
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
694
should_not_reach_here();
695
} else {
696
if (install_monitor_exception) {
697
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
698
b(Lunlocked);
699
}
700
}
701
702
bind(Lunlock);
703
unlock_object(Rmonitor_base);
704
}
705
706
// Check that all other monitors are unlocked. Throw IllegelMonitorState exception if not.
707
bind(Lunlocked);
708
{
709
Label Lexception, Lrestart;
710
Register Rcurrent_obj_addr = R11_scratch1;
711
const int delta = frame::interpreter_frame_monitor_size_in_bytes();
712
assert((delta & LongAlignmentMask) == 0, "sizeof BasicObjectLock must be even number of doublewords");
713
714
bind(Lrestart);
715
// Set up search loop: Calc num of iterations.
716
{
717
Register Riterations = R12_scratch2;
718
Register Rmonitor_base = Rcurrent_obj_addr;
719
ld(Rmonitor_base, 0, R1_SP);
720
addi(Rmonitor_base, Rmonitor_base, - frame::ijava_state_size); // Monitor base
721
722
subf_(Riterations, R26_monitor, Rmonitor_base);
723
ble(CCR0, Lno_unlock);
724
725
addi(Rcurrent_obj_addr, Rmonitor_base,
726
BasicObjectLock::obj_offset_in_bytes() - frame::interpreter_frame_monitor_size_in_bytes());
727
// Check if any monitor is on stack, bail out if not
728
srdi(Riterations, Riterations, exact_log2(delta));
729
mtctr(Riterations);
730
}
731
732
// The search loop: Look for locked monitors.
733
{
734
const Register Rcurrent_obj = R0;
735
Label Lloop;
736
737
ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
738
addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
739
bind(Lloop);
740
741
// Check if current entry is used.
742
cmpdi(CCR0, Rcurrent_obj, 0);
743
bne(CCR0, Lexception);
744
// Preload next iteration's compare value.
745
ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
746
addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
747
bdnz(Lloop);
748
}
749
// Fell through: Everything's unlocked => finish.
750
b(Lno_unlock);
751
752
// An object is still locked => need to throw exception.
753
bind(Lexception);
754
if (throw_monitor_exception) {
755
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
756
should_not_reach_here();
757
} else {
758
// Stack unrolling. Unlock object and if requested, install illegal_monitor_exception.
759
// Unlock does not block, so don't have to worry about the frame.
760
Register Rmonitor_addr = R11_scratch1;
761
addi(Rmonitor_addr, Rcurrent_obj_addr, -BasicObjectLock::obj_offset_in_bytes() + delta);
762
unlock_object(Rmonitor_addr);
763
if (install_monitor_exception) {
764
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
765
}
766
b(Lrestart);
767
}
768
}
769
770
align(32, 12);
771
bind(Lno_unlock);
772
pop(state);
773
}
774
775
// Support function for remove_activation & Co.
776
void InterpreterMacroAssembler::merge_frames(Register Rsender_sp, Register return_pc,
777
Register Rscratch1, Register Rscratch2) {
778
// Pop interpreter frame.
779
ld(Rscratch1, 0, R1_SP); // *SP
780
ld(Rsender_sp, _ijava_state_neg(sender_sp), Rscratch1); // top_frame_sp
781
ld(Rscratch2, 0, Rscratch1); // **SP
782
if (return_pc!=noreg) {
783
ld(return_pc, _abi0(lr), Rscratch1); // LR
784
}
785
786
// Merge top frames.
787
subf(Rscratch1, R1_SP, Rsender_sp); // top_frame_sp - SP
788
stdux(Rscratch2, R1_SP, Rscratch1); // atomically set *(SP = top_frame_sp) = **SP
789
}
790
791
void InterpreterMacroAssembler::narrow(Register result) {
792
Register ret_type = R11_scratch1;
793
ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
794
lbz(ret_type, in_bytes(ConstMethod::result_type_offset()), R11_scratch1);
795
796
Label notBool, notByte, notChar, done;
797
798
// common case first
799
cmpwi(CCR0, ret_type, T_INT);
800
beq(CCR0, done);
801
802
cmpwi(CCR0, ret_type, T_BOOLEAN);
803
bne(CCR0, notBool);
804
andi(result, result, 0x1);
805
b(done);
806
807
bind(notBool);
808
cmpwi(CCR0, ret_type, T_BYTE);
809
bne(CCR0, notByte);
810
extsb(result, result);
811
b(done);
812
813
bind(notByte);
814
cmpwi(CCR0, ret_type, T_CHAR);
815
bne(CCR0, notChar);
816
andi(result, result, 0xffff);
817
b(done);
818
819
bind(notChar);
820
// cmpwi(CCR0, ret_type, T_SHORT); // all that's left
821
// bne(CCR0, done);
822
extsh(result, result);
823
824
// Nothing to do for T_INT
825
bind(done);
826
}
827
828
// Remove activation.
829
//
830
// Apply stack watermark barrier.
831
// Unlock the receiver if this is a synchronized method.
832
// Unlock any Java monitors from synchronized blocks.
833
// Remove the activation from the stack.
834
//
835
// If there are locked Java monitors
836
// If throw_monitor_exception
837
// throws IllegalMonitorStateException
838
// Else if install_monitor_exception
839
// installs IllegalMonitorStateException
840
// Else
841
// no error processing
842
void InterpreterMacroAssembler::remove_activation(TosState state,
843
bool throw_monitor_exception,
844
bool install_monitor_exception) {
845
BLOCK_COMMENT("remove_activation {");
846
847
// The below poll is for the stack watermark barrier. It allows fixing up frames lazily,
848
// that would normally not be safe to use. Such bad returns into unsafe territory of
849
// the stack, will call InterpreterRuntime::at_unwind.
850
Label slow_path;
851
Label fast_path;
852
safepoint_poll(slow_path, R11_scratch1, true /* at_return */, false /* in_nmethod */);
853
b(fast_path);
854
bind(slow_path);
855
push(state);
856
set_last_Java_frame(R1_SP, noreg);
857
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), R16_thread);
858
reset_last_Java_frame();
859
pop(state);
860
align(32);
861
bind(fast_path);
862
863
unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception);
864
865
// Save result (push state before jvmti call and pop it afterwards) and notify jvmti.
866
notify_method_exit(false, state, NotifyJVMTI, true);
867
868
BLOCK_COMMENT("reserved_stack_check:");
869
if (StackReservedPages > 0) {
870
// Test if reserved zone needs to be enabled.
871
Label no_reserved_zone_enabling;
872
873
// Compare frame pointers. There is no good stack pointer, as with stack
874
// frame compression we can get different SPs when we do calls. A subsequent
875
// call could have a smaller SP, so that this compare succeeds for an
876
// inner call of the method annotated with ReservedStack.
877
ld_ptr(R0, JavaThread::reserved_stack_activation_offset(), R16_thread);
878
ld_ptr(R11_scratch1, _abi0(callers_sp), R1_SP); // Load frame pointer.
879
cmpld(CCR0, R11_scratch1, R0);
880
blt_predict_taken(CCR0, no_reserved_zone_enabling);
881
882
// Enable reserved zone again, throw stack overflow exception.
883
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), R16_thread);
884
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError));
885
886
should_not_reach_here();
887
888
bind(no_reserved_zone_enabling);
889
}
890
891
verify_oop(R17_tos, state);
892
verify_thread();
893
894
merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
895
mtlr(R0);
896
BLOCK_COMMENT("} remove_activation");
897
}
898
899
// Lock object
900
//
901
// Registers alive
902
// monitor - Address of the BasicObjectLock to be used for locking,
903
// which must be initialized with the object to lock.
904
// object - Address of the object to be locked.
905
//
906
void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
907
if (UseHeavyMonitors) {
908
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);
909
} else {
910
// template code:
911
//
912
// markWord displaced_header = obj->mark().set_unlocked();
913
// monitor->lock()->set_displaced_header(displaced_header);
914
// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {
915
// // We stored the monitor address into the object's mark word.
916
// } else if (THREAD->is_lock_owned((address)displaced_header))
917
// // Simple recursive case.
918
// monitor->lock()->set_displaced_header(NULL);
919
// } else {
920
// // Slow path.
921
// InterpreterRuntime::monitorenter(THREAD, monitor);
922
// }
923
924
const Register displaced_header = R7_ARG5;
925
const Register object_mark_addr = R8_ARG6;
926
const Register current_header = R9_ARG7;
927
const Register tmp = R10_ARG8;
928
929
Label done;
930
Label cas_failed, slow_case;
931
932
assert_different_registers(displaced_header, object_mark_addr, current_header, tmp);
933
934
// markWord displaced_header = obj->mark().set_unlocked();
935
936
// Load markWord from object into displaced_header.
937
ld(displaced_header, oopDesc::mark_offset_in_bytes(), object);
938
939
if (DiagnoseSyncOnValueBasedClasses != 0) {
940
load_klass(tmp, object);
941
lwz(tmp, in_bytes(Klass::access_flags_offset()), tmp);
942
testbitdi(CCR0, R0, tmp, exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));
943
bne(CCR0, slow_case);
944
}
945
946
if (UseBiasedLocking) {
947
biased_locking_enter(CCR0, object, displaced_header, tmp, current_header, done, &slow_case);
948
}
949
950
// Set displaced_header to be (markWord of object | UNLOCK_VALUE).
951
ori(displaced_header, displaced_header, markWord::unlocked_value);
952
953
// monitor->lock()->set_displaced_header(displaced_header);
954
955
// Initialize the box (Must happen before we update the object mark!).
956
std(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
957
BasicLock::displaced_header_offset_in_bytes(), monitor);
958
959
// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {
960
961
// Store stack address of the BasicObjectLock (this is monitor) into object.
962
addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
963
964
// Must fence, otherwise, preceding store(s) may float below cmpxchg.
965
// CmpxchgX sets CCR0 to cmpX(current, displaced).
966
cmpxchgd(/*flag=*/CCR0,
967
/*current_value=*/current_header,
968
/*compare_value=*/displaced_header, /*exchange_value=*/monitor,
969
/*where=*/object_mark_addr,
970
MacroAssembler::MemBarRel | MacroAssembler::MemBarAcq,
971
MacroAssembler::cmpxchgx_hint_acquire_lock(),
972
noreg,
973
&cas_failed,
974
/*check without membar and ldarx first*/true);
975
976
// If the compare-and-exchange succeeded, then we found an unlocked
977
// object and we have now locked it.
978
b(done);
979
bind(cas_failed);
980
981
// } else if (THREAD->is_lock_owned((address)displaced_header))
982
// // Simple recursive case.
983
// monitor->lock()->set_displaced_header(NULL);
984
985
// We did not see an unlocked object so try the fast recursive case.
986
987
// Check if owner is self by comparing the value in the markWord of object
988
// (current_header) with the stack pointer.
989
sub(current_header, current_header, R1_SP);
990
991
assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");
992
load_const_optimized(tmp, ~(os::vm_page_size()-1) | markWord::lock_mask_in_place);
993
994
and_(R0/*==0?*/, current_header, tmp);
995
// If condition is true we are done and hence we can store 0 in the displaced
996
// header indicating it is a recursive lock.
997
bne(CCR0, slow_case);
998
std(R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() +
999
BasicLock::displaced_header_offset_in_bytes(), monitor);
1000
b(done);
1001
1002
// } else {
1003
// // Slow path.
1004
// InterpreterRuntime::monitorenter(THREAD, monitor);
1005
1006
// None of the above fast optimizations worked so we have to get into the
1007
// slow case of monitor enter.
1008
bind(slow_case);
1009
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);
1010
// }
1011
align(32, 12);
1012
bind(done);
1013
}
1014
}
1015
1016
// Unlocks an object. Used in monitorexit bytecode and remove_activation.
1017
//
1018
// Registers alive
1019
// monitor - Address of the BasicObjectLock to be used for locking,
1020
// which must be initialized with the object to lock.
1021
//
1022
// Throw IllegalMonitorException if object is not locked by current thread.
1023
void InterpreterMacroAssembler::unlock_object(Register monitor) {
1024
if (UseHeavyMonitors) {
1025
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
1026
} else {
1027
1028
// template code:
1029
//
1030
// if ((displaced_header = monitor->displaced_header()) == NULL) {
1031
// // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.
1032
// monitor->set_obj(NULL);
1033
// } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {
1034
// // We swapped the unlocked mark in displaced_header into the object's mark word.
1035
// monitor->set_obj(NULL);
1036
// } else {
1037
// // Slow path.
1038
// InterpreterRuntime::monitorexit(monitor);
1039
// }
1040
1041
const Register object = R7_ARG5;
1042
const Register displaced_header = R8_ARG6;
1043
const Register object_mark_addr = R9_ARG7;
1044
const Register current_header = R10_ARG8;
1045
1046
Label free_slot;
1047
Label slow_case;
1048
1049
assert_different_registers(object, displaced_header, object_mark_addr, current_header);
1050
1051
if (UseBiasedLocking) {
1052
// The object address from the monitor is in object.
1053
ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor);
1054
assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0");
1055
biased_locking_exit(CCR0, object, displaced_header, free_slot);
1056
}
1057
1058
// Test first if we are in the fast recursive case.
1059
ld(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
1060
BasicLock::displaced_header_offset_in_bytes(), monitor);
1061
1062
// If the displaced header is zero, we have a recursive unlock.
1063
cmpdi(CCR0, displaced_header, 0);
1064
beq(CCR0, free_slot); // recursive unlock
1065
1066
// } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {
1067
// // We swapped the unlocked mark in displaced_header into the object's mark word.
1068
// monitor->set_obj(NULL);
1069
1070
// If we still have a lightweight lock, unlock the object and be done.
1071
1072
// The object address from the monitor is in object.
1073
if (!UseBiasedLocking) { ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor); }
1074
addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
1075
1076
// We have the displaced header in displaced_header. If the lock is still
1077
// lightweight, it will contain the monitor address and we'll store the
1078
// displaced header back into the object's mark word.
1079
// CmpxchgX sets CCR0 to cmpX(current, monitor).
1080
cmpxchgd(/*flag=*/CCR0,
1081
/*current_value=*/current_header,
1082
/*compare_value=*/monitor, /*exchange_value=*/displaced_header,
1083
/*where=*/object_mark_addr,
1084
MacroAssembler::MemBarRel,
1085
MacroAssembler::cmpxchgx_hint_release_lock(),
1086
noreg,
1087
&slow_case);
1088
b(free_slot);
1089
1090
// } else {
1091
// // Slow path.
1092
// InterpreterRuntime::monitorexit(monitor);
1093
1094
// The lock has been converted into a heavy lock and hence
1095
// we need to get into the slow case.
1096
bind(slow_case);
1097
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
1098
// }
1099
1100
Label done;
1101
b(done); // Monitor register may be overwritten! Runtime has already freed the slot.
1102
1103
// Exchange worked, do monitor->set_obj(NULL);
1104
align(32, 12);
1105
bind(free_slot);
1106
li(R0, 0);
1107
std(R0, BasicObjectLock::obj_offset_in_bytes(), monitor);
1108
bind(done);
1109
}
1110
}
1111
1112
// Load compiled (i2c) or interpreter entry when calling from interpreted and
1113
// do the call. Centralized so that all interpreter calls will do the same actions.
1114
// If jvmti single stepping is on for a thread we must not call compiled code.
1115
//
1116
// Input:
1117
// - Rtarget_method: method to call
1118
// - Rret_addr: return address
1119
// - 2 scratch regs
1120
//
1121
void InterpreterMacroAssembler::call_from_interpreter(Register Rtarget_method, Register Rret_addr,
1122
Register Rscratch1, Register Rscratch2) {
1123
assert_different_registers(Rscratch1, Rscratch2, Rtarget_method, Rret_addr);
1124
// Assume we want to go compiled if available.
1125
const Register Rtarget_addr = Rscratch1;
1126
const Register Rinterp_only = Rscratch2;
1127
1128
ld(Rtarget_addr, in_bytes(Method::from_interpreted_offset()), Rtarget_method);
1129
1130
if (JvmtiExport::can_post_interpreter_events()) {
1131
lwz(Rinterp_only, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
1132
1133
// JVMTI events, such as single-stepping, are implemented partly by avoiding running
1134
// compiled code in threads for which the event is enabled. Check here for
1135
// interp_only_mode if these events CAN be enabled.
1136
Label done;
1137
verify_thread();
1138
cmpwi(CCR0, Rinterp_only, 0);
1139
beq(CCR0, done);
1140
ld(Rtarget_addr, in_bytes(Method::interpreter_entry_offset()), Rtarget_method);
1141
align(32, 12);
1142
bind(done);
1143
}
1144
1145
#ifdef ASSERT
1146
{
1147
Label Lok;
1148
cmpdi(CCR0, Rtarget_addr, 0);
1149
bne(CCR0, Lok);
1150
stop("null entry point");
1151
bind(Lok);
1152
}
1153
#endif // ASSERT
1154
1155
mr(R21_sender_SP, R1_SP);
1156
1157
// Calc a precise SP for the call. The SP value we calculated in
1158
// generate_fixed_frame() is based on the max_stack() value, so we would waste stack space
1159
// if esp is not max. Also, the i2c adapter extends the stack space without restoring
1160
// our pre-calced value, so repeating calls via i2c would result in stack overflow.
1161
// Since esp already points to an empty slot, we just have to sub 1 additional slot
1162
// to meet the abi scratch requirements.
1163
// The max_stack pointer will get restored by means of the GR_Lmax_stack local in
1164
// the return entry of the interpreter.
1165
addi(Rscratch2, R15_esp, Interpreter::stackElementSize - frame::abi_reg_args_size);
1166
clrrdi(Rscratch2, Rscratch2, exact_log2(frame::alignment_in_bytes)); // round towards smaller address
1167
resize_frame_absolute(Rscratch2, Rscratch2, R0);
1168
1169
mr_if_needed(R19_method, Rtarget_method);
1170
mtctr(Rtarget_addr);
1171
mtlr(Rret_addr);
1172
1173
save_interpreter_state(Rscratch2);
1174
#ifdef ASSERT
1175
ld(Rscratch1, _ijava_state_neg(top_frame_sp), Rscratch2); // Rscratch2 contains fp
1176
cmpd(CCR0, R21_sender_SP, Rscratch1);
1177
asm_assert_eq("top_frame_sp incorrect");
1178
#endif
1179
1180
bctr();
1181
}
1182
1183
// Set the method data pointer for the current bcp.
1184
void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
1185
assert(ProfileInterpreter, "must be profiling interpreter");
1186
Label get_continue;
1187
ld(R28_mdx, in_bytes(Method::method_data_offset()), R19_method);
1188
test_method_data_pointer(get_continue);
1189
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), R19_method, R14_bcp);
1190
1191
addi(R28_mdx, R28_mdx, in_bytes(MethodData::data_offset()));
1192
add(R28_mdx, R28_mdx, R3_RET);
1193
bind(get_continue);
1194
}
1195
1196
// Test ImethodDataPtr. If it is null, continue at the specified label.
1197
void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) {
1198
assert(ProfileInterpreter, "must be profiling interpreter");
1199
cmpdi(CCR0, R28_mdx, 0);
1200
beq(CCR0, zero_continue);
1201
}
1202
1203
void InterpreterMacroAssembler::verify_method_data_pointer() {
1204
assert(ProfileInterpreter, "must be profiling interpreter");
1205
#ifdef ASSERT
1206
Label verify_continue;
1207
test_method_data_pointer(verify_continue);
1208
1209
// If the mdp is valid, it will point to a DataLayout header which is
1210
// consistent with the bcp. The converse is highly probable also.
1211
lhz(R11_scratch1, in_bytes(DataLayout::bci_offset()), R28_mdx);
1212
ld(R12_scratch2, in_bytes(Method::const_offset()), R19_method);
1213
addi(R11_scratch1, R11_scratch1, in_bytes(ConstMethod::codes_offset()));
1214
add(R11_scratch1, R12_scratch2, R12_scratch2);
1215
cmpd(CCR0, R11_scratch1, R14_bcp);
1216
beq(CCR0, verify_continue);
1217
1218
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp ), R19_method, R14_bcp, R28_mdx);
1219
1220
bind(verify_continue);
1221
#endif
1222
}
1223
1224
// Store a value at some constant offset from the method data pointer.
1225
void InterpreterMacroAssembler::set_mdp_data_at(int constant, Register value) {
1226
assert(ProfileInterpreter, "must be profiling interpreter");
1227
1228
std(value, constant, R28_mdx);
1229
}
1230
1231
// Increment the value at some constant offset from the method data pointer.
1232
void InterpreterMacroAssembler::increment_mdp_data_at(int constant,
1233
Register counter_addr,
1234
Register Rbumped_count,
1235
bool decrement) {
1236
// Locate the counter at a fixed offset from the mdp:
1237
addi(counter_addr, R28_mdx, constant);
1238
increment_mdp_data_at(counter_addr, Rbumped_count, decrement);
1239
}
1240
1241
// Increment the value at some non-fixed (reg + constant) offset from
1242
// the method data pointer.
1243
void InterpreterMacroAssembler::increment_mdp_data_at(Register reg,
1244
int constant,
1245
Register scratch,
1246
Register Rbumped_count,
1247
bool decrement) {
1248
// Add the constant to reg to get the offset.
1249
add(scratch, R28_mdx, reg);
1250
// Then calculate the counter address.
1251
addi(scratch, scratch, constant);
1252
increment_mdp_data_at(scratch, Rbumped_count, decrement);
1253
}
1254
1255
void InterpreterMacroAssembler::increment_mdp_data_at(Register counter_addr,
1256
Register Rbumped_count,
1257
bool decrement) {
1258
assert(ProfileInterpreter, "must be profiling interpreter");
1259
1260
// Load the counter.
1261
ld(Rbumped_count, 0, counter_addr);
1262
1263
if (decrement) {
1264
// Decrement the register. Set condition codes.
1265
addi(Rbumped_count, Rbumped_count, - DataLayout::counter_increment);
1266
// Store the decremented counter, if it is still negative.
1267
std(Rbumped_count, 0, counter_addr);
1268
// Note: add/sub overflow check are not ported, since 64 bit
1269
// calculation should never overflow.
1270
} else {
1271
// Increment the register. Set carry flag.
1272
addi(Rbumped_count, Rbumped_count, DataLayout::counter_increment);
1273
// Store the incremented counter.
1274
std(Rbumped_count, 0, counter_addr);
1275
}
1276
}
1277
1278
// Set a flag value at the current method data pointer position.
1279
void InterpreterMacroAssembler::set_mdp_flag_at(int flag_constant,
1280
Register scratch) {
1281
assert(ProfileInterpreter, "must be profiling interpreter");
1282
// Load the data header.
1283
lbz(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);
1284
// Set the flag.
1285
ori(scratch, scratch, flag_constant);
1286
// Store the modified header.
1287
stb(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);
1288
}
1289
1290
// Test the location at some offset from the method data pointer.
1291
// If it is not equal to value, branch to the not_equal_continue Label.
1292
void InterpreterMacroAssembler::test_mdp_data_at(int offset,
1293
Register value,
1294
Label& not_equal_continue,
1295
Register test_out) {
1296
assert(ProfileInterpreter, "must be profiling interpreter");
1297
1298
ld(test_out, offset, R28_mdx);
1299
cmpd(CCR0, value, test_out);
1300
bne(CCR0, not_equal_continue);
1301
}
1302
1303
// Update the method data pointer by the displacement located at some fixed
1304
// offset from the method data pointer.
1305
void InterpreterMacroAssembler::update_mdp_by_offset(int offset_of_disp,
1306
Register scratch) {
1307
assert(ProfileInterpreter, "must be profiling interpreter");
1308
1309
ld(scratch, offset_of_disp, R28_mdx);
1310
add(R28_mdx, scratch, R28_mdx);
1311
}
1312
1313
// Update the method data pointer by the displacement located at the
1314
// offset (reg + offset_of_disp).
1315
void InterpreterMacroAssembler::update_mdp_by_offset(Register reg,
1316
int offset_of_disp,
1317
Register scratch) {
1318
assert(ProfileInterpreter, "must be profiling interpreter");
1319
1320
add(scratch, reg, R28_mdx);
1321
ld(scratch, offset_of_disp, scratch);
1322
add(R28_mdx, scratch, R28_mdx);
1323
}
1324
1325
// Update the method data pointer by a simple constant displacement.
1326
void InterpreterMacroAssembler::update_mdp_by_constant(int constant) {
1327
assert(ProfileInterpreter, "must be profiling interpreter");
1328
addi(R28_mdx, R28_mdx, constant);
1329
}
1330
1331
// Update the method data pointer for a _ret bytecode whose target
1332
// was not among our cached targets.
1333
void InterpreterMacroAssembler::update_mdp_for_ret(TosState state,
1334
Register return_bci) {
1335
assert(ProfileInterpreter, "must be profiling interpreter");
1336
1337
push(state);
1338
assert(return_bci->is_nonvolatile(), "need to protect return_bci");
1339
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
1340
pop(state);
1341
}
1342
1343
// Increments the backedge counter.
1344
// Returns backedge counter + invocation counter in Rdst.
1345
void InterpreterMacroAssembler::increment_backedge_counter(const Register Rcounters, const Register Rdst,
1346
const Register Rtmp1, Register Rscratch) {
1347
assert(UseCompiler, "incrementing must be useful");
1348
assert_different_registers(Rdst, Rtmp1);
1349
const Register invocation_counter = Rtmp1;
1350
const Register counter = Rdst;
1351
// TODO: PPC port: assert(4 == InvocationCounter::sz_counter(), "unexpected field size.");
1352
1353
// Load backedge counter.
1354
lwz(counter, in_bytes(MethodCounters::backedge_counter_offset()) +
1355
in_bytes(InvocationCounter::counter_offset()), Rcounters);
1356
// Load invocation counter.
1357
lwz(invocation_counter, in_bytes(MethodCounters::invocation_counter_offset()) +
1358
in_bytes(InvocationCounter::counter_offset()), Rcounters);
1359
1360
// Add the delta to the backedge counter.
1361
addi(counter, counter, InvocationCounter::count_increment);
1362
1363
// Mask the invocation counter.
1364
andi(invocation_counter, invocation_counter, InvocationCounter::count_mask_value);
1365
1366
// Store new counter value.
1367
stw(counter, in_bytes(MethodCounters::backedge_counter_offset()) +
1368
in_bytes(InvocationCounter::counter_offset()), Rcounters);
1369
// Return invocation counter + backedge counter.
1370
add(counter, counter, invocation_counter);
1371
}
1372
1373
// Count a taken branch in the bytecodes.
1374
void InterpreterMacroAssembler::profile_taken_branch(Register scratch, Register bumped_count) {
1375
if (ProfileInterpreter) {
1376
Label profile_continue;
1377
1378
// If no method data exists, go to profile_continue.
1379
test_method_data_pointer(profile_continue);
1380
1381
// We are taking a branch. Increment the taken count.
1382
increment_mdp_data_at(in_bytes(JumpData::taken_offset()), scratch, bumped_count);
1383
1384
// The method data pointer needs to be updated to reflect the new target.
1385
update_mdp_by_offset(in_bytes(JumpData::displacement_offset()), scratch);
1386
bind (profile_continue);
1387
}
1388
}
1389
1390
// Count a not-taken branch in the bytecodes.
1391
void InterpreterMacroAssembler::profile_not_taken_branch(Register scratch1, Register scratch2) {
1392
if (ProfileInterpreter) {
1393
Label profile_continue;
1394
1395
// If no method data exists, go to profile_continue.
1396
test_method_data_pointer(profile_continue);
1397
1398
// We are taking a branch. Increment the not taken count.
1399
increment_mdp_data_at(in_bytes(BranchData::not_taken_offset()), scratch1, scratch2);
1400
1401
// The method data pointer needs to be updated to correspond to the
1402
// next bytecode.
1403
update_mdp_by_constant(in_bytes(BranchData::branch_data_size()));
1404
bind (profile_continue);
1405
}
1406
}
1407
1408
// Count a non-virtual call in the bytecodes.
1409
void InterpreterMacroAssembler::profile_call(Register scratch1, Register scratch2) {
1410
if (ProfileInterpreter) {
1411
Label profile_continue;
1412
1413
// If no method data exists, go to profile_continue.
1414
test_method_data_pointer(profile_continue);
1415
1416
// We are making a call. Increment the count.
1417
increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1418
1419
// The method data pointer needs to be updated to reflect the new target.
1420
update_mdp_by_constant(in_bytes(CounterData::counter_data_size()));
1421
bind (profile_continue);
1422
}
1423
}
1424
1425
// Count a final call in the bytecodes.
1426
void InterpreterMacroAssembler::profile_final_call(Register scratch1, Register scratch2) {
1427
if (ProfileInterpreter) {
1428
Label profile_continue;
1429
1430
// If no method data exists, go to profile_continue.
1431
test_method_data_pointer(profile_continue);
1432
1433
// We are making a call. Increment the count.
1434
increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1435
1436
// The method data pointer needs to be updated to reflect the new target.
1437
update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1438
bind (profile_continue);
1439
}
1440
}
1441
1442
// Count a virtual call in the bytecodes.
1443
void InterpreterMacroAssembler::profile_virtual_call(Register Rreceiver,
1444
Register Rscratch1,
1445
Register Rscratch2,
1446
bool receiver_can_be_null) {
1447
if (!ProfileInterpreter) { return; }
1448
Label profile_continue;
1449
1450
// If no method data exists, go to profile_continue.
1451
test_method_data_pointer(profile_continue);
1452
1453
Label skip_receiver_profile;
1454
if (receiver_can_be_null) {
1455
Label not_null;
1456
cmpdi(CCR0, Rreceiver, 0);
1457
bne(CCR0, not_null);
1458
// We are making a call. Increment the count for null receiver.
1459
increment_mdp_data_at(in_bytes(CounterData::count_offset()), Rscratch1, Rscratch2);
1460
b(skip_receiver_profile);
1461
bind(not_null);
1462
}
1463
1464
// Record the receiver type.
1465
record_klass_in_profile(Rreceiver, Rscratch1, Rscratch2, true);
1466
bind(skip_receiver_profile);
1467
1468
// The method data pointer needs to be updated to reflect the new target.
1469
update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1470
bind (profile_continue);
1471
}
1472
1473
void InterpreterMacroAssembler::profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2) {
1474
if (ProfileInterpreter) {
1475
Label profile_continue;
1476
1477
// If no method data exists, go to profile_continue.
1478
test_method_data_pointer(profile_continue);
1479
1480
int mdp_delta = in_bytes(BitData::bit_data_size());
1481
if (TypeProfileCasts) {
1482
mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1483
1484
// Record the object type.
1485
record_klass_in_profile(Rklass, Rscratch1, Rscratch2, false);
1486
}
1487
1488
// The method data pointer needs to be updated.
1489
update_mdp_by_constant(mdp_delta);
1490
1491
bind (profile_continue);
1492
}
1493
}
1494
1495
void InterpreterMacroAssembler::profile_typecheck_failed(Register Rscratch1, Register Rscratch2) {
1496
if (ProfileInterpreter && TypeProfileCasts) {
1497
Label profile_continue;
1498
1499
// If no method data exists, go to profile_continue.
1500
test_method_data_pointer(profile_continue);
1501
1502
int count_offset = in_bytes(CounterData::count_offset());
1503
// Back up the address, since we have already bumped the mdp.
1504
count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1505
1506
// *Decrement* the counter. We expect to see zero or small negatives.
1507
increment_mdp_data_at(count_offset, Rscratch1, Rscratch2, true);
1508
1509
bind (profile_continue);
1510
}
1511
}
1512
1513
// Count a ret in the bytecodes.
1514
void InterpreterMacroAssembler::profile_ret(TosState state, Register return_bci,
1515
Register scratch1, Register scratch2) {
1516
if (ProfileInterpreter) {
1517
Label profile_continue;
1518
uint row;
1519
1520
// If no method data exists, go to profile_continue.
1521
test_method_data_pointer(profile_continue);
1522
1523
// Update the total ret count.
1524
increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2 );
1525
1526
for (row = 0; row < RetData::row_limit(); row++) {
1527
Label next_test;
1528
1529
// See if return_bci is equal to bci[n]:
1530
test_mdp_data_at(in_bytes(RetData::bci_offset(row)), return_bci, next_test, scratch1);
1531
1532
// return_bci is equal to bci[n]. Increment the count.
1533
increment_mdp_data_at(in_bytes(RetData::bci_count_offset(row)), scratch1, scratch2);
1534
1535
// The method data pointer needs to be updated to reflect the new target.
1536
update_mdp_by_offset(in_bytes(RetData::bci_displacement_offset(row)), scratch1);
1537
b(profile_continue);
1538
bind(next_test);
1539
}
1540
1541
update_mdp_for_ret(state, return_bci);
1542
1543
bind (profile_continue);
1544
}
1545
}
1546
1547
// Count the default case of a switch construct.
1548
void InterpreterMacroAssembler::profile_switch_default(Register scratch1, Register scratch2) {
1549
if (ProfileInterpreter) {
1550
Label profile_continue;
1551
1552
// If no method data exists, go to profile_continue.
1553
test_method_data_pointer(profile_continue);
1554
1555
// Update the default case count
1556
increment_mdp_data_at(in_bytes(MultiBranchData::default_count_offset()),
1557
scratch1, scratch2);
1558
1559
// The method data pointer needs to be updated.
1560
update_mdp_by_offset(in_bytes(MultiBranchData::default_displacement_offset()),
1561
scratch1);
1562
1563
bind (profile_continue);
1564
}
1565
}
1566
1567
// Count the index'th case of a switch construct.
1568
void InterpreterMacroAssembler::profile_switch_case(Register index,
1569
Register scratch1,
1570
Register scratch2,
1571
Register scratch3) {
1572
if (ProfileInterpreter) {
1573
assert_different_registers(index, scratch1, scratch2, scratch3);
1574
Label profile_continue;
1575
1576
// If no method data exists, go to profile_continue.
1577
test_method_data_pointer(profile_continue);
1578
1579
// Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes().
1580
li(scratch3, in_bytes(MultiBranchData::case_array_offset()));
1581
1582
assert (in_bytes(MultiBranchData::per_case_size()) == 16, "so that shladd works");
1583
sldi(scratch1, index, exact_log2(in_bytes(MultiBranchData::per_case_size())));
1584
add(scratch1, scratch1, scratch3);
1585
1586
// Update the case count.
1587
increment_mdp_data_at(scratch1, in_bytes(MultiBranchData::relative_count_offset()), scratch2, scratch3);
1588
1589
// The method data pointer needs to be updated.
1590
update_mdp_by_offset(scratch1, in_bytes(MultiBranchData::relative_displacement_offset()), scratch2);
1591
1592
bind (profile_continue);
1593
}
1594
}
1595
1596
void InterpreterMacroAssembler::profile_null_seen(Register Rscratch1, Register Rscratch2) {
1597
if (ProfileInterpreter) {
1598
assert_different_registers(Rscratch1, Rscratch2);
1599
Label profile_continue;
1600
1601
// If no method data exists, go to profile_continue.
1602
test_method_data_pointer(profile_continue);
1603
1604
set_mdp_flag_at(BitData::null_seen_byte_constant(), Rscratch1);
1605
1606
// The method data pointer needs to be updated.
1607
int mdp_delta = in_bytes(BitData::bit_data_size());
1608
if (TypeProfileCasts) {
1609
mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1610
}
1611
update_mdp_by_constant(mdp_delta);
1612
1613
bind (profile_continue);
1614
}
1615
}
1616
1617
void InterpreterMacroAssembler::record_klass_in_profile(Register Rreceiver,
1618
Register Rscratch1, Register Rscratch2,
1619
bool is_virtual_call) {
1620
assert(ProfileInterpreter, "must be profiling");
1621
assert_different_registers(Rreceiver, Rscratch1, Rscratch2);
1622
1623
Label done;
1624
record_klass_in_profile_helper(Rreceiver, Rscratch1, Rscratch2, 0, done, is_virtual_call);
1625
bind (done);
1626
}
1627
1628
void InterpreterMacroAssembler::record_klass_in_profile_helper(
1629
Register receiver, Register scratch1, Register scratch2,
1630
int start_row, Label& done, bool is_virtual_call) {
1631
if (TypeProfileWidth == 0) {
1632
if (is_virtual_call) {
1633
increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1634
}
1635
return;
1636
}
1637
1638
int last_row = VirtualCallData::row_limit() - 1;
1639
assert(start_row <= last_row, "must be work left to do");
1640
// Test this row for both the receiver and for null.
1641
// Take any of three different outcomes:
1642
// 1. found receiver => increment count and goto done
1643
// 2. found null => keep looking for case 1, maybe allocate this cell
1644
// 3. found something else => keep looking for cases 1 and 2
1645
// Case 3 is handled by a recursive call.
1646
for (int row = start_row; row <= last_row; row++) {
1647
Label next_test;
1648
bool test_for_null_also = (row == start_row);
1649
1650
// See if the receiver is receiver[n].
1651
int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1652
test_mdp_data_at(recvr_offset, receiver, next_test, scratch1);
1653
// delayed()->tst(scratch);
1654
1655
// The receiver is receiver[n]. Increment count[n].
1656
int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1657
increment_mdp_data_at(count_offset, scratch1, scratch2);
1658
b(done);
1659
bind(next_test);
1660
1661
if (test_for_null_also) {
1662
Label found_null;
1663
// Failed the equality check on receiver[n]... Test for null.
1664
if (start_row == last_row) {
1665
// The only thing left to do is handle the null case.
1666
if (is_virtual_call) {
1667
// Scratch1 contains test_out from test_mdp_data_at.
1668
cmpdi(CCR0, scratch1, 0);
1669
beq(CCR0, found_null);
1670
// Receiver did not match any saved receiver and there is no empty row for it.
1671
// Increment total counter to indicate polymorphic case.
1672
increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1673
b(done);
1674
bind(found_null);
1675
} else {
1676
cmpdi(CCR0, scratch1, 0);
1677
bne(CCR0, done);
1678
}
1679
break;
1680
}
1681
// Since null is rare, make it be the branch-taken case.
1682
cmpdi(CCR0, scratch1, 0);
1683
beq(CCR0, found_null);
1684
1685
// Put all the "Case 3" tests here.
1686
record_klass_in_profile_helper(receiver, scratch1, scratch2, start_row + 1, done, is_virtual_call);
1687
1688
// Found a null. Keep searching for a matching receiver,
1689
// but remember that this is an empty (unused) slot.
1690
bind(found_null);
1691
}
1692
}
1693
1694
// In the fall-through case, we found no matching receiver, but we
1695
// observed the receiver[start_row] is NULL.
1696
1697
// Fill in the receiver field and increment the count.
1698
int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1699
set_mdp_data_at(recvr_offset, receiver);
1700
int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1701
li(scratch1, DataLayout::counter_increment);
1702
set_mdp_data_at(count_offset, scratch1);
1703
if (start_row > 0) {
1704
b(done);
1705
}
1706
}
1707
1708
// Argument and return type profilig.
1709
// kills: tmp, tmp2, R0, CR0, CR1
1710
void InterpreterMacroAssembler::profile_obj_type(Register obj, Register mdo_addr_base,
1711
RegisterOrConstant mdo_addr_offs,
1712
Register tmp, Register tmp2) {
1713
Label do_nothing, do_update;
1714
1715
// tmp2 = obj is allowed
1716
assert_different_registers(obj, mdo_addr_base, tmp, R0);
1717
assert_different_registers(tmp2, mdo_addr_base, tmp, R0);
1718
const Register klass = tmp2;
1719
1720
verify_oop(obj);
1721
1722
ld(tmp, mdo_addr_offs, mdo_addr_base);
1723
1724
// Set null_seen if obj is 0.
1725
cmpdi(CCR0, obj, 0);
1726
ori(R0, tmp, TypeEntries::null_seen);
1727
beq(CCR0, do_update);
1728
1729
load_klass(klass, obj);
1730
1731
clrrdi(R0, tmp, exact_log2(-TypeEntries::type_klass_mask));
1732
// Basically same as andi(R0, tmp, TypeEntries::type_klass_mask);
1733
cmpd(CCR1, R0, klass);
1734
// Klass seen before, nothing to do (regardless of unknown bit).
1735
//beq(CCR1, do_nothing);
1736
1737
andi_(R0, klass, TypeEntries::type_unknown);
1738
// Already unknown. Nothing to do anymore.
1739
//bne(CCR0, do_nothing);
1740
crorc(CCR0, Assembler::equal, CCR1, Assembler::equal); // cr0 eq = cr1 eq or cr0 ne
1741
beq(CCR0, do_nothing);
1742
1743
clrrdi_(R0, tmp, exact_log2(-TypeEntries::type_mask));
1744
orr(R0, klass, tmp); // Combine klass and null_seen bit (only used if (tmp & type_mask)==0).
1745
beq(CCR0, do_update); // First time here. Set profile type.
1746
1747
// Different than before. Cannot keep accurate profile.
1748
ori(R0, tmp, TypeEntries::type_unknown);
1749
1750
bind(do_update);
1751
// update profile
1752
std(R0, mdo_addr_offs, mdo_addr_base);
1753
1754
align(32, 12);
1755
bind(do_nothing);
1756
}
1757
1758
void InterpreterMacroAssembler::profile_arguments_type(Register callee,
1759
Register tmp1, Register tmp2,
1760
bool is_virtual) {
1761
if (!ProfileInterpreter) {
1762
return;
1763
}
1764
1765
assert_different_registers(callee, tmp1, tmp2, R28_mdx);
1766
1767
if (MethodData::profile_arguments() || MethodData::profile_return()) {
1768
Label profile_continue;
1769
1770
test_method_data_pointer(profile_continue);
1771
1772
int off_to_start = is_virtual ?
1773
in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1774
1775
lbz(tmp1, in_bytes(DataLayout::tag_offset()) - off_to_start, R28_mdx);
1776
cmpwi(CCR0, tmp1, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
1777
bne(CCR0, profile_continue);
1778
1779
if (MethodData::profile_arguments()) {
1780
Label done;
1781
int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1782
add(R28_mdx, off_to_args, R28_mdx);
1783
1784
for (int i = 0; i < TypeProfileArgsLimit; i++) {
1785
if (i > 0 || MethodData::profile_return()) {
1786
// If return value type is profiled we may have no argument to profile.
1787
ld(tmp1, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, R28_mdx);
1788
cmpdi(CCR0, tmp1, (i+1)*TypeStackSlotEntries::per_arg_count());
1789
addi(tmp1, tmp1, -i*TypeStackSlotEntries::per_arg_count());
1790
blt(CCR0, done);
1791
}
1792
ld(tmp1, in_bytes(Method::const_offset()), callee);
1793
lhz(tmp1, in_bytes(ConstMethod::size_of_parameters_offset()), tmp1);
1794
// Stack offset o (zero based) from the start of the argument
1795
// list, for n arguments translates into offset n - o - 1 from
1796
// the end of the argument list. But there's an extra slot at
1797
// the top of the stack. So the offset is n - o from Lesp.
1798
ld(tmp2, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args, R28_mdx);
1799
subf(tmp1, tmp2, tmp1);
1800
1801
sldi(tmp1, tmp1, Interpreter::logStackElementSize);
1802
ldx(tmp1, tmp1, R15_esp);
1803
1804
profile_obj_type(tmp1, R28_mdx, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args, tmp2, tmp1);
1805
1806
int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1807
addi(R28_mdx, R28_mdx, to_add);
1808
off_to_args += to_add;
1809
}
1810
1811
if (MethodData::profile_return()) {
1812
ld(tmp1, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, R28_mdx);
1813
addi(tmp1, tmp1, -TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
1814
}
1815
1816
bind(done);
1817
1818
if (MethodData::profile_return()) {
1819
// We're right after the type profile for the last
1820
// argument. tmp1 is the number of cells left in the
1821
// CallTypeData/VirtualCallTypeData to reach its end. Non null
1822
// if there's a return to profile.
1823
assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(),
1824
"can't move past ret type");
1825
sldi(tmp1, tmp1, exact_log2(DataLayout::cell_size));
1826
add(R28_mdx, tmp1, R28_mdx);
1827
}
1828
} else {
1829
assert(MethodData::profile_return(), "either profile call args or call ret");
1830
update_mdp_by_constant(in_bytes(TypeEntriesAtCall::return_only_size()));
1831
}
1832
1833
// Mdp points right after the end of the
1834
// CallTypeData/VirtualCallTypeData, right after the cells for the
1835
// return value type if there's one.
1836
align(32, 12);
1837
bind(profile_continue);
1838
}
1839
}
1840
1841
void InterpreterMacroAssembler::profile_return_type(Register ret, Register tmp1, Register tmp2) {
1842
assert_different_registers(ret, tmp1, tmp2);
1843
if (ProfileInterpreter && MethodData::profile_return()) {
1844
Label profile_continue;
1845
1846
test_method_data_pointer(profile_continue);
1847
1848
if (MethodData::profile_return_jsr292_only()) {
1849
// If we don't profile all invoke bytecodes we must make sure
1850
// it's a bytecode we indeed profile. We can't go back to the
1851
// begining of the ProfileData we intend to update to check its
1852
// type because we're right after it and we don't known its
1853
// length.
1854
lbz(tmp1, 0, R14_bcp);
1855
lbz(tmp2, Method::intrinsic_id_offset_in_bytes(), R19_method);
1856
cmpwi(CCR0, tmp1, Bytecodes::_invokedynamic);
1857
cmpwi(CCR1, tmp1, Bytecodes::_invokehandle);
1858
cror(CCR0, Assembler::equal, CCR1, Assembler::equal);
1859
cmpwi(CCR1, tmp2, static_cast<int>(vmIntrinsics::_compiledLambdaForm));
1860
cror(CCR0, Assembler::equal, CCR1, Assembler::equal);
1861
bne(CCR0, profile_continue);
1862
}
1863
1864
profile_obj_type(ret, R28_mdx, -in_bytes(ReturnTypeEntry::size()), tmp1, tmp2);
1865
1866
align(32, 12);
1867
bind(profile_continue);
1868
}
1869
}
1870
1871
void InterpreterMacroAssembler::profile_parameters_type(Register tmp1, Register tmp2,
1872
Register tmp3, Register tmp4) {
1873
if (ProfileInterpreter && MethodData::profile_parameters()) {
1874
Label profile_continue, done;
1875
1876
test_method_data_pointer(profile_continue);
1877
1878
// Load the offset of the area within the MDO used for
1879
// parameters. If it's negative we're not profiling any parameters.
1880
lwz(tmp1, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()), R28_mdx);
1881
cmpwi(CCR0, tmp1, 0);
1882
blt(CCR0, profile_continue);
1883
1884
// Compute a pointer to the area for parameters from the offset
1885
// and move the pointer to the slot for the last
1886
// parameters. Collect profiling from last parameter down.
1887
// mdo start + parameters offset + array length - 1
1888
1889
// Pointer to the parameter area in the MDO.
1890
const Register mdp = tmp1;
1891
add(mdp, tmp1, R28_mdx);
1892
1893
// Offset of the current profile entry to update.
1894
const Register entry_offset = tmp2;
1895
// entry_offset = array len in number of cells
1896
ld(entry_offset, in_bytes(ArrayData::array_len_offset()), mdp);
1897
1898
int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
1899
assert(off_base % DataLayout::cell_size == 0, "should be a number of cells");
1900
1901
// entry_offset (number of cells) = array len - size of 1 entry + offset of the stack slot field
1902
addi(entry_offset, entry_offset, -TypeStackSlotEntries::per_arg_count() + (off_base / DataLayout::cell_size));
1903
// entry_offset in bytes
1904
sldi(entry_offset, entry_offset, exact_log2(DataLayout::cell_size));
1905
1906
Label loop;
1907
align(32, 12);
1908
bind(loop);
1909
1910
// Load offset on the stack from the slot for this parameter.
1911
ld(tmp3, entry_offset, mdp);
1912
sldi(tmp3, tmp3, Interpreter::logStackElementSize);
1913
neg(tmp3, tmp3);
1914
// Read the parameter from the local area.
1915
ldx(tmp3, tmp3, R18_locals);
1916
1917
// Make entry_offset now point to the type field for this parameter.
1918
int type_base = in_bytes(ParametersTypeData::type_offset(0));
1919
assert(type_base > off_base, "unexpected");
1920
addi(entry_offset, entry_offset, type_base - off_base);
1921
1922
// Profile the parameter.
1923
profile_obj_type(tmp3, mdp, entry_offset, tmp4, tmp3);
1924
1925
// Go to next parameter.
1926
int delta = TypeStackSlotEntries::per_arg_count() * DataLayout::cell_size + (type_base - off_base);
1927
cmpdi(CCR0, entry_offset, off_base + delta);
1928
addi(entry_offset, entry_offset, -delta);
1929
bge(CCR0, loop);
1930
1931
align(32, 12);
1932
bind(profile_continue);
1933
}
1934
}
1935
1936
// Add a InterpMonitorElem to stack (see frame_sparc.hpp).
1937
void InterpreterMacroAssembler::add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2) {
1938
1939
// Very-local scratch registers.
1940
const Register esp = Rtemp1;
1941
const Register slot = Rtemp2;
1942
1943
// Extracted monitor_size.
1944
int monitor_size = frame::interpreter_frame_monitor_size_in_bytes();
1945
assert(Assembler::is_aligned((unsigned int)monitor_size,
1946
(unsigned int)frame::alignment_in_bytes),
1947
"size of a monitor must respect alignment of SP");
1948
1949
resize_frame(-monitor_size, /*temp*/esp); // Allocate space for new monitor
1950
std(R1_SP, _ijava_state_neg(top_frame_sp), esp); // esp contains fp
1951
1952
// Shuffle expression stack down. Recall that stack_base points
1953
// just above the new expression stack bottom. Old_tos and new_tos
1954
// are used to scan thru the old and new expression stacks.
1955
if (!stack_is_empty) {
1956
Label copy_slot, copy_slot_finished;
1957
const Register n_slots = slot;
1958
1959
addi(esp, R15_esp, Interpreter::stackElementSize); // Point to first element (pre-pushed stack).
1960
subf(n_slots, esp, R26_monitor);
1961
srdi_(n_slots, n_slots, LogBytesPerWord); // Compute number of slots to copy.
1962
assert(LogBytesPerWord == 3, "conflicts assembler instructions");
1963
beq(CCR0, copy_slot_finished); // Nothing to copy.
1964
1965
mtctr(n_slots);
1966
1967
// loop
1968
bind(copy_slot);
1969
ld(slot, 0, esp); // Move expression stack down.
1970
std(slot, -monitor_size, esp); // distance = monitor_size
1971
addi(esp, esp, BytesPerWord);
1972
bdnz(copy_slot);
1973
1974
bind(copy_slot_finished);
1975
}
1976
1977
addi(R15_esp, R15_esp, -monitor_size);
1978
addi(R26_monitor, R26_monitor, -monitor_size);
1979
1980
// Restart interpreter
1981
}
1982
1983
// ============================================================================
1984
// Java locals access
1985
1986
// Load a local variable at index in Rindex into register Rdst_value.
1987
// Also puts address of local into Rdst_address as a service.
1988
// Kills:
1989
// - Rdst_value
1990
// - Rdst_address
1991
void InterpreterMacroAssembler::load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex) {
1992
sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
1993
subf(Rdst_address, Rdst_address, R18_locals);
1994
lwz(Rdst_value, 0, Rdst_address);
1995
}
1996
1997
// Load a local variable at index in Rindex into register Rdst_value.
1998
// Also puts address of local into Rdst_address as a service.
1999
// Kills:
2000
// - Rdst_value
2001
// - Rdst_address
2002
void InterpreterMacroAssembler::load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex) {
2003
sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
2004
subf(Rdst_address, Rdst_address, R18_locals);
2005
ld(Rdst_value, -8, Rdst_address);
2006
}
2007
2008
// Load a local variable at index in Rindex into register Rdst_value.
2009
// Also puts address of local into Rdst_address as a service.
2010
// Input:
2011
// - Rindex: slot nr of local variable
2012
// Kills:
2013
// - Rdst_value
2014
// - Rdst_address
2015
void InterpreterMacroAssembler::load_local_ptr(Register Rdst_value,
2016
Register Rdst_address,
2017
Register Rindex) {
2018
sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
2019
subf(Rdst_address, Rdst_address, R18_locals);
2020
ld(Rdst_value, 0, Rdst_address);
2021
}
2022
2023
// Load a local variable at index in Rindex into register Rdst_value.
2024
// Also puts address of local into Rdst_address as a service.
2025
// Kills:
2026
// - Rdst_value
2027
// - Rdst_address
2028
void InterpreterMacroAssembler::load_local_float(FloatRegister Rdst_value,
2029
Register Rdst_address,
2030
Register Rindex) {
2031
sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
2032
subf(Rdst_address, Rdst_address, R18_locals);
2033
lfs(Rdst_value, 0, Rdst_address);
2034
}
2035
2036
// Load a local variable at index in Rindex into register Rdst_value.
2037
// Also puts address of local into Rdst_address as a service.
2038
// Kills:
2039
// - Rdst_value
2040
// - Rdst_address
2041
void InterpreterMacroAssembler::load_local_double(FloatRegister Rdst_value,
2042
Register Rdst_address,
2043
Register Rindex) {
2044
sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
2045
subf(Rdst_address, Rdst_address, R18_locals);
2046
lfd(Rdst_value, -8, Rdst_address);
2047
}
2048
2049
// Store an int value at local variable slot Rindex.
2050
// Kills:
2051
// - Rindex
2052
void InterpreterMacroAssembler::store_local_int(Register Rvalue, Register Rindex) {
2053
sldi(Rindex, Rindex, Interpreter::logStackElementSize);
2054
subf(Rindex, Rindex, R18_locals);
2055
stw(Rvalue, 0, Rindex);
2056
}
2057
2058
// Store a long value at local variable slot Rindex.
2059
// Kills:
2060
// - Rindex
2061
void InterpreterMacroAssembler::store_local_long(Register Rvalue, Register Rindex) {
2062
sldi(Rindex, Rindex, Interpreter::logStackElementSize);
2063
subf(Rindex, Rindex, R18_locals);
2064
std(Rvalue, -8, Rindex);
2065
}
2066
2067
// Store an oop value at local variable slot Rindex.
2068
// Kills:
2069
// - Rindex
2070
void InterpreterMacroAssembler::store_local_ptr(Register Rvalue, Register Rindex) {
2071
sldi(Rindex, Rindex, Interpreter::logStackElementSize);
2072
subf(Rindex, Rindex, R18_locals);
2073
std(Rvalue, 0, Rindex);
2074
}
2075
2076
// Store an int value at local variable slot Rindex.
2077
// Kills:
2078
// - Rindex
2079
void InterpreterMacroAssembler::store_local_float(FloatRegister Rvalue, Register Rindex) {
2080
sldi(Rindex, Rindex, Interpreter::logStackElementSize);
2081
subf(Rindex, Rindex, R18_locals);
2082
stfs(Rvalue, 0, Rindex);
2083
}
2084
2085
// Store an int value at local variable slot Rindex.
2086
// Kills:
2087
// - Rindex
2088
void InterpreterMacroAssembler::store_local_double(FloatRegister Rvalue, Register Rindex) {
2089
sldi(Rindex, Rindex, Interpreter::logStackElementSize);
2090
subf(Rindex, Rindex, R18_locals);
2091
stfd(Rvalue, -8, Rindex);
2092
}
2093
2094
// Read pending exception from thread and jump to interpreter.
2095
// Throw exception entry if one if pending. Fall through otherwise.
2096
void InterpreterMacroAssembler::check_and_forward_exception(Register Rscratch1, Register Rscratch2) {
2097
assert_different_registers(Rscratch1, Rscratch2, R3);
2098
Register Rexception = Rscratch1;
2099
Register Rtmp = Rscratch2;
2100
Label Ldone;
2101
// Get pending exception oop.
2102
ld(Rexception, thread_(pending_exception));
2103
cmpdi(CCR0, Rexception, 0);
2104
beq(CCR0, Ldone);
2105
li(Rtmp, 0);
2106
mr_if_needed(R3, Rexception);
2107
std(Rtmp, thread_(pending_exception)); // Clear exception in thread
2108
if (Interpreter::rethrow_exception_entry() != NULL) {
2109
// Already got entry address.
2110
load_dispatch_table(Rtmp, (address*)Interpreter::rethrow_exception_entry());
2111
} else {
2112
// Dynamically load entry address.
2113
int simm16_rest = load_const_optimized(Rtmp, &Interpreter::_rethrow_exception_entry, R0, true);
2114
ld(Rtmp, simm16_rest, Rtmp);
2115
}
2116
mtctr(Rtmp);
2117
save_interpreter_state(Rtmp);
2118
bctr();
2119
2120
align(32, 12);
2121
bind(Ldone);
2122
}
2123
2124
void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, bool check_exceptions) {
2125
save_interpreter_state(R11_scratch1);
2126
2127
MacroAssembler::call_VM(oop_result, entry_point, false);
2128
2129
restore_interpreter_state(R11_scratch1, /*bcp_and_mdx_only*/ true);
2130
2131
check_and_handle_popframe(R11_scratch1);
2132
check_and_handle_earlyret(R11_scratch1);
2133
// Now check exceptions manually.
2134
if (check_exceptions) {
2135
check_and_forward_exception(R11_scratch1, R12_scratch2);
2136
}
2137
}
2138
2139
void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,
2140
Register arg_1, bool check_exceptions) {
2141
// ARG1 is reserved for the thread.
2142
mr_if_needed(R4_ARG2, arg_1);
2143
call_VM(oop_result, entry_point, check_exceptions);
2144
}
2145
2146
void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,
2147
Register arg_1, Register arg_2,
2148
bool check_exceptions) {
2149
// ARG1 is reserved for the thread.
2150
mr_if_needed(R4_ARG2, arg_1);
2151
assert(arg_2 != R4_ARG2, "smashed argument");
2152
mr_if_needed(R5_ARG3, arg_2);
2153
call_VM(oop_result, entry_point, check_exceptions);
2154
}
2155
2156
void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,
2157
Register arg_1, Register arg_2, Register arg_3,
2158
bool check_exceptions) {
2159
// ARG1 is reserved for the thread.
2160
mr_if_needed(R4_ARG2, arg_1);
2161
assert(arg_2 != R4_ARG2, "smashed argument");
2162
mr_if_needed(R5_ARG3, arg_2);
2163
assert(arg_3 != R4_ARG2 && arg_3 != R5_ARG3, "smashed argument");
2164
mr_if_needed(R6_ARG4, arg_3);
2165
call_VM(oop_result, entry_point, check_exceptions);
2166
}
2167
2168
void InterpreterMacroAssembler::save_interpreter_state(Register scratch) {
2169
ld(scratch, 0, R1_SP);
2170
std(R15_esp, _ijava_state_neg(esp), scratch);
2171
std(R14_bcp, _ijava_state_neg(bcp), scratch);
2172
std(R26_monitor, _ijava_state_neg(monitors), scratch);
2173
if (ProfileInterpreter) { std(R28_mdx, _ijava_state_neg(mdx), scratch); }
2174
// Other entries should be unchanged.
2175
}
2176
2177
void InterpreterMacroAssembler::restore_interpreter_state(Register scratch, bool bcp_and_mdx_only) {
2178
ld(scratch, 0, R1_SP);
2179
ld(R14_bcp, _ijava_state_neg(bcp), scratch); // Changed by VM code (exception).
2180
if (ProfileInterpreter) { ld(R28_mdx, _ijava_state_neg(mdx), scratch); } // Changed by VM code.
2181
if (!bcp_and_mdx_only) {
2182
// Following ones are Metadata.
2183
ld(R19_method, _ijava_state_neg(method), scratch);
2184
ld(R27_constPoolCache, _ijava_state_neg(cpoolCache), scratch);
2185
// Following ones are stack addresses and don't require reload.
2186
ld(R15_esp, _ijava_state_neg(esp), scratch);
2187
ld(R18_locals, _ijava_state_neg(locals), scratch);
2188
ld(R26_monitor, _ijava_state_neg(monitors), scratch);
2189
}
2190
#ifdef ASSERT
2191
{
2192
Label Lok;
2193
subf(R0, R1_SP, scratch);
2194
cmpdi(CCR0, R0, frame::abi_reg_args_size + frame::ijava_state_size);
2195
bge(CCR0, Lok);
2196
stop("frame too small (restore istate)");
2197
bind(Lok);
2198
}
2199
#endif
2200
}
2201
2202
void InterpreterMacroAssembler::get_method_counters(Register method,
2203
Register Rcounters,
2204
Label& skip) {
2205
BLOCK_COMMENT("Load and ev. allocate counter object {");
2206
Label has_counters;
2207
ld(Rcounters, in_bytes(Method::method_counters_offset()), method);
2208
cmpdi(CCR0, Rcounters, 0);
2209
bne(CCR0, has_counters);
2210
call_VM(noreg, CAST_FROM_FN_PTR(address,
2211
InterpreterRuntime::build_method_counters), method);
2212
ld(Rcounters, in_bytes(Method::method_counters_offset()), method);
2213
cmpdi(CCR0, Rcounters, 0);
2214
beq(CCR0, skip); // No MethodCounters, OutOfMemory.
2215
BLOCK_COMMENT("} Load and ev. allocate counter object");
2216
2217
bind(has_counters);
2218
}
2219
2220
void InterpreterMacroAssembler::increment_invocation_counter(Register Rcounters,
2221
Register iv_be_count,
2222
Register Rtmp_r0) {
2223
assert(UseCompiler || LogTouchedMethods, "incrementing must be useful");
2224
Register invocation_count = iv_be_count;
2225
Register backedge_count = Rtmp_r0;
2226
int delta = InvocationCounter::count_increment;
2227
2228
// Load each counter in a register.
2229
// ld(inv_counter, Rtmp);
2230
// ld(be_counter, Rtmp2);
2231
int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() +
2232
InvocationCounter::counter_offset());
2233
int be_counter_offset = in_bytes(MethodCounters::backedge_counter_offset() +
2234
InvocationCounter::counter_offset());
2235
2236
BLOCK_COMMENT("Increment profiling counters {");
2237
2238
// Load the backedge counter.
2239
lwz(backedge_count, be_counter_offset, Rcounters); // is unsigned int
2240
// Mask the backedge counter.
2241
andi(backedge_count, backedge_count, InvocationCounter::count_mask_value);
2242
2243
// Load the invocation counter.
2244
lwz(invocation_count, inv_counter_offset, Rcounters); // is unsigned int
2245
// Add the delta to the invocation counter and store the result.
2246
addi(invocation_count, invocation_count, delta);
2247
// Store value.
2248
stw(invocation_count, inv_counter_offset, Rcounters);
2249
2250
// Add invocation counter + backedge counter.
2251
add(iv_be_count, backedge_count, invocation_count);
2252
2253
// Note that this macro must leave the backedge_count + invocation_count in
2254
// register iv_be_count!
2255
BLOCK_COMMENT("} Increment profiling counters");
2256
}
2257
2258
void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
2259
if (state == atos) { MacroAssembler::verify_oop(reg, FILE_AND_LINE); }
2260
}
2261
2262
// Local helper function for the verify_oop_or_return_address macro.
2263
static bool verify_return_address(Method* m, int bci) {
2264
#ifndef PRODUCT
2265
address pc = (address)(m->constMethod()) + in_bytes(ConstMethod::codes_offset()) + bci;
2266
// Assume it is a valid return address if it is inside m and is preceded by a jsr.
2267
if (!m->contains(pc)) return false;
2268
address jsr_pc;
2269
jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr);
2270
if (*jsr_pc == Bytecodes::_jsr && jsr_pc >= m->code_base()) return true;
2271
jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr_w);
2272
if (*jsr_pc == Bytecodes::_jsr_w && jsr_pc >= m->code_base()) return true;
2273
#endif // PRODUCT
2274
return false;
2275
}
2276
2277
void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
2278
if (VerifyFPU) {
2279
unimplemented("verfiyFPU");
2280
}
2281
}
2282
2283
void InterpreterMacroAssembler::verify_oop_or_return_address(Register reg, Register Rtmp) {
2284
if (!VerifyOops) return;
2285
2286
// The VM documentation for the astore[_wide] bytecode allows
2287
// the TOS to be not only an oop but also a return address.
2288
Label test;
2289
Label skip;
2290
// See if it is an address (in the current method):
2291
2292
const int log2_bytecode_size_limit = 16;
2293
srdi_(Rtmp, reg, log2_bytecode_size_limit);
2294
bne(CCR0, test);
2295
2296
address fd = CAST_FROM_FN_PTR(address, verify_return_address);
2297
const int nbytes_save = MacroAssembler::num_volatile_regs * 8;
2298
save_volatile_gprs(R1_SP, -nbytes_save); // except R0
2299
save_LR_CR(Rtmp); // Save in old frame.
2300
push_frame_reg_args(nbytes_save, Rtmp);
2301
2302
load_const_optimized(Rtmp, fd, R0);
2303
mr_if_needed(R4_ARG2, reg);
2304
mr(R3_ARG1, R19_method);
2305
call_c(Rtmp); // call C
2306
2307
pop_frame();
2308
restore_LR_CR(Rtmp);
2309
restore_volatile_gprs(R1_SP, -nbytes_save); // except R0
2310
b(skip);
2311
2312
// Perform a more elaborate out-of-line call.
2313
// Not an address; verify it:
2314
bind(test);
2315
verify_oop(reg);
2316
bind(skip);
2317
}
2318
2319
// Inline assembly for:
2320
//
2321
// if (thread is in interp_only_mode) {
2322
// InterpreterRuntime::post_method_entry();
2323
// }
2324
// if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY ) ||
2325
// *jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY2) ) {
2326
// SharedRuntime::jvmpi_method_entry(method, receiver);
2327
// }
2328
void InterpreterMacroAssembler::notify_method_entry() {
2329
// JVMTI
2330
// Whenever JVMTI puts a thread in interp_only_mode, method
2331
// entry/exit events are sent for that thread to track stack
2332
// depth. If it is possible to enter interp_only_mode we add
2333
// the code to check if the event should be sent.
2334
if (JvmtiExport::can_post_interpreter_events()) {
2335
Label jvmti_post_done;
2336
2337
lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
2338
cmpwi(CCR0, R0, 0);
2339
beq(CCR0, jvmti_post_done);
2340
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
2341
2342
bind(jvmti_post_done);
2343
}
2344
}
2345
2346
// Inline assembly for:
2347
//
2348
// if (thread is in interp_only_mode) {
2349
// // save result
2350
// InterpreterRuntime::post_method_exit();
2351
// // restore result
2352
// }
2353
// if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_EXIT)) {
2354
// // save result
2355
// SharedRuntime::jvmpi_method_exit();
2356
// // restore result
2357
// }
2358
//
2359
// Native methods have their result stored in d_tmp and l_tmp.
2360
// Java methods have their result stored in the expression stack.
2361
void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, TosState state,
2362
NotifyMethodExitMode mode, bool check_exceptions) {
2363
// JVMTI
2364
// Whenever JVMTI puts a thread in interp_only_mode, method
2365
// entry/exit events are sent for that thread to track stack
2366
// depth. If it is possible to enter interp_only_mode we add
2367
// the code to check if the event should be sent.
2368
if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
2369
Label jvmti_post_done;
2370
2371
lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
2372
cmpwi(CCR0, R0, 0);
2373
beq(CCR0, jvmti_post_done);
2374
if (!is_native_method) { push(state); } // Expose tos to GC.
2375
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit), check_exceptions);
2376
if (!is_native_method) { pop(state); }
2377
2378
align(32, 12);
2379
bind(jvmti_post_done);
2380
}
2381
2382
// Dtrace support not implemented.
2383
}
2384
2385