Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.cpp
32285 views
1
/*
2
* Copyright (c) 2013, Red Hat Inc.
3
* Copyright (c) 2003, 2011, Oracle and/or its affiliates.
4
* All rights reserved.
5
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
*
7
* This code is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 2 only, as
9
* published by the Free Software Foundation.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*
25
*/
26
27
#include "precompiled.hpp"
28
#include "interp_masm_aarch64.hpp"
29
#include "interpreter/interpreter.hpp"
30
#include "interpreter/interpreterRuntime.hpp"
31
#include "oops/arrayOop.hpp"
32
#include "oops/markOop.hpp"
33
#include "oops/methodData.hpp"
34
#include "oops/method.hpp"
35
#include "prims/jvmtiExport.hpp"
36
#include "prims/jvmtiRedefineClassesTrace.hpp"
37
#include "prims/jvmtiThreadState.hpp"
38
#include "runtime/basicLock.hpp"
39
#include "runtime/biasedLocking.hpp"
40
#include "runtime/sharedRuntime.hpp"
41
#include "runtime/thread.inline.hpp"
42
43
44
void InterpreterMacroAssembler::narrow(Register result) {
45
46
// Get method->_constMethod->_result_type
47
ldr(rscratch1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
48
ldr(rscratch1, Address(rscratch1, Method::const_offset()));
49
ldrb(rscratch1, Address(rscratch1, ConstMethod::result_type_offset()));
50
51
Label done, notBool, notByte, notChar;
52
53
// common case first
54
cmpw(rscratch1, T_INT);
55
br(Assembler::EQ, done);
56
57
// mask integer result to narrower return type.
58
cmpw(rscratch1, T_BOOLEAN);
59
br(Assembler::NE, notBool);
60
andw(result, result, 0x1);
61
b(done);
62
63
bind(notBool);
64
cmpw(rscratch1, T_BYTE);
65
br(Assembler::NE, notByte);
66
sbfx(result, result, 0, 8);
67
b(done);
68
69
bind(notByte);
70
cmpw(rscratch1, T_CHAR);
71
br(Assembler::NE, notChar);
72
ubfx(result, result, 0, 16); // truncate upper 16 bits
73
b(done);
74
75
bind(notChar);
76
sbfx(result, result, 0, 16); // sign-extend short
77
78
// Nothing to do for T_INT
79
bind(done);
80
}
81
82
#ifndef CC_INTERP
83
84
void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
85
if (JvmtiExport::can_pop_frame()) {
86
Label L;
87
// Initiate popframe handling only if it is not already being
88
// processed. If the flag has the popframe_processing bit set, it
89
// means that this code is called *during* popframe handling - we
90
// don't want to reenter.
91
// This method is only called just after the call into the vm in
92
// call_VM_base, so the arg registers are available.
93
ldrw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset()));
94
tstw(rscratch1, JavaThread::popframe_pending_bit);
95
br(Assembler::EQ, L);
96
tstw(rscratch1, JavaThread::popframe_processing_bit);
97
br(Assembler::NE, L);
98
// Call Interpreter::remove_activation_preserving_args_entry() to get the
99
// address of the same-named entrypoint in the generated interpreter code.
100
call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
101
br(r0);
102
bind(L);
103
}
104
}
105
106
107
void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
108
ldr(r2, Address(rthread, JavaThread::jvmti_thread_state_offset()));
109
const Address tos_addr(r2, JvmtiThreadState::earlyret_tos_offset());
110
const Address oop_addr(r2, JvmtiThreadState::earlyret_oop_offset());
111
const Address val_addr(r2, JvmtiThreadState::earlyret_value_offset());
112
switch (state) {
113
case atos: ldr(r0, oop_addr);
114
str(zr, oop_addr);
115
verify_oop(r0, state); break;
116
case ltos: ldr(r0, val_addr); break;
117
case btos: // fall through
118
case ztos: // fall through
119
case ctos: // fall through
120
case stos: // fall through
121
case itos: ldrw(r0, val_addr); break;
122
case ftos: ldrs(v0, val_addr); break;
123
case dtos: ldrd(v0, val_addr); break;
124
case vtos: /* nothing to do */ break;
125
default : ShouldNotReachHere();
126
}
127
// Clean up tos value in the thread object
128
movw(rscratch1, (int) ilgl);
129
strw(rscratch1, tos_addr);
130
strw(zr, val_addr);
131
}
132
133
134
void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
135
if (JvmtiExport::can_force_early_return()) {
136
Label L;
137
ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
138
cbz(rscratch1, L); // if (thread->jvmti_thread_state() == NULL) exit;
139
140
// Initiate earlyret handling only if it is not already being processed.
141
// If the flag has the earlyret_processing bit set, it means that this code
142
// is called *during* earlyret handling - we don't want to reenter.
143
ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_state_offset()));
144
cmpw(rscratch1, JvmtiThreadState::earlyret_pending);
145
br(Assembler::NE, L);
146
147
// Call Interpreter::remove_activation_early_entry() to get the address of the
148
// same-named entrypoint in the generated interpreter code.
149
ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
150
ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_tos_offset()));
151
call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), rscratch1);
152
br(r0);
153
bind(L);
154
}
155
}
156
157
void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
158
Register reg,
159
int bcp_offset) {
160
assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
161
ldrh(reg, Address(rbcp, bcp_offset));
162
rev16(reg, reg);
163
}
164
165
void InterpreterMacroAssembler::get_dispatch() {
166
unsigned long offset;
167
adrp(rdispatch, ExternalAddress((address)Interpreter::dispatch_table()), offset);
168
lea(rdispatch, Address(rdispatch, offset));
169
}
170
171
void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
172
int bcp_offset,
173
size_t index_size) {
174
assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
175
if (index_size == sizeof(u2)) {
176
load_unsigned_short(index, Address(rbcp, bcp_offset));
177
} else if (index_size == sizeof(u4)) {
178
assert(EnableInvokeDynamic, "giant index used only for JSR 292");
179
ldrw(index, Address(rbcp, bcp_offset));
180
// Check if the secondary index definition is still ~x, otherwise
181
// we have to change the following assembler code to calculate the
182
// plain index.
183
assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
184
eonw(index, index, zr); // convert to plain index
185
} else if (index_size == sizeof(u1)) {
186
load_unsigned_byte(index, Address(rbcp, bcp_offset));
187
} else {
188
ShouldNotReachHere();
189
}
190
}
191
192
// Return
193
// Rindex: index into constant pool
194
// Rcache: address of cache entry - ConstantPoolCache::base_offset()
195
//
196
// A caller must add ConstantPoolCache::base_offset() to Rcache to get
197
// the true address of the cache entry.
198
//
199
void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
200
Register index,
201
int bcp_offset,
202
size_t index_size) {
203
assert_different_registers(cache, index);
204
assert_different_registers(cache, rcpool);
205
get_cache_index_at_bcp(index, bcp_offset, index_size);
206
assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
207
// convert from field index to ConstantPoolCacheEntry
208
// aarch64 already has the cache in rcpool so there is no need to
209
// install it in cache. instead we pre-add the indexed offset to
210
// rcpool and return it in cache. All clients of this method need to
211
// be modified accordingly.
212
add(cache, rcpool, index, Assembler::LSL, 5);
213
}
214
215
216
void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
217
Register index,
218
Register bytecode,
219
int byte_no,
220
int bcp_offset,
221
size_t index_size) {
222
get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
223
// We use a 32-bit load here since the layout of 64-bit words on
224
// little-endian machines allow us that.
225
// n.b. unlike x86 cache already includes the index offset
226
lea(bytecode, Address(cache,
227
ConstantPoolCache::base_offset()
228
+ ConstantPoolCacheEntry::indices_offset()));
229
ldarw(bytecode, bytecode);
230
const int shift_count = (1 + byte_no) * BitsPerByte;
231
ubfx(bytecode, bytecode, shift_count, BitsPerByte);
232
}
233
234
void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
235
Register tmp,
236
int bcp_offset,
237
size_t index_size) {
238
assert(cache != tmp, "must use different register");
239
get_cache_index_at_bcp(tmp, bcp_offset, index_size);
240
assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
241
// convert from field index to ConstantPoolCacheEntry index
242
// and from word offset to byte offset
243
assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
244
ldr(cache, Address(rfp, frame::interpreter_frame_cache_offset * wordSize));
245
// skip past the header
246
add(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
247
add(cache, cache, tmp, Assembler::LSL, 2 + LogBytesPerWord); // construct pointer to cache entry
248
}
249
250
void InterpreterMacroAssembler::get_method_counters(Register method,
251
Register mcs, Label& skip) {
252
Label has_counters;
253
ldr(mcs, Address(method, Method::method_counters_offset()));
254
cbnz(mcs, has_counters);
255
call_VM(noreg, CAST_FROM_FN_PTR(address,
256
InterpreterRuntime::build_method_counters), method);
257
ldr(mcs, Address(method, Method::method_counters_offset()));
258
cbz(mcs, skip); // No MethodCounters allocated, OutOfMemory
259
bind(has_counters);
260
}
261
262
// Load object from cpool->resolved_references(index)
263
void InterpreterMacroAssembler::load_resolved_reference_at_index(
264
Register result, Register index) {
265
assert_different_registers(result, index);
266
// convert from field index to resolved_references() index and from
267
// word index to byte offset. Since this is a java object, it can be compressed
268
Register tmp = index; // reuse
269
lslw(tmp, tmp, LogBytesPerHeapOop);
270
271
get_constant_pool(result);
272
// load pointer for resolved_references[] objArray
273
ldr(result, Address(result, ConstantPool::resolved_references_offset_in_bytes()));
274
// JNIHandles::resolve(obj);
275
ldr(result, Address(result, 0));
276
// Add in the index
277
add(result, result, tmp);
278
load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
279
}
280
281
// Generate a subtype check: branch to ok_is_subtype if sub_klass is a
282
// subtype of super_klass.
283
//
284
// Args:
285
// r0: superklass
286
// Rsub_klass: subklass
287
//
288
// Kills:
289
// r2, r5
290
void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
291
Label& ok_is_subtype) {
292
assert(Rsub_klass != r0, "r0 holds superklass");
293
assert(Rsub_klass != r2, "r2 holds 2ndary super array length");
294
assert(Rsub_klass != r5, "r5 holds 2ndary super array scan ptr");
295
296
// Profile the not-null value's klass.
297
profile_typecheck(r2, Rsub_klass, r5); // blows r2, reloads r5
298
299
// Do the check.
300
check_klass_subtype(Rsub_klass, r0, r2, ok_is_subtype); // blows r2
301
302
// Profile the failure of the check.
303
profile_typecheck_failed(r2); // blows r2
304
}
305
306
// Java Expression Stack
307
308
void InterpreterMacroAssembler::pop_ptr(Register r) {
309
ldr(r, post(esp, wordSize));
310
}
311
312
void InterpreterMacroAssembler::pop_i(Register r) {
313
ldrw(r, post(esp, wordSize));
314
}
315
316
void InterpreterMacroAssembler::pop_l(Register r) {
317
ldr(r, post(esp, 2 * Interpreter::stackElementSize));
318
}
319
320
void InterpreterMacroAssembler::push_ptr(Register r) {
321
str(r, pre(esp, -wordSize));
322
}
323
324
void InterpreterMacroAssembler::push_i(Register r) {
325
str(r, pre(esp, -wordSize));
326
}
327
328
void InterpreterMacroAssembler::push_l(Register r) {
329
str(r, pre(esp, 2 * -wordSize));
330
}
331
332
void InterpreterMacroAssembler::pop_f(FloatRegister r) {
333
ldrs(r, post(esp, wordSize));
334
}
335
336
void InterpreterMacroAssembler::pop_d(FloatRegister r) {
337
ldrd(r, post(esp, 2 * Interpreter::stackElementSize));
338
}
339
340
void InterpreterMacroAssembler::push_f(FloatRegister r) {
341
strs(r, pre(esp, -wordSize));
342
}
343
344
void InterpreterMacroAssembler::push_d(FloatRegister r) {
345
strd(r, pre(esp, 2* -wordSize));
346
}
347
348
void InterpreterMacroAssembler::pop(TosState state) {
349
switch (state) {
350
case atos: pop_ptr(); break;
351
case btos:
352
case ztos:
353
case ctos:
354
case stos:
355
case itos: pop_i(); break;
356
case ltos: pop_l(); break;
357
case ftos: pop_f(); break;
358
case dtos: pop_d(); break;
359
case vtos: /* nothing to do */ break;
360
default: ShouldNotReachHere();
361
}
362
verify_oop(r0, state);
363
}
364
365
void InterpreterMacroAssembler::push(TosState state) {
366
verify_oop(r0, state);
367
switch (state) {
368
case atos: push_ptr(); break;
369
case btos:
370
case ztos:
371
case ctos:
372
case stos:
373
case itos: push_i(); break;
374
case ltos: push_l(); break;
375
case ftos: push_f(); break;
376
case dtos: push_d(); break;
377
case vtos: /* nothing to do */ break;
378
default : ShouldNotReachHere();
379
}
380
}
381
382
// Helpers for swap and dup
383
void InterpreterMacroAssembler::load_ptr(int n, Register val) {
384
ldr(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
385
}
386
387
void InterpreterMacroAssembler::store_ptr(int n, Register val) {
388
str(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
389
}
390
391
392
void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
393
// set sender sp
394
mov(r13, sp);
395
// record last_sp
396
str(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
397
}
398
399
// Jump to from_interpreted entry of a call unless single stepping is possible
400
// in this thread in which case we must call the i2i entry
401
void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
402
prepare_to_jump_from_interpreted();
403
404
if (JvmtiExport::can_post_interpreter_events()) {
405
Label run_compiled_code;
406
// JVMTI events, such as single-stepping, are implemented partly by avoiding running
407
// compiled code in threads for which the event is enabled. Check here for
408
// interp_only_mode if these events CAN be enabled.
409
// interp_only is an int, on little endian it is sufficient to test the byte only
410
// Is a cmpl faster?
411
ldr(rscratch1, Address(rthread, JavaThread::interp_only_mode_offset()));
412
cbz(rscratch1, run_compiled_code);
413
ldr(rscratch1, Address(method, Method::interpreter_entry_offset()));
414
br(rscratch1);
415
bind(run_compiled_code);
416
}
417
418
ldr(rscratch1, Address(method, Method::from_interpreted_offset()));
419
br(rscratch1);
420
}
421
422
// The following two routines provide a hook so that an implementation
423
// can schedule the dispatch in two parts. amd64 does not do this.
424
void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
425
}
426
427
void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
428
dispatch_next(state, step);
429
}
430
431
void InterpreterMacroAssembler::dispatch_base(TosState state,
432
address* table,
433
bool verifyoop) {
434
if (VerifyActivationFrameSize) {
435
Unimplemented();
436
}
437
if (verifyoop) {
438
verify_oop(r0, state);
439
}
440
if (table == Interpreter::dispatch_table(state)) {
441
addw(rscratch2, rscratch1, Interpreter::distance_from_dispatch_table(state));
442
ldr(rscratch2, Address(rdispatch, rscratch2, Address::uxtw(3)));
443
} else {
444
mov(rscratch2, (address)table);
445
ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3)));
446
}
447
br(rscratch2);
448
}
449
450
void InterpreterMacroAssembler::dispatch_only(TosState state) {
451
dispatch_base(state, Interpreter::dispatch_table(state));
452
}
453
454
void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
455
dispatch_base(state, Interpreter::normal_table(state));
456
}
457
458
void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
459
dispatch_base(state, Interpreter::normal_table(state), false);
460
}
461
462
463
void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
464
// load next bytecode
465
ldrb(rscratch1, Address(pre(rbcp, step)));
466
dispatch_base(state, Interpreter::dispatch_table(state));
467
}
468
469
void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
470
// load current bytecode
471
ldrb(rscratch1, Address(rbcp, 0));
472
dispatch_base(state, table);
473
}
474
475
// remove activation
476
//
477
// Unlock the receiver if this is a synchronized method.
478
// Unlock any Java monitors from syncronized blocks.
479
// Remove the activation from the stack.
480
//
481
// If there are locked Java monitors
482
// If throw_monitor_exception
483
// throws IllegalMonitorStateException
484
// Else if install_monitor_exception
485
// installs IllegalMonitorStateException
486
// Else
487
// no error processing
488
void InterpreterMacroAssembler::remove_activation(
489
TosState state,
490
bool throw_monitor_exception,
491
bool install_monitor_exception,
492
bool notify_jvmdi) {
493
// Note: Registers r3 xmm0 may be in use for the
494
// result check if synchronized method
495
Label unlocked, unlock, no_unlock;
496
497
// get the value of _do_not_unlock_if_synchronized into r3
498
const Address do_not_unlock_if_synchronized(rthread,
499
in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
500
ldrb(r3, do_not_unlock_if_synchronized);
501
strb(zr, do_not_unlock_if_synchronized); // reset the flag
502
503
// get method access flags
504
ldr(r1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
505
ldr(r2, Address(r1, Method::access_flags_offset()));
506
tst(r2, JVM_ACC_SYNCHRONIZED);
507
br(Assembler::EQ, unlocked);
508
509
// Don't unlock anything if the _do_not_unlock_if_synchronized flag
510
// is set.
511
cbnz(r3, no_unlock);
512
513
// unlock monitor
514
push(state); // save result
515
516
// BasicObjectLock will be first in list, since this is a
517
// synchronized method. However, need to check that the object has
518
// not been unlocked by an explicit monitorexit bytecode.
519
const Address monitor(rfp, frame::interpreter_frame_initial_sp_offset *
520
wordSize - (int) sizeof(BasicObjectLock));
521
// We use c_rarg1 so that if we go slow path it will be the correct
522
// register for unlock_object to pass to VM directly
523
lea(c_rarg1, monitor); // address of first monitor
524
525
ldr(r0, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
526
cbnz(r0, unlock);
527
528
pop(state);
529
if (throw_monitor_exception) {
530
// Entry already unlocked, need to throw exception
531
call_VM(noreg, CAST_FROM_FN_PTR(address,
532
InterpreterRuntime::throw_illegal_monitor_state_exception));
533
should_not_reach_here();
534
} else {
535
// Monitor already unlocked during a stack unroll. If requested,
536
// install an illegal_monitor_state_exception. Continue with
537
// stack unrolling.
538
if (install_monitor_exception) {
539
call_VM(noreg, CAST_FROM_FN_PTR(address,
540
InterpreterRuntime::new_illegal_monitor_state_exception));
541
}
542
b(unlocked);
543
}
544
545
bind(unlock);
546
unlock_object(c_rarg1);
547
pop(state);
548
549
// Check that for block-structured locking (i.e., that all locked
550
// objects has been unlocked)
551
bind(unlocked);
552
553
// r0: Might contain return value
554
555
// Check that all monitors are unlocked
556
{
557
Label loop, exception, entry, restart;
558
const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
559
const Address monitor_block_top(
560
rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
561
const Address monitor_block_bot(
562
rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
563
564
bind(restart);
565
// We use c_rarg1 so that if we go slow path it will be the correct
566
// register for unlock_object to pass to VM directly
567
ldr(c_rarg1, monitor_block_top); // points to current entry, starting
568
// with top-most entry
569
lea(r19, monitor_block_bot); // points to word before bottom of
570
// monitor block
571
b(entry);
572
573
// Entry already locked, need to throw exception
574
bind(exception);
575
576
if (throw_monitor_exception) {
577
// Throw exception
578
MacroAssembler::call_VM(noreg,
579
CAST_FROM_FN_PTR(address, InterpreterRuntime::
580
throw_illegal_monitor_state_exception));
581
should_not_reach_here();
582
} else {
583
// Stack unrolling. Unlock object and install illegal_monitor_exception.
584
// Unlock does not block, so don't have to worry about the frame.
585
// We don't have to preserve c_rarg1 since we are going to throw an exception.
586
587
push(state);
588
unlock_object(c_rarg1);
589
pop(state);
590
591
if (install_monitor_exception) {
592
call_VM(noreg, CAST_FROM_FN_PTR(address,
593
InterpreterRuntime::
594
new_illegal_monitor_state_exception));
595
}
596
597
b(restart);
598
}
599
600
bind(loop);
601
// check if current entry is used
602
ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
603
cbnz(rscratch1, exception);
604
605
add(c_rarg1, c_rarg1, entry_size); // otherwise advance to next entry
606
bind(entry);
607
cmp(c_rarg1, r19); // check if bottom reached
608
br(Assembler::NE, loop); // if not at bottom then check this entry
609
}
610
611
bind(no_unlock);
612
613
// jvmti support
614
if (notify_jvmdi) {
615
notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
616
} else {
617
notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
618
}
619
620
// remove activation
621
// get sender esp
622
ldr(esp,
623
Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
624
// remove frame anchor
625
leave();
626
// If we're returning to interpreted code we will shortly be
627
// adjusting SP to allow some space for ESP. If we're returning to
628
// compiled code the saved sender SP was saved in sender_sp, so this
629
// restores it.
630
andr(sp, esp, -16);
631
}
632
633
#endif // C_INTERP
634
635
// Lock object
636
//
637
// Args:
638
// c_rarg1: BasicObjectLock to be used for locking
639
//
640
// Kills:
641
// r0
642
// c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
643
// rscratch1, rscratch2 (scratch regs)
644
void InterpreterMacroAssembler::lock_object(Register lock_reg)
645
{
646
assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
647
if (UseHeavyMonitors) {
648
call_VM(noreg,
649
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
650
lock_reg);
651
} else {
652
Label done;
653
654
const Register swap_reg = r0;
655
const Register tmp = c_rarg2;
656
const Register obj_reg = c_rarg3; // Will contain the oop
657
658
const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
659
const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
660
const int mark_offset = lock_offset +
661
BasicLock::displaced_header_offset_in_bytes();
662
663
Label slow_case;
664
665
// Load object pointer into obj_reg %c_rarg3
666
ldr(obj_reg, Address(lock_reg, obj_offset));
667
668
if (UseBiasedLocking) {
669
biased_locking_enter(lock_reg, obj_reg, swap_reg, tmp, false, done, &slow_case);
670
}
671
672
// Load (object->mark() | 1) into swap_reg
673
ldr(rscratch1, Address(obj_reg, 0));
674
orr(swap_reg, rscratch1, 1);
675
676
// Save (object->mark() | 1) into BasicLock's displaced header
677
str(swap_reg, Address(lock_reg, mark_offset));
678
679
assert(lock_offset == 0,
680
"displached header must be first word in BasicObjectLock");
681
682
Label fail;
683
if (PrintBiasedLockingStatistics) {
684
Label fast;
685
cmpxchgptr(swap_reg, lock_reg, obj_reg, rscratch1, fast, &fail);
686
bind(fast);
687
atomic_incw(Address((address)BiasedLocking::fast_path_entry_count_addr()),
688
rscratch2, rscratch1, tmp);
689
b(done);
690
bind(fail);
691
} else {
692
cmpxchgptr(swap_reg, lock_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
693
}
694
695
// Test if the oopMark is an obvious stack pointer, i.e.,
696
// 1) (mark & 7) == 0, and
697
// 2) rsp <= mark < mark + os::pagesize()
698
//
699
// These 3 tests can be done by evaluating the following
700
// expression: ((mark - rsp) & (7 - os::vm_page_size())),
701
// assuming both stack pointer and pagesize have their
702
// least significant 3 bits clear.
703
// NOTE: the oopMark is in swap_reg %r0 as the result of cmpxchg
704
// NOTE2: aarch64 does not like to subtract sp from rn so take a
705
// copy
706
mov(rscratch1, sp);
707
sub(swap_reg, swap_reg, rscratch1);
708
ands(swap_reg, swap_reg, (unsigned long)(7 - os::vm_page_size()));
709
710
// Save the test result, for recursive case, the result is zero
711
str(swap_reg, Address(lock_reg, mark_offset));
712
713
if (PrintBiasedLockingStatistics) {
714
br(Assembler::NE, slow_case);
715
atomic_incw(Address((address)BiasedLocking::fast_path_entry_count_addr()),
716
rscratch2, rscratch1, tmp);
717
}
718
br(Assembler::EQ, done);
719
720
bind(slow_case);
721
722
// Call the runtime routine for slow case
723
call_VM(noreg,
724
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
725
lock_reg);
726
727
bind(done);
728
}
729
}
730
731
732
// Unlocks an object. Used in monitorexit bytecode and
733
// remove_activation. Throws an IllegalMonitorException if object is
734
// not locked by current thread.
735
//
736
// Args:
737
// c_rarg1: BasicObjectLock for lock
738
//
739
// Kills:
740
// r0
741
// c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
742
// rscratch1, rscratch2 (scratch regs)
743
void InterpreterMacroAssembler::unlock_object(Register lock_reg)
744
{
745
assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
746
747
if (UseHeavyMonitors) {
748
call_VM(noreg,
749
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
750
lock_reg);
751
} else {
752
Label done;
753
754
const Register swap_reg = r0;
755
const Register header_reg = c_rarg2; // Will contain the old oopMark
756
const Register obj_reg = c_rarg3; // Will contain the oop
757
758
save_bcp(); // Save in case of exception
759
760
// Convert from BasicObjectLock structure to object and BasicLock
761
// structure Store the BasicLock address into %r0
762
lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
763
764
// Load oop into obj_reg(%c_rarg3)
765
ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
766
767
// Free entry
768
str(zr, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
769
770
if (UseBiasedLocking) {
771
biased_locking_exit(obj_reg, header_reg, done);
772
}
773
774
// Load the old header from BasicLock structure
775
ldr(header_reg, Address(swap_reg,
776
BasicLock::displaced_header_offset_in_bytes()));
777
778
// Test for recursion
779
cbz(header_reg, done);
780
781
// Atomic swap back the old header
782
cmpxchgptr(swap_reg, header_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
783
784
// Call the runtime routine for slow case.
785
str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); // restore obj
786
call_VM(noreg,
787
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
788
lock_reg);
789
790
bind(done);
791
792
restore_bcp();
793
}
794
}
795
796
#ifndef CC_INTERP
797
798
void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
799
Label& zero_continue) {
800
assert(ProfileInterpreter, "must be profiling interpreter");
801
ldr(mdp, Address(rfp, frame::interpreter_frame_mdx_offset * wordSize));
802
cbz(mdp, zero_continue);
803
}
804
805
// Set the method data pointer for the current bcp.
806
void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
807
assert(ProfileInterpreter, "must be profiling interpreter");
808
Label set_mdp;
809
stp(r0, r1, Address(pre(sp, -2 * wordSize)));
810
811
// Test MDO to avoid the call if it is NULL.
812
ldr(r0, Address(rmethod, in_bytes(Method::method_data_offset())));
813
cbz(r0, set_mdp);
814
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rmethod, rbcp);
815
// r0: mdi
816
// mdo is guaranteed to be non-zero here, we checked for it before the call.
817
ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset())));
818
lea(r1, Address(r1, in_bytes(MethodData::data_offset())));
819
add(r0, r1, r0);
820
str(r0, Address(rfp, frame::interpreter_frame_mdx_offset * wordSize));
821
bind(set_mdp);
822
ldp(r0, r1, Address(post(sp, 2 * wordSize)));
823
}
824
825
void InterpreterMacroAssembler::verify_method_data_pointer() {
826
assert(ProfileInterpreter, "must be profiling interpreter");
827
#ifdef ASSERT
828
Label verify_continue;
829
stp(r0, r1, Address(pre(sp, -2 * wordSize)));
830
stp(r2, r3, Address(pre(sp, -2 * wordSize)));
831
test_method_data_pointer(r3, verify_continue); // If mdp is zero, continue
832
get_method(r1);
833
834
// If the mdp is valid, it will point to a DataLayout header which is
835
// consistent with the bcp. The converse is highly probable also.
836
ldrsh(r2, Address(r3, in_bytes(DataLayout::bci_offset())));
837
ldr(rscratch1, Address(r1, Method::const_offset()));
838
add(r2, r2, rscratch1, Assembler::LSL);
839
lea(r2, Address(r2, ConstMethod::codes_offset()));
840
cmp(r2, rbcp);
841
br(Assembler::EQ, verify_continue);
842
// r1: method
843
// rbcp: bcp // rbcp == 22
844
// r3: mdp
845
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
846
r1, rbcp, r3);
847
bind(verify_continue);
848
ldp(r2, r3, Address(post(sp, 2 * wordSize)));
849
ldp(r0, r1, Address(post(sp, 2 * wordSize)));
850
#endif // ASSERT
851
}
852
853
854
void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
855
int constant,
856
Register value) {
857
assert(ProfileInterpreter, "must be profiling interpreter");
858
Address data(mdp_in, constant);
859
str(value, data);
860
}
861
862
863
void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
864
int constant,
865
bool decrement) {
866
increment_mdp_data_at(mdp_in, noreg, constant, decrement);
867
}
868
869
void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
870
Register reg,
871
int constant,
872
bool decrement) {
873
assert(ProfileInterpreter, "must be profiling interpreter");
874
// %%% this does 64bit counters at best it is wasting space
875
// at worst it is a rare bug when counters overflow
876
877
assert_different_registers(rscratch2, rscratch1, mdp_in, reg);
878
879
Address addr1(mdp_in, constant);
880
Address addr2(rscratch2, reg, Address::lsl(0));
881
Address &addr = addr1;
882
if (reg != noreg) {
883
lea(rscratch2, addr1);
884
addr = addr2;
885
}
886
887
if (decrement) {
888
// Decrement the register. Set condition codes.
889
// Intel does this
890
// addptr(data, (int32_t) -DataLayout::counter_increment);
891
// If the decrement causes the counter to overflow, stay negative
892
// Label L;
893
// jcc(Assembler::negative, L);
894
// addptr(data, (int32_t) DataLayout::counter_increment);
895
// so we do this
896
ldr(rscratch1, addr);
897
subs(rscratch1, rscratch1, (unsigned)DataLayout::counter_increment);
898
Label L;
899
br(Assembler::LO, L); // skip store if counter overflow
900
str(rscratch1, addr);
901
bind(L);
902
} else {
903
assert(DataLayout::counter_increment == 1,
904
"flow-free idiom only works with 1");
905
// Intel does this
906
// Increment the register. Set carry flag.
907
// addptr(data, DataLayout::counter_increment);
908
// If the increment causes the counter to overflow, pull back by 1.
909
// sbbptr(data, (int32_t)0);
910
// so we do this
911
ldr(rscratch1, addr);
912
adds(rscratch1, rscratch1, DataLayout::counter_increment);
913
Label L;
914
br(Assembler::CS, L); // skip store if counter overflow
915
str(rscratch1, addr);
916
bind(L);
917
}
918
}
919
920
void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
921
int flag_byte_constant) {
922
assert(ProfileInterpreter, "must be profiling interpreter");
923
int header_offset = in_bytes(DataLayout::header_offset());
924
int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
925
// Set the flag
926
ldr(rscratch1, Address(mdp_in, header_offset));
927
orr(rscratch1, rscratch1, header_bits);
928
str(rscratch1, Address(mdp_in, header_offset));
929
}
930
931
932
void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
933
int offset,
934
Register value,
935
Register test_value_out,
936
Label& not_equal_continue) {
937
assert(ProfileInterpreter, "must be profiling interpreter");
938
if (test_value_out == noreg) {
939
ldr(rscratch1, Address(mdp_in, offset));
940
cmp(value, rscratch1);
941
} else {
942
// Put the test value into a register, so caller can use it:
943
ldr(test_value_out, Address(mdp_in, offset));
944
cmp(value, test_value_out);
945
}
946
br(Assembler::NE, not_equal_continue);
947
}
948
949
950
void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
951
int offset_of_disp) {
952
assert(ProfileInterpreter, "must be profiling interpreter");
953
ldr(rscratch1, Address(mdp_in, offset_of_disp));
954
add(mdp_in, mdp_in, rscratch1, LSL);
955
str(mdp_in, Address(rfp, frame::interpreter_frame_mdx_offset * wordSize));
956
}
957
958
959
void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
960
Register reg,
961
int offset_of_disp) {
962
assert(ProfileInterpreter, "must be profiling interpreter");
963
lea(rscratch1, Address(mdp_in, offset_of_disp));
964
ldr(rscratch1, Address(rscratch1, reg, Address::lsl(0)));
965
add(mdp_in, mdp_in, rscratch1, LSL);
966
str(mdp_in, Address(rfp, frame::interpreter_frame_mdx_offset * wordSize));
967
}
968
969
970
void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
971
int constant) {
972
assert(ProfileInterpreter, "must be profiling interpreter");
973
add(mdp_in, mdp_in, (unsigned)constant);
974
str(mdp_in, Address(rfp, frame::interpreter_frame_mdx_offset * wordSize));
975
}
976
977
978
void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
979
assert(ProfileInterpreter, "must be profiling interpreter");
980
// save/restore across call_VM
981
stp(zr, return_bci, Address(pre(sp, -2 * wordSize)));
982
call_VM(noreg,
983
CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
984
return_bci);
985
ldp(zr, return_bci, Address(post(sp, 2 * wordSize)));
986
}
987
988
989
void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
990
Register bumped_count) {
991
if (ProfileInterpreter) {
992
Label profile_continue;
993
994
// If no method data exists, go to profile_continue.
995
// Otherwise, assign to mdp
996
test_method_data_pointer(mdp, profile_continue);
997
998
// We are taking a branch. Increment the taken count.
999
// We inline increment_mdp_data_at to return bumped_count in a register
1000
//increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1001
Address data(mdp, in_bytes(JumpData::taken_offset()));
1002
ldr(bumped_count, data);
1003
assert(DataLayout::counter_increment == 1,
1004
"flow-free idiom only works with 1");
1005
// Intel does this to catch overflow
1006
// addptr(bumped_count, DataLayout::counter_increment);
1007
// sbbptr(bumped_count, 0);
1008
// so we do this
1009
adds(bumped_count, bumped_count, DataLayout::counter_increment);
1010
Label L;
1011
br(Assembler::CS, L); // skip store if counter overflow
1012
str(bumped_count, data);
1013
bind(L);
1014
// The method data pointer needs to be updated to reflect the new target.
1015
update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1016
bind(profile_continue);
1017
}
1018
}
1019
1020
1021
void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1022
if (ProfileInterpreter) {
1023
Label profile_continue;
1024
1025
// If no method data exists, go to profile_continue.
1026
test_method_data_pointer(mdp, profile_continue);
1027
1028
// We are taking a branch. Increment the not taken count.
1029
increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1030
1031
// The method data pointer needs to be updated to correspond to
1032
// the next bytecode
1033
update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1034
bind(profile_continue);
1035
}
1036
}
1037
1038
1039
void InterpreterMacroAssembler::profile_call(Register mdp) {
1040
if (ProfileInterpreter) {
1041
Label profile_continue;
1042
1043
// If no method data exists, go to profile_continue.
1044
test_method_data_pointer(mdp, profile_continue);
1045
1046
// We are making a call. Increment the count.
1047
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1048
1049
// The method data pointer needs to be updated to reflect the new target.
1050
update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1051
bind(profile_continue);
1052
}
1053
}
1054
1055
void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1056
if (ProfileInterpreter) {
1057
Label profile_continue;
1058
1059
// If no method data exists, go to profile_continue.
1060
test_method_data_pointer(mdp, profile_continue);
1061
1062
// We are making a call. Increment the count.
1063
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1064
1065
// The method data pointer needs to be updated to reflect the new target.
1066
update_mdp_by_constant(mdp,
1067
in_bytes(VirtualCallData::
1068
virtual_call_data_size()));
1069
bind(profile_continue);
1070
}
1071
}
1072
1073
1074
void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1075
Register mdp,
1076
Register reg2,
1077
bool receiver_can_be_null) {
1078
if (ProfileInterpreter) {
1079
Label profile_continue;
1080
1081
// If no method data exists, go to profile_continue.
1082
test_method_data_pointer(mdp, profile_continue);
1083
1084
Label skip_receiver_profile;
1085
if (receiver_can_be_null) {
1086
Label not_null;
1087
// We are making a call. Increment the count for null receiver.
1088
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1089
b(skip_receiver_profile);
1090
bind(not_null);
1091
}
1092
1093
// Record the receiver type.
1094
record_klass_in_profile(receiver, mdp, reg2, true);
1095
bind(skip_receiver_profile);
1096
1097
// The method data pointer needs to be updated to reflect the new target.
1098
update_mdp_by_constant(mdp,
1099
in_bytes(VirtualCallData::
1100
virtual_call_data_size()));
1101
bind(profile_continue);
1102
}
1103
}
1104
1105
// This routine creates a state machine for updating the multi-row
1106
// type profile at a virtual call site (or other type-sensitive bytecode).
1107
// The machine visits each row (of receiver/count) until the receiver type
1108
// is found, or until it runs out of rows. At the same time, it remembers
1109
// the location of the first empty row. (An empty row records null for its
1110
// receiver, and can be allocated for a newly-observed receiver type.)
1111
// Because there are two degrees of freedom in the state, a simple linear
1112
// search will not work; it must be a decision tree. Hence this helper
1113
// function is recursive, to generate the required tree structured code.
1114
// It's the interpreter, so we are trading off code space for speed.
1115
// See below for example code.
1116
void InterpreterMacroAssembler::record_klass_in_profile_helper(
1117
Register receiver, Register mdp,
1118
Register reg2, int start_row,
1119
Label& done, bool is_virtual_call) {
1120
if (TypeProfileWidth == 0) {
1121
if (is_virtual_call) {
1122
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1123
}
1124
return;
1125
}
1126
1127
int last_row = VirtualCallData::row_limit() - 1;
1128
assert(start_row <= last_row, "must be work left to do");
1129
// Test this row for both the receiver and for null.
1130
// Take any of three different outcomes:
1131
// 1. found receiver => increment count and goto done
1132
// 2. found null => keep looking for case 1, maybe allocate this cell
1133
// 3. found something else => keep looking for cases 1 and 2
1134
// Case 3 is handled by a recursive call.
1135
for (int row = start_row; row <= last_row; row++) {
1136
Label next_test;
1137
bool test_for_null_also = (row == start_row);
1138
1139
// See if the receiver is receiver[n].
1140
int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1141
test_mdp_data_at(mdp, recvr_offset, receiver,
1142
(test_for_null_also ? reg2 : noreg),
1143
next_test);
1144
// (Reg2 now contains the receiver from the CallData.)
1145
1146
// The receiver is receiver[n]. Increment count[n].
1147
int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1148
increment_mdp_data_at(mdp, count_offset);
1149
b(done);
1150
bind(next_test);
1151
1152
if (test_for_null_also) {
1153
Label found_null;
1154
// Failed the equality check on receiver[n]... Test for null.
1155
if (start_row == last_row) {
1156
// The only thing left to do is handle the null case.
1157
if (is_virtual_call) {
1158
cbz(reg2, found_null);
1159
// Receiver did not match any saved receiver and there is no empty row for it.
1160
// Increment total counter to indicate polymorphic case.
1161
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1162
b(done);
1163
bind(found_null);
1164
} else {
1165
cbnz(reg2, done);
1166
}
1167
break;
1168
}
1169
// Since null is rare, make it be the branch-taken case.
1170
cbz(reg2, found_null);
1171
1172
// Put all the "Case 3" tests here.
1173
record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
1174
1175
// Found a null. Keep searching for a matching receiver,
1176
// but remember that this is an empty (unused) slot.
1177
bind(found_null);
1178
}
1179
}
1180
1181
// In the fall-through case, we found no matching receiver, but we
1182
// observed the receiver[start_row] is NULL.
1183
1184
// Fill in the receiver field and increment the count.
1185
int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1186
set_mdp_data_at(mdp, recvr_offset, receiver);
1187
int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1188
mov(reg2, DataLayout::counter_increment);
1189
set_mdp_data_at(mdp, count_offset, reg2);
1190
if (start_row > 0) {
1191
b(done);
1192
}
1193
}
1194
1195
// Example state machine code for three profile rows:
1196
// // main copy of decision tree, rooted at row[1]
1197
// if (row[0].rec == rec) { row[0].incr(); goto done; }
1198
// if (row[0].rec != NULL) {
1199
// // inner copy of decision tree, rooted at row[1]
1200
// if (row[1].rec == rec) { row[1].incr(); goto done; }
1201
// if (row[1].rec != NULL) {
1202
// // degenerate decision tree, rooted at row[2]
1203
// if (row[2].rec == rec) { row[2].incr(); goto done; }
1204
// if (row[2].rec != NULL) { count.incr(); goto done; } // overflow
1205
// row[2].init(rec); goto done;
1206
// } else {
1207
// // remember row[1] is empty
1208
// if (row[2].rec == rec) { row[2].incr(); goto done; }
1209
// row[1].init(rec); goto done;
1210
// }
1211
// } else {
1212
// // remember row[0] is empty
1213
// if (row[1].rec == rec) { row[1].incr(); goto done; }
1214
// if (row[2].rec == rec) { row[2].incr(); goto done; }
1215
// row[0].init(rec); goto done;
1216
// }
1217
// done:
1218
1219
void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1220
Register mdp, Register reg2,
1221
bool is_virtual_call) {
1222
assert(ProfileInterpreter, "must be profiling");
1223
Label done;
1224
1225
record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1226
1227
bind (done);
1228
}
1229
1230
void InterpreterMacroAssembler::profile_ret(Register return_bci,
1231
Register mdp) {
1232
if (ProfileInterpreter) {
1233
Label profile_continue;
1234
uint row;
1235
1236
// If no method data exists, go to profile_continue.
1237
test_method_data_pointer(mdp, profile_continue);
1238
1239
// Update the total ret count.
1240
increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1241
1242
for (row = 0; row < RetData::row_limit(); row++) {
1243
Label next_test;
1244
1245
// See if return_bci is equal to bci[n]:
1246
test_mdp_data_at(mdp,
1247
in_bytes(RetData::bci_offset(row)),
1248
return_bci, noreg,
1249
next_test);
1250
1251
// return_bci is equal to bci[n]. Increment the count.
1252
increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1253
1254
// The method data pointer needs to be updated to reflect the new target.
1255
update_mdp_by_offset(mdp,
1256
in_bytes(RetData::bci_displacement_offset(row)));
1257
b(profile_continue);
1258
bind(next_test);
1259
}
1260
1261
update_mdp_for_ret(return_bci);
1262
1263
bind(profile_continue);
1264
}
1265
}
1266
1267
void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1268
if (ProfileInterpreter) {
1269
Label profile_continue;
1270
1271
// If no method data exists, go to profile_continue.
1272
test_method_data_pointer(mdp, profile_continue);
1273
1274
set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1275
1276
// The method data pointer needs to be updated.
1277
int mdp_delta = in_bytes(BitData::bit_data_size());
1278
if (TypeProfileCasts) {
1279
mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1280
}
1281
update_mdp_by_constant(mdp, mdp_delta);
1282
1283
bind(profile_continue);
1284
}
1285
}
1286
1287
void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1288
if (ProfileInterpreter && TypeProfileCasts) {
1289
Label profile_continue;
1290
1291
// If no method data exists, go to profile_continue.
1292
test_method_data_pointer(mdp, profile_continue);
1293
1294
int count_offset = in_bytes(CounterData::count_offset());
1295
// Back up the address, since we have already bumped the mdp.
1296
count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1297
1298
// *Decrement* the counter. We expect to see zero or small negatives.
1299
increment_mdp_data_at(mdp, count_offset, true);
1300
1301
bind (profile_continue);
1302
}
1303
}
1304
1305
void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1306
if (ProfileInterpreter) {
1307
Label profile_continue;
1308
1309
// If no method data exists, go to profile_continue.
1310
test_method_data_pointer(mdp, profile_continue);
1311
1312
// The method data pointer needs to be updated.
1313
int mdp_delta = in_bytes(BitData::bit_data_size());
1314
if (TypeProfileCasts) {
1315
mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1316
1317
// Record the object type.
1318
record_klass_in_profile(klass, mdp, reg2, false);
1319
}
1320
update_mdp_by_constant(mdp, mdp_delta);
1321
1322
bind(profile_continue);
1323
}
1324
}
1325
1326
void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1327
if (ProfileInterpreter) {
1328
Label profile_continue;
1329
1330
// If no method data exists, go to profile_continue.
1331
test_method_data_pointer(mdp, profile_continue);
1332
1333
// Update the default case count
1334
increment_mdp_data_at(mdp,
1335
in_bytes(MultiBranchData::default_count_offset()));
1336
1337
// The method data pointer needs to be updated.
1338
update_mdp_by_offset(mdp,
1339
in_bytes(MultiBranchData::
1340
default_displacement_offset()));
1341
1342
bind(profile_continue);
1343
}
1344
}
1345
1346
void InterpreterMacroAssembler::profile_switch_case(Register index,
1347
Register mdp,
1348
Register reg2) {
1349
if (ProfileInterpreter) {
1350
Label profile_continue;
1351
1352
// If no method data exists, go to profile_continue.
1353
test_method_data_pointer(mdp, profile_continue);
1354
1355
// Build the base (index * per_case_size_in_bytes()) +
1356
// case_array_offset_in_bytes()
1357
movw(reg2, in_bytes(MultiBranchData::per_case_size()));
1358
movw(rscratch1, in_bytes(MultiBranchData::case_array_offset()));
1359
Assembler::maddw(index, index, reg2, rscratch1);
1360
1361
// Update the case count
1362
increment_mdp_data_at(mdp,
1363
index,
1364
in_bytes(MultiBranchData::relative_count_offset()));
1365
1366
// The method data pointer needs to be updated.
1367
update_mdp_by_offset(mdp,
1368
index,
1369
in_bytes(MultiBranchData::
1370
relative_displacement_offset()));
1371
1372
bind(profile_continue);
1373
}
1374
}
1375
1376
void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1377
if (state == atos) {
1378
MacroAssembler::verify_oop(reg);
1379
}
1380
}
1381
1382
void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { ; }
1383
#endif // !CC_INTERP
1384
1385
1386
void InterpreterMacroAssembler::notify_method_entry() {
1387
// Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1388
// track stack depth. If it is possible to enter interp_only_mode we add
1389
// the code to check if the event should be sent.
1390
if (JvmtiExport::can_post_interpreter_events()) {
1391
Label L;
1392
ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1393
cbzw(r3, L);
1394
call_VM(noreg, CAST_FROM_FN_PTR(address,
1395
InterpreterRuntime::post_method_entry));
1396
bind(L);
1397
}
1398
1399
{
1400
SkipIfEqual skip(this, &DTraceMethodProbes, false);
1401
get_method(c_rarg1);
1402
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1403
rthread, c_rarg1);
1404
}
1405
1406
// RedefineClasses() tracing support for obsolete method entry
1407
if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1408
get_method(c_rarg1);
1409
call_VM_leaf(
1410
CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1411
rthread, c_rarg1);
1412
}
1413
1414
}
1415
1416
1417
void InterpreterMacroAssembler::notify_method_exit(
1418
TosState state, NotifyMethodExitMode mode) {
1419
// Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1420
// track stack depth. If it is possible to enter interp_only_mode we add
1421
// the code to check if the event should be sent.
1422
if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1423
Label L;
1424
// Note: frame::interpreter_frame_result has a dependency on how the
1425
// method result is saved across the call to post_method_exit. If this
1426
// is changed then the interpreter_frame_result implementation will
1427
// need to be updated too.
1428
1429
// For c++ interpreter the result is always stored at a known location in the frame
1430
// template interpreter will leave it on the top of the stack.
1431
NOT_CC_INTERP(push(state);)
1432
ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1433
cbz(r3, L);
1434
call_VM(noreg,
1435
CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1436
bind(L);
1437
NOT_CC_INTERP(pop(state));
1438
}
1439
1440
{
1441
SkipIfEqual skip(this, &DTraceMethodProbes, false);
1442
NOT_CC_INTERP(push(state));
1443
get_method(c_rarg1);
1444
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1445
rthread, c_rarg1);
1446
NOT_CC_INTERP(pop(state));
1447
}
1448
}
1449
1450
1451
// Jump if ((*counter_addr += increment) & mask) satisfies the condition.
1452
void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
1453
int increment, int mask,
1454
Register scratch, Register scratch2,
1455
bool preloaded,
1456
Condition cond, Label* where) {
1457
if (!preloaded) {
1458
ldrw(scratch, counter_addr);
1459
}
1460
add(scratch, scratch, increment);
1461
strw(scratch, counter_addr);
1462
if (operand_valid_for_logical_immediate(/*is32*/true, mask)) {
1463
andsw(scratch, scratch, mask);
1464
} else {
1465
movw(scratch2, (unsigned)mask);
1466
andsw(scratch, scratch, scratch2);
1467
}
1468
br(cond, *where);
1469
}
1470
1471
void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
1472
int number_of_arguments) {
1473
// interpreter specific
1474
//
1475
// Note: No need to save/restore rbcp & rlocals pointer since these
1476
// are callee saved registers and no blocking/ GC can happen
1477
// in leaf calls.
1478
#ifdef ASSERT
1479
{
1480
Label L;
1481
ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1482
cbz(rscratch1, L);
1483
stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1484
" last_sp != NULL");
1485
bind(L);
1486
}
1487
#endif /* ASSERT */
1488
// super call
1489
MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
1490
}
1491
1492
void InterpreterMacroAssembler::call_VM_base(Register oop_result,
1493
Register java_thread,
1494
Register last_java_sp,
1495
address entry_point,
1496
int number_of_arguments,
1497
bool check_exceptions) {
1498
// interpreter specific
1499
//
1500
// Note: Could avoid restoring locals ptr (callee saved) - however doesn't
1501
// really make a difference for these runtime calls, since they are
1502
// slow anyway. Btw., bcp must be saved/restored since it may change
1503
// due to GC.
1504
// assert(java_thread == noreg , "not expecting a precomputed java thread");
1505
save_bcp();
1506
#ifdef ASSERT
1507
{
1508
Label L;
1509
ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1510
cbz(rscratch1, L);
1511
stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1512
" last_sp != NULL");
1513
bind(L);
1514
}
1515
#endif /* ASSERT */
1516
// super call
1517
MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
1518
entry_point, number_of_arguments,
1519
check_exceptions);
1520
// interpreter specific
1521
restore_bcp();
1522
restore_locals();
1523
}
1524
1525
void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
1526
Label update, next, none;
1527
1528
verify_oop(obj);
1529
1530
cbnz(obj, update);
1531
orptr(mdo_addr, TypeEntries::null_seen);
1532
b(next);
1533
1534
bind(update);
1535
load_klass(obj, obj);
1536
1537
ldr(rscratch1, mdo_addr);
1538
eor(obj, obj, rscratch1);
1539
tst(obj, TypeEntries::type_klass_mask);
1540
br(Assembler::EQ, next); // klass seen before, nothing to
1541
// do. The unknown bit may have been
1542
// set already but no need to check.
1543
1544
tst(obj, TypeEntries::type_unknown);
1545
br(Assembler::NE, next); // already unknown. Nothing to do anymore.
1546
1547
ldr(rscratch1, mdo_addr);
1548
cbz(rscratch1, none);
1549
cmp(rscratch1, TypeEntries::null_seen);
1550
br(Assembler::EQ, none);
1551
// There is a chance that the checks above (re-reading profiling
1552
// data from memory) fail if another thread has just set the
1553
// profiling to this obj's klass
1554
ldr(rscratch1, mdo_addr);
1555
eor(obj, obj, rscratch1);
1556
tst(obj, TypeEntries::type_klass_mask);
1557
br(Assembler::EQ, next);
1558
1559
// different than before. Cannot keep accurate profile.
1560
orptr(mdo_addr, TypeEntries::type_unknown);
1561
b(next);
1562
1563
bind(none);
1564
// first time here. Set profile type.
1565
str(obj, mdo_addr);
1566
1567
bind(next);
1568
}
1569
1570
void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
1571
if (!ProfileInterpreter) {
1572
return;
1573
}
1574
1575
if (MethodData::profile_arguments() || MethodData::profile_return()) {
1576
Label profile_continue;
1577
1578
test_method_data_pointer(mdp, profile_continue);
1579
1580
int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1581
1582
ldrb(rscratch1, Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start));
1583
cmp(rscratch1, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
1584
br(Assembler::NE, profile_continue);
1585
1586
if (MethodData::profile_arguments()) {
1587
Label done;
1588
int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1589
1590
for (int i = 0; i < TypeProfileArgsLimit; i++) {
1591
if (i > 0 || MethodData::profile_return()) {
1592
// If return value type is profiled we may have no argument to profile
1593
ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1594
sub(tmp, tmp, i*TypeStackSlotEntries::per_arg_count());
1595
cmp(tmp, TypeStackSlotEntries::per_arg_count());
1596
add(rscratch1, mdp, off_to_args);
1597
br(Assembler::LT, done);
1598
}
1599
ldr(tmp, Address(callee, Method::const_offset()));
1600
load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
1601
// stack offset o (zero based) from the start of the argument
1602
// list, for n arguments translates into offset n - o - 1 from
1603
// the end of the argument list
1604
ldr(rscratch1, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))));
1605
sub(tmp, tmp, rscratch1);
1606
sub(tmp, tmp, 1);
1607
Address arg_addr = argument_address(tmp);
1608
ldr(tmp, arg_addr);
1609
1610
Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i)));
1611
profile_obj_type(tmp, mdo_arg_addr);
1612
1613
int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1614
off_to_args += to_add;
1615
}
1616
1617
if (MethodData::profile_return()) {
1618
ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1619
sub(tmp, tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
1620
}
1621
1622
add(rscratch1, mdp, off_to_args);
1623
bind(done);
1624
mov(mdp, rscratch1);
1625
1626
if (MethodData::profile_return()) {
1627
// We're right after the type profile for the last
1628
// argument. tmp is the number of cells left in the
1629
// CallTypeData/VirtualCallTypeData to reach its end. Non null
1630
// if there's a return to profile.
1631
assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
1632
add(mdp, mdp, tmp, LSL, exact_log2(DataLayout::cell_size));
1633
}
1634
str(mdp, Address(rfp, frame::interpreter_frame_mdx_offset * wordSize));
1635
} else {
1636
assert(MethodData::profile_return(), "either profile call args or call ret");
1637
update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
1638
}
1639
1640
// mdp points right after the end of the
1641
// CallTypeData/VirtualCallTypeData, right after the cells for the
1642
// return value type if there's one
1643
1644
bind(profile_continue);
1645
}
1646
}
1647
1648
void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
1649
assert_different_registers(mdp, ret, tmp, rbcp);
1650
if (ProfileInterpreter && MethodData::profile_return()) {
1651
Label profile_continue, done;
1652
1653
test_method_data_pointer(mdp, profile_continue);
1654
1655
if (MethodData::profile_return_jsr292_only()) {
1656
// If we don't profile all invoke bytecodes we must make sure
1657
// it's a bytecode we indeed profile. We can't go back to the
1658
// begining of the ProfileData we intend to update to check its
1659
// type because we're right after it and we don't known its
1660
// length
1661
Label do_profile;
1662
ldrb(rscratch1, Address(rbcp, 0));
1663
cmp(rscratch1, Bytecodes::_invokedynamic);
1664
br(Assembler::EQ, do_profile);
1665
cmp(rscratch1, Bytecodes::_invokehandle);
1666
br(Assembler::EQ, do_profile);
1667
get_method(tmp);
1668
ldrb(rscratch1, Address(tmp, Method::intrinsic_id_offset_in_bytes()));
1669
cmp(rscratch1, vmIntrinsics::_compiledLambdaForm);
1670
br(Assembler::NE, profile_continue);
1671
1672
bind(do_profile);
1673
}
1674
1675
Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
1676
mov(tmp, ret);
1677
profile_obj_type(tmp, mdo_ret_addr);
1678
1679
bind(profile_continue);
1680
}
1681
}
1682
1683
void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
1684
if (ProfileInterpreter && MethodData::profile_parameters()) {
1685
Label profile_continue, done;
1686
1687
test_method_data_pointer(mdp, profile_continue);
1688
1689
// Load the offset of the area within the MDO used for
1690
// parameters. If it's negative we're not profiling any parameters
1691
ldr(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
1692
cmp(tmp1, 0u);
1693
br(Assembler::LT, profile_continue);
1694
1695
// Compute a pointer to the area for parameters from the offset
1696
// and move the pointer to the slot for the last
1697
// parameters. Collect profiling from last parameter down.
1698
// mdo start + parameters offset + array length - 1
1699
add(mdp, mdp, tmp1);
1700
ldr(tmp1, Address(mdp, ArrayData::array_len_offset()));
1701
sub(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1702
1703
Label loop;
1704
bind(loop);
1705
1706
int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
1707
int type_base = in_bytes(ParametersTypeData::type_offset(0));
1708
int per_arg_scale = exact_log2(DataLayout::cell_size);
1709
add(rscratch1, mdp, off_base);
1710
add(rscratch2, mdp, type_base);
1711
1712
Address arg_off(rscratch1, tmp1, Address::lsl(per_arg_scale));
1713
Address arg_type(rscratch2, tmp1, Address::lsl(per_arg_scale));
1714
1715
// load offset on the stack from the slot for this parameter
1716
ldr(tmp2, arg_off);
1717
neg(tmp2, tmp2);
1718
// read the parameter from the local area
1719
ldr(tmp2, Address(rlocals, tmp2, Address::lsl(Interpreter::logStackElementSize)));
1720
1721
// profile the parameter
1722
profile_obj_type(tmp2, arg_type);
1723
1724
// go to next parameter
1725
subs(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1726
br(Assembler::GE, loop);
1727
1728
bind(profile_continue);
1729
}
1730
}
1731
1732