1 /*
2 * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2014, 2020, Red Hat Inc. 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 #include "precompiled.hpp"
27 #include "asm/macroAssembler.inline.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "compiler/compiler_globals.hpp"
30 #include "gc/shared/barrierSetAssembler.hpp"
31 #include "interpreter/bytecodeHistogram.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "interpreter/interpreterRuntime.hpp"
34 #include "interpreter/interp_masm.hpp"
35 #include "interpreter/templateInterpreterGenerator.hpp"
36 #include "interpreter/templateTable.hpp"
37 #include "interpreter/bytecodeTracer.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/arrayOop.hpp"
40 #include "oops/methodData.hpp"
41 #include "oops/method.hpp"
42 #include "oops/oop.inline.hpp"
43 #include "prims/jvmtiExport.hpp"
44 #include "prims/jvmtiThreadState.hpp"
45 #include "runtime/arguments.hpp"
46 #include "runtime/deoptimization.hpp"
47 #include "runtime/frame.inline.hpp"
48 #include "runtime/jniHandles.hpp"
49 #include "runtime/sharedRuntime.hpp"
50 #include "runtime/stubRoutines.hpp"
51 #include "runtime/synchronizer.hpp"
52 #include "runtime/timer.hpp"
53 #include "runtime/vframeArray.hpp"
54 #include "utilities/debug.hpp"
55 #include "utilities/powerOfTwo.hpp"
56 #include <sys/types.h>
57
58 #ifndef PRODUCT
59 #include "oops/method.hpp"
60 #endif // !PRODUCT
61
62 // Size of interpreter code. Increase if too small. Interpreter will
63 // fail with a guarantee ("not enough space for interpreter generation");
64 // if too small.
65 // Run with +PrintInterpreter to get the VM to print out the size.
66 // Max size with JVMTI
67 int TemplateInterpreter::InterpreterCodeSize = 200 * 1024;
68
69 #define __ _masm->
70
71 //-----------------------------------------------------------------------------
72
73 extern "C" void entry(CodeBuffer*);
74
75 //-----------------------------------------------------------------------------
76
generate_slow_signature_handler()77 address TemplateInterpreterGenerator::generate_slow_signature_handler() {
78 address entry = __ pc();
79
80 __ andr(esp, esp, -16);
81 __ mov(c_rarg3, esp);
82 // rmethod
83 // rlocals
84 // c_rarg3: first stack arg - wordSize
85
86 // adjust sp
87 __ sub(sp, c_rarg3, 18 * wordSize);
88 __ str(lr, Address(__ pre(sp, -2 * wordSize)));
89 __ call_VM(noreg,
90 CAST_FROM_FN_PTR(address,
91 InterpreterRuntime::slow_signature_handler),
92 rmethod, rlocals, c_rarg3);
93
94 // r0: result handler
95
96 // Stack layout:
97 // rsp: return address <- sp
98 // 1 garbage
99 // 8 integer args (if static first is unused)
100 // 1 float/double identifiers
101 // 8 double args
102 // stack args <- esp
103 // garbage
104 // expression stack bottom
105 // bcp (NULL)
106 // ...
107
108 // Restore LR
109 __ ldr(lr, Address(__ post(sp, 2 * wordSize)));
110
111 // Do FP first so we can use c_rarg3 as temp
112 __ ldrw(c_rarg3, Address(sp, 9 * wordSize)); // float/double identifiers
113
114 for (int i = 0; i < Argument::n_float_register_parameters_c; i++) {
115 const FloatRegister r = as_FloatRegister(i);
116
117 Label d, done;
118
119 __ tbnz(c_rarg3, i, d);
120 __ ldrs(r, Address(sp, (10 + i) * wordSize));
121 __ b(done);
122 __ bind(d);
123 __ ldrd(r, Address(sp, (10 + i) * wordSize));
124 __ bind(done);
125 }
126
127 // c_rarg0 contains the result from the call of
128 // InterpreterRuntime::slow_signature_handler so we don't touch it
129 // here. It will be loaded with the JNIEnv* later.
130 __ ldr(c_rarg1, Address(sp, 1 * wordSize));
131 for (int i = c_rarg2->encoding(); i <= c_rarg7->encoding(); i += 2) {
132 Register rm = as_Register(i), rn = as_Register(i+1);
133 __ ldp(rm, rn, Address(sp, i * wordSize));
134 }
135
136 __ add(sp, sp, 18 * wordSize);
137 __ ret(lr);
138
139 return entry;
140 }
141
142
143 //
144 // Various method entries
145 //
146
generate_math_entry(AbstractInterpreter::MethodKind kind)147 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
148 // rmethod: Method*
149 // r13: sender sp
150 // esp: args
151
152 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
153
154 // These don't need a safepoint check because they aren't virtually
155 // callable. We won't enter these intrinsics from compiled code.
156 // If in the future we added an intrinsic which was virtually callable
157 // we'd have to worry about how to safepoint so that this code is used.
158
159 // mathematical functions inlined by compiler
160 // (interpreter must provide identical implementation
161 // in order to avoid monotonicity bugs when switching
162 // from interpreter to compiler in the middle of some
163 // computation)
164 //
165 // stack:
166 // [ arg ] <-- esp
167 // [ arg ]
168 // retaddr in lr
169
170 address entry_point = NULL;
171 Register continuation = lr;
172 switch (kind) {
173 case Interpreter::java_lang_math_abs:
174 entry_point = __ pc();
175 __ ldrd(v0, Address(esp));
176 __ fabsd(v0, v0);
177 __ mov(sp, r13); // Restore caller's SP
178 break;
179 case Interpreter::java_lang_math_sqrt:
180 entry_point = __ pc();
181 __ ldrd(v0, Address(esp));
182 __ fsqrtd(v0, v0);
183 __ mov(sp, r13);
184 break;
185 case Interpreter::java_lang_math_sin :
186 case Interpreter::java_lang_math_cos :
187 case Interpreter::java_lang_math_tan :
188 case Interpreter::java_lang_math_log :
189 case Interpreter::java_lang_math_log10 :
190 case Interpreter::java_lang_math_exp :
191 entry_point = __ pc();
192 __ ldrd(v0, Address(esp));
193 __ mov(sp, r13);
194 __ mov(r19, lr);
195 continuation = r19; // The first callee-saved register
196 generate_transcendental_entry(kind, 1);
197 break;
198 case Interpreter::java_lang_math_pow :
199 entry_point = __ pc();
200 __ mov(r19, lr);
201 continuation = r19;
202 __ ldrd(v0, Address(esp, 2 * Interpreter::stackElementSize));
203 __ ldrd(v1, Address(esp));
204 __ mov(sp, r13);
205 generate_transcendental_entry(kind, 2);
206 break;
207 case Interpreter::java_lang_math_fmaD :
208 if (UseFMA) {
209 entry_point = __ pc();
210 __ ldrd(v0, Address(esp, 4 * Interpreter::stackElementSize));
211 __ ldrd(v1, Address(esp, 2 * Interpreter::stackElementSize));
212 __ ldrd(v2, Address(esp));
213 __ fmaddd(v0, v0, v1, v2);
214 __ mov(sp, r13); // Restore caller's SP
215 }
216 break;
217 case Interpreter::java_lang_math_fmaF :
218 if (UseFMA) {
219 entry_point = __ pc();
220 __ ldrs(v0, Address(esp, 2 * Interpreter::stackElementSize));
221 __ ldrs(v1, Address(esp, Interpreter::stackElementSize));
222 __ ldrs(v2, Address(esp));
223 __ fmadds(v0, v0, v1, v2);
224 __ mov(sp, r13); // Restore caller's SP
225 }
226 break;
227 default:
228 ;
229 }
230 if (entry_point) {
231 __ br(continuation);
232 }
233
234 return entry_point;
235 }
236
237 // double trigonometrics and transcendentals
238 // static jdouble dsin(jdouble x);
239 // static jdouble dcos(jdouble x);
240 // static jdouble dtan(jdouble x);
241 // static jdouble dlog(jdouble x);
242 // static jdouble dlog10(jdouble x);
243 // static jdouble dexp(jdouble x);
244 // static jdouble dpow(jdouble x, jdouble y);
245
generate_transcendental_entry(AbstractInterpreter::MethodKind kind,int fpargs)246 void TemplateInterpreterGenerator::generate_transcendental_entry(AbstractInterpreter::MethodKind kind, int fpargs) {
247 address fn;
248 switch (kind) {
249 case Interpreter::java_lang_math_sin :
250 if (StubRoutines::dsin() == NULL) {
251 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
252 } else {
253 fn = CAST_FROM_FN_PTR(address, StubRoutines::dsin());
254 }
255 break;
256 case Interpreter::java_lang_math_cos :
257 if (StubRoutines::dcos() == NULL) {
258 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
259 } else {
260 fn = CAST_FROM_FN_PTR(address, StubRoutines::dcos());
261 }
262 break;
263 case Interpreter::java_lang_math_tan :
264 if (StubRoutines::dtan() == NULL) {
265 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
266 } else {
267 fn = CAST_FROM_FN_PTR(address, StubRoutines::dtan());
268 }
269 break;
270 case Interpreter::java_lang_math_log :
271 if (StubRoutines::dlog() == NULL) {
272 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
273 } else {
274 fn = CAST_FROM_FN_PTR(address, StubRoutines::dlog());
275 }
276 break;
277 case Interpreter::java_lang_math_log10 :
278 if (StubRoutines::dlog10() == NULL) {
279 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
280 } else {
281 fn = CAST_FROM_FN_PTR(address, StubRoutines::dlog10());
282 }
283 break;
284 case Interpreter::java_lang_math_exp :
285 if (StubRoutines::dexp() == NULL) {
286 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
287 } else {
288 fn = CAST_FROM_FN_PTR(address, StubRoutines::dexp());
289 }
290 break;
291 case Interpreter::java_lang_math_pow :
292 if (StubRoutines::dpow() == NULL) {
293 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
294 } else {
295 fn = CAST_FROM_FN_PTR(address, StubRoutines::dpow());
296 }
297 break;
298 default:
299 ShouldNotReachHere();
300 fn = NULL; // unreachable
301 }
302 __ mov(rscratch1, fn);
303 __ blr(rscratch1);
304 }
305
306 // Abstract method entry
307 // Attempt to execute abstract method. Throw exception
generate_abstract_entry(void)308 address TemplateInterpreterGenerator::generate_abstract_entry(void) {
309 // rmethod: Method*
310 // r13: sender SP
311
312 address entry_point = __ pc();
313
314 // abstract method entry
315
316 // pop return address, reset last_sp to NULL
317 __ empty_expression_stack();
318 __ restore_bcp(); // bcp must be correct for exception handler (was destroyed)
319 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
320
321 // throw exception
322 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
323 InterpreterRuntime::throw_AbstractMethodErrorWithMethod),
324 rmethod);
325 // the call_VM checks for exception, so we should never return here.
326 __ should_not_reach_here();
327
328 return entry_point;
329 }
330
generate_StackOverflowError_handler()331 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
332 address entry = __ pc();
333
334 #ifdef ASSERT
335 {
336 Label L;
337 __ ldr(rscratch1, Address(rfp,
338 frame::interpreter_frame_monitor_block_top_offset *
339 wordSize));
340 __ mov(rscratch2, sp);
341 __ cmp(rscratch1, rscratch2); // maximal rsp for current rfp (stack
342 // grows negative)
343 __ br(Assembler::HS, L); // check if frame is complete
344 __ stop ("interpreter frame not set up");
345 __ bind(L);
346 }
347 #endif // ASSERT
348 // Restore bcp under the assumption that the current frame is still
349 // interpreted
350 __ restore_bcp();
351
352 // expression stack must be empty before entering the VM if an
353 // exception happened
354 __ empty_expression_stack();
355 // throw exception
356 __ call_VM(noreg,
357 CAST_FROM_FN_PTR(address,
358 InterpreterRuntime::throw_StackOverflowError));
359 return entry;
360 }
361
generate_ArrayIndexOutOfBounds_handler()362 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler() {
363 address entry = __ pc();
364 // expression stack must be empty before entering the VM if an
365 // exception happened
366 __ empty_expression_stack();
367 // setup parameters
368
369 // ??? convention: expect aberrant index in register r1
370 __ movw(c_rarg2, r1);
371 // ??? convention: expect array in register r3
372 __ mov(c_rarg1, r3);
373 __ call_VM(noreg,
374 CAST_FROM_FN_PTR(address,
375 InterpreterRuntime::
376 throw_ArrayIndexOutOfBoundsException),
377 c_rarg1, c_rarg2);
378 return entry;
379 }
380
generate_ClassCastException_handler()381 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
382 address entry = __ pc();
383
384 // object is at TOS
385 __ pop(c_rarg1);
386
387 // expression stack must be empty before entering the VM if an
388 // exception happened
389 __ empty_expression_stack();
390
391 __ call_VM(noreg,
392 CAST_FROM_FN_PTR(address,
393 InterpreterRuntime::
394 throw_ClassCastException),
395 c_rarg1);
396 return entry;
397 }
398
generate_exception_handler_common(const char * name,const char * message,bool pass_oop)399 address TemplateInterpreterGenerator::generate_exception_handler_common(
400 const char* name, const char* message, bool pass_oop) {
401 assert(!pass_oop || message == NULL, "either oop or message but not both");
402 address entry = __ pc();
403 if (pass_oop) {
404 // object is at TOS
405 __ pop(c_rarg2);
406 }
407 // expression stack must be empty before entering the VM if an
408 // exception happened
409 __ empty_expression_stack();
410 // setup parameters
411 __ lea(c_rarg1, Address((address)name));
412 if (pass_oop) {
413 __ call_VM(r0, CAST_FROM_FN_PTR(address,
414 InterpreterRuntime::
415 create_klass_exception),
416 c_rarg1, c_rarg2);
417 } else {
418 // kind of lame ExternalAddress can't take NULL because
419 // external_word_Relocation will assert.
420 if (message != NULL) {
421 __ lea(c_rarg2, Address((address)message));
422 } else {
423 __ mov(c_rarg2, NULL_WORD);
424 }
425 __ call_VM(r0,
426 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception),
427 c_rarg1, c_rarg2);
428 }
429 // throw exception
430 __ b(address(Interpreter::throw_exception_entry()));
431 return entry;
432 }
433
generate_return_entry_for(TosState state,int step,size_t index_size)434 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
435 address entry = __ pc();
436
437 // Restore stack bottom in case i2c adjusted stack
438 __ ldr(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
439 // and NULL it as marker that esp is now tos until next java call
440 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
441 __ restore_bcp();
442 __ restore_locals();
443 __ restore_constant_pool_cache();
444 __ get_method(rmethod);
445
446 if (state == atos) {
447 Register obj = r0;
448 Register mdp = r1;
449 Register tmp = r2;
450 __ profile_return_type(mdp, obj, tmp);
451 }
452
453 // Pop N words from the stack
454 __ get_cache_and_index_at_bcp(r1, r2, 1, index_size);
455 __ ldr(r1, Address(r1, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
456 __ andr(r1, r1, ConstantPoolCacheEntry::parameter_size_mask);
457
458 __ add(esp, esp, r1, Assembler::LSL, 3);
459
460 // Restore machine SP
461 __ ldr(rscratch1, Address(rmethod, Method::const_offset()));
462 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset()));
463 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 2);
464 __ ldr(rscratch2,
465 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize));
466 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtw, 3);
467 __ andr(sp, rscratch1, -16);
468
469 __ check_and_handle_popframe(rthread);
470 __ check_and_handle_earlyret(rthread);
471
472 __ get_dispatch();
473 __ dispatch_next(state, step);
474
475 return entry;
476 }
477
generate_deopt_entry_for(TosState state,int step,address continuation)478 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
479 int step,
480 address continuation) {
481 address entry = __ pc();
482 __ restore_bcp();
483 __ restore_locals();
484 __ restore_constant_pool_cache();
485 __ get_method(rmethod);
486 __ get_dispatch();
487
488 // Calculate stack limit
489 __ ldr(rscratch1, Address(rmethod, Method::const_offset()));
490 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset()));
491 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 2);
492 __ ldr(rscratch2,
493 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize));
494 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtx, 3);
495 __ andr(sp, rscratch1, -16);
496
497 // Restore expression stack pointer
498 __ ldr(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
499 // NULL last_sp until next java call
500 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
501
502 #if INCLUDE_JVMCI
503 // Check if we need to take lock at entry of synchronized method. This can
504 // only occur on method entry so emit it only for vtos with step 0.
505 if (EnableJVMCI && state == vtos && step == 0) {
506 Label L;
507 __ ldrb(rscratch1, Address(rthread, JavaThread::pending_monitorenter_offset()));
508 __ cbz(rscratch1, L);
509 // Clear flag.
510 __ strb(zr, Address(rthread, JavaThread::pending_monitorenter_offset()));
511 // Take lock.
512 lock_method();
513 __ bind(L);
514 } else {
515 #ifdef ASSERT
516 if (EnableJVMCI) {
517 Label L;
518 __ ldrb(rscratch1, Address(rthread, JavaThread::pending_monitorenter_offset()));
519 __ cbz(rscratch1, L);
520 __ stop("unexpected pending monitor in deopt entry");
521 __ bind(L);
522 }
523 #endif
524 }
525 #endif
526 // handle exceptions
527 {
528 Label L;
529 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset()));
530 __ cbz(rscratch1, L);
531 __ call_VM(noreg,
532 CAST_FROM_FN_PTR(address,
533 InterpreterRuntime::throw_pending_exception));
534 __ should_not_reach_here();
535 __ bind(L);
536 }
537
538 if (continuation == NULL) {
539 __ dispatch_next(state, step);
540 } else {
541 __ jump_to_entry(continuation);
542 }
543 return entry;
544 }
545
generate_result_handler_for(BasicType type)546 address TemplateInterpreterGenerator::generate_result_handler_for(
547 BasicType type) {
548 address entry = __ pc();
549 switch (type) {
550 case T_BOOLEAN: __ c2bool(r0); break;
551 case T_CHAR : __ uxth(r0, r0); break;
552 case T_BYTE : __ sxtb(r0, r0); break;
553 case T_SHORT : __ sxth(r0, r0); break;
554 case T_INT : __ uxtw(r0, r0); break; // FIXME: We almost certainly don't need this
555 case T_LONG : /* nothing to do */ break;
556 case T_VOID : /* nothing to do */ break;
557 case T_FLOAT : /* nothing to do */ break;
558 case T_DOUBLE : /* nothing to do */ break;
559 case T_OBJECT :
560 // retrieve result from frame
561 __ ldr(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize));
562 // and verify it
563 __ verify_oop(r0);
564 break;
565 default : ShouldNotReachHere();
566 }
567 __ ret(lr); // return from result handler
568 return entry;
569 }
570
generate_safept_entry_for(TosState state,address runtime_entry)571 address TemplateInterpreterGenerator::generate_safept_entry_for(
572 TosState state,
573 address runtime_entry) {
574 address entry = __ pc();
575 __ push(state);
576 __ call_VM(noreg, runtime_entry);
577 __ membar(Assembler::AnyAny);
578 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
579 return entry;
580 }
581
582 // Helpers for commoning out cases in the various type of method entries.
583 //
584
585
586 // increment invocation count & check for overflow
587 //
588 // Note: checking for negative value instead of overflow
589 // so we have a 'sticky' overflow test
590 //
591 // rmethod: method
592 //
generate_counter_incr(Label * overflow)593 void TemplateInterpreterGenerator::generate_counter_incr(Label* overflow) {
594 Label done;
595 // Note: In tiered we increment either counters in Method* or in MDO depending if we're profiling or not.
596 int increment = InvocationCounter::count_increment;
597 Label no_mdo;
598 if (ProfileInterpreter) {
599 // Are we profiling?
600 __ ldr(r0, Address(rmethod, Method::method_data_offset()));
601 __ cbz(r0, no_mdo);
602 // Increment counter in the MDO
603 const Address mdo_invocation_counter(r0, in_bytes(MethodData::invocation_counter_offset()) +
604 in_bytes(InvocationCounter::counter_offset()));
605 const Address mask(r0, in_bytes(MethodData::invoke_mask_offset()));
606 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rscratch1, rscratch2, false, Assembler::EQ, overflow);
607 __ b(done);
608 }
609 __ bind(no_mdo);
610 // Increment counter in MethodCounters
611 const Address invocation_counter(rscratch2,
612 MethodCounters::invocation_counter_offset() +
613 InvocationCounter::counter_offset());
614 __ get_method_counters(rmethod, rscratch2, done);
615 const Address mask(rscratch2, in_bytes(MethodCounters::invoke_mask_offset()));
616 __ increment_mask_and_jump(invocation_counter, increment, mask, rscratch1, r1, false, Assembler::EQ, overflow);
617 __ bind(done);
618 }
619
generate_counter_overflow(Label & do_continue)620 void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) {
621
622 // Asm interpreter on entry
623 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
624 // Everything as it was on entry
625
626 // InterpreterRuntime::frequency_counter_overflow takes two
627 // arguments, the first (thread) is passed by call_VM, the second
628 // indicates if the counter overflow occurs at a backwards branch
629 // (NULL bcp). We pass zero for it. The call returns the address
630 // of the verified entry point for the method or NULL if the
631 // compilation did not complete (either went background or bailed
632 // out).
633 __ mov(c_rarg1, 0);
634 __ call_VM(noreg,
635 CAST_FROM_FN_PTR(address,
636 InterpreterRuntime::frequency_counter_overflow),
637 c_rarg1);
638
639 __ b(do_continue);
640 }
641
642 // See if we've got enough room on the stack for locals plus overhead
643 // below JavaThread::stack_overflow_limit(). If not, throw a StackOverflowError
644 // without going through the signal handler, i.e., reserved and yellow zones
645 // will not be made usable. The shadow zone must suffice to handle the
646 // overflow.
647 // The expression stack grows down incrementally, so the normal guard
648 // page mechanism will work for that.
649 //
650 // NOTE: Since the additional locals are also always pushed (wasn't
651 // obvious in generate_method_entry) so the guard should work for them
652 // too.
653 //
654 // Args:
655 // r3: number of additional locals this frame needs (what we must check)
656 // rmethod: Method*
657 //
658 // Kills:
659 // r0
generate_stack_overflow_check(void)660 void TemplateInterpreterGenerator::generate_stack_overflow_check(void) {
661
662 // monitor entry size: see picture of stack set
663 // (generate_method_entry) and frame_amd64.hpp
664 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
665
666 // total overhead size: entry_size + (saved rbp through expr stack
667 // bottom). be sure to change this if you add/subtract anything
668 // to/from the overhead area
669 const int overhead_size =
670 -(frame::interpreter_frame_initial_sp_offset * wordSize) + entry_size;
671
672 const int page_size = os::vm_page_size();
673
674 Label after_frame_check;
675
676 // see if the frame is greater than one page in size. If so,
677 // then we need to verify there is enough stack space remaining
678 // for the additional locals.
679 //
680 // Note that we use SUBS rather than CMP here because the immediate
681 // field of this instruction may overflow. SUBS can cope with this
682 // because it is a macro that will expand to some number of MOV
683 // instructions and a register operation.
684 __ subs(rscratch1, r3, (page_size - overhead_size) / Interpreter::stackElementSize);
685 __ br(Assembler::LS, after_frame_check);
686
687 // compute rsp as if this were going to be the last frame on
688 // the stack before the red zone
689
690 // locals + overhead, in bytes
691 __ mov(r0, overhead_size);
692 __ add(r0, r0, r3, Assembler::LSL, Interpreter::logStackElementSize); // 2 slots per parameter.
693
694 const Address stack_limit(rthread, JavaThread::stack_overflow_limit_offset());
695 __ ldr(rscratch1, stack_limit);
696
697 #ifdef ASSERT
698 Label limit_okay;
699 // Verify that thread stack limit is non-zero.
700 __ cbnz(rscratch1, limit_okay);
701 __ stop("stack overflow limit is zero");
702 __ bind(limit_okay);
703 #endif
704
705 // Add stack limit to locals.
706 __ add(r0, r0, rscratch1);
707
708 // Check against the current stack bottom.
709 __ cmp(sp, r0);
710 __ br(Assembler::HI, after_frame_check);
711
712 // Remove the incoming args, peeling the machine SP back to where it
713 // was in the caller. This is not strictly necessary, but unless we
714 // do so the stack frame may have a garbage FP; this ensures a
715 // correct call stack that we can always unwind. The ANDR should be
716 // unnecessary because the sender SP in r13 is always aligned, but
717 // it doesn't hurt.
718 __ andr(sp, r13, -16);
719
720 // Note: the restored frame is not necessarily interpreted.
721 // Use the shared runtime version of the StackOverflowError.
722 assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated");
723 __ far_jump(RuntimeAddress(StubRoutines::throw_StackOverflowError_entry()));
724
725 // all done with frame size check
726 __ bind(after_frame_check);
727 }
728
729 // Allocate monitor and lock method (asm interpreter)
730 //
731 // Args:
732 // rmethod: Method*
733 // rlocals: locals
734 //
735 // Kills:
736 // r0
737 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs)
738 // rscratch1, rscratch2 (scratch regs)
lock_method()739 void TemplateInterpreterGenerator::lock_method() {
740 // synchronize method
741 const Address access_flags(rmethod, Method::access_flags_offset());
742 const Address monitor_block_top(
743 rfp,
744 frame::interpreter_frame_monitor_block_top_offset * wordSize);
745 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
746
747 #ifdef ASSERT
748 {
749 Label L;
750 __ ldrw(r0, access_flags);
751 __ tst(r0, JVM_ACC_SYNCHRONIZED);
752 __ br(Assembler::NE, L);
753 __ stop("method doesn't need synchronization");
754 __ bind(L);
755 }
756 #endif // ASSERT
757
758 // get synchronization object
759 {
760 Label done;
761 __ ldrw(r0, access_flags);
762 __ tst(r0, JVM_ACC_STATIC);
763 // get receiver (assume this is frequent case)
764 __ ldr(r0, Address(rlocals, Interpreter::local_offset_in_bytes(0)));
765 __ br(Assembler::EQ, done);
766 __ load_mirror(r0, rmethod);
767
768 #ifdef ASSERT
769 {
770 Label L;
771 __ cbnz(r0, L);
772 __ stop("synchronization object is NULL");
773 __ bind(L);
774 }
775 #endif // ASSERT
776
777 __ bind(done);
778 }
779
780 // add space for monitor & lock
781 __ sub(sp, sp, entry_size); // add space for a monitor entry
782 __ sub(esp, esp, entry_size);
783 __ mov(rscratch1, esp);
784 __ str(rscratch1, monitor_block_top); // set new monitor block top
785 // store object
786 __ str(r0, Address(esp, BasicObjectLock::obj_offset_in_bytes()));
787 __ mov(c_rarg1, esp); // object address
788 __ lock_object(c_rarg1);
789 }
790
791 // Generate a fixed interpreter frame. This is identical setup for
792 // interpreted methods and for native methods hence the shared code.
793 //
794 // Args:
795 // lr: return address
796 // rmethod: Method*
797 // rlocals: pointer to locals
798 // rcpool: cp cache
799 // stack_pointer: previous sp
generate_fixed_frame(bool native_call)800 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
801 // initialize fixed part of activation frame
802 if (native_call) {
803 __ sub(esp, sp, 14 * wordSize);
804 __ mov(rbcp, zr);
805 __ stp(esp, zr, Address(__ pre(sp, -14 * wordSize)));
806 // add 2 zero-initialized slots for native calls
807 __ stp(zr, zr, Address(sp, 12 * wordSize));
808 } else {
809 __ sub(esp, sp, 12 * wordSize);
810 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); // get ConstMethod
811 __ add(rbcp, rscratch1, in_bytes(ConstMethod::codes_offset())); // get codebase
812 __ stp(esp, rbcp, Address(__ pre(sp, -12 * wordSize)));
813 }
814
815 if (ProfileInterpreter) {
816 Label method_data_continue;
817 __ ldr(rscratch1, Address(rmethod, Method::method_data_offset()));
818 __ cbz(rscratch1, method_data_continue);
819 __ lea(rscratch1, Address(rscratch1, in_bytes(MethodData::data_offset())));
820 __ bind(method_data_continue);
821 __ stp(rscratch1, rmethod, Address(sp, 6 * wordSize)); // save Method* and mdp (method data pointer)
822 } else {
823 __ stp(zr, rmethod, Address(sp, 6 * wordSize)); // save Method* (no mdp)
824 }
825
826 // Get mirror and store it in the frame as GC root for this Method*
827 __ load_mirror(r10, rmethod);
828 __ stp(r10, zr, Address(sp, 4 * wordSize));
829
830 __ ldr(rcpool, Address(rmethod, Method::const_offset()));
831 __ ldr(rcpool, Address(rcpool, ConstMethod::constants_offset()));
832 __ ldr(rcpool, Address(rcpool, ConstantPool::cache_offset_in_bytes()));
833 __ stp(rlocals, rcpool, Address(sp, 2 * wordSize));
834
835 __ stp(rfp, lr, Address(sp, 10 * wordSize));
836 __ lea(rfp, Address(sp, 10 * wordSize));
837
838 // set sender sp
839 // leave last_sp as null
840 __ stp(zr, r13, Address(sp, 8 * wordSize));
841
842 // Move SP out of the way
843 if (! native_call) {
844 __ ldr(rscratch1, Address(rmethod, Method::const_offset()));
845 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset()));
846 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 2);
847 __ sub(rscratch1, sp, rscratch1, ext::uxtw, 3);
848 __ andr(sp, rscratch1, -16);
849 }
850 }
851
852 // End of helpers
853
854 // Various method entries
855 //------------------------------------------------------------------------------------------------------------------------
856 //
857 //
858
859 // Method entry for java.lang.ref.Reference.get.
generate_Reference_get_entry(void)860 address TemplateInterpreterGenerator::generate_Reference_get_entry(void) {
861 // Code: _aload_0, _getfield, _areturn
862 // parameter size = 1
863 //
864 // The code that gets generated by this routine is split into 2 parts:
865 // 1. The "intrinsified" code for G1 (or any SATB based GC),
866 // 2. The slow path - which is an expansion of the regular method entry.
867 //
868 // Notes:-
869 // * In the G1 code we do not check whether we need to block for
870 // a safepoint. If G1 is enabled then we must execute the specialized
871 // code for Reference.get (except when the Reference object is null)
872 // so that we can log the value in the referent field with an SATB
873 // update buffer.
874 // If the code for the getfield template is modified so that the
875 // G1 pre-barrier code is executed when the current method is
876 // Reference.get() then going through the normal method entry
877 // will be fine.
878 // * The G1 code can, however, check the receiver object (the instance
879 // of java.lang.Reference) and jump to the slow path if null. If the
880 // Reference object is null then we obviously cannot fetch the referent
881 // and so we don't need to call the G1 pre-barrier. Thus we can use the
882 // regular method entry code to generate the NPE.
883 //
884 // This code is based on generate_accessor_entry.
885 //
886 // rmethod: Method*
887 // r13: senderSP must preserve for slow path, set SP to it on fast path
888
889 // LR is live. It must be saved around calls.
890
891 address entry = __ pc();
892
893 const int referent_offset = java_lang_ref_Reference::referent_offset();
894
895 Label slow_path;
896 const Register local_0 = c_rarg0;
897 // Check if local 0 != NULL
898 // If the receiver is null then it is OK to jump to the slow path.
899 __ ldr(local_0, Address(esp, 0));
900 __ cbz(local_0, slow_path);
901
902 __ mov(r19, r13); // Move senderSP to a callee-saved register
903
904 // Load the value of the referent field.
905 const Address field_address(local_0, referent_offset);
906 BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler();
907 bs->load_at(_masm, IN_HEAP | ON_WEAK_OOP_REF, T_OBJECT, local_0, field_address, /*tmp1*/ rscratch2, /*tmp2*/ rscratch1);
908
909 // areturn
910 __ andr(sp, r19, -16); // done with stack
911 __ ret(lr);
912
913 // generate a vanilla interpreter entry as the slow path
914 __ bind(slow_path);
915 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals));
916 return entry;
917
918 }
919
920 /**
921 * Method entry for static native methods:
922 * int java.util.zip.CRC32.update(int crc, int b)
923 */
generate_CRC32_update_entry()924 address TemplateInterpreterGenerator::generate_CRC32_update_entry() {
925 if (UseCRC32Intrinsics) {
926 address entry = __ pc();
927
928 // rmethod: Method*
929 // r13: senderSP must preserved for slow path
930 // esp: args
931
932 Label slow_path;
933 // If we need a safepoint check, generate full interpreter entry.
934 __ safepoint_poll(slow_path, false /* at_return */, false /* acquire */, false /* in_nmethod */);
935
936 // We don't generate local frame and don't align stack because
937 // we call stub code and there is no safepoint on this path.
938
939 // Load parameters
940 const Register crc = c_rarg0; // crc
941 const Register val = c_rarg1; // source java byte value
942 const Register tbl = c_rarg2; // scratch
943
944 // Arguments are reversed on java expression stack
945 __ ldrw(val, Address(esp, 0)); // byte value
946 __ ldrw(crc, Address(esp, wordSize)); // Initial CRC
947
948 uint64_t offset;
949 __ adrp(tbl, ExternalAddress(StubRoutines::crc_table_addr()), offset);
950 __ add(tbl, tbl, offset);
951
952 __ mvnw(crc, crc); // ~crc
953 __ update_byte_crc32(crc, val, tbl);
954 __ mvnw(crc, crc); // ~crc
955
956 // result in c_rarg0
957
958 __ andr(sp, r13, -16);
959 __ ret(lr);
960
961 // generate a vanilla native entry as the slow path
962 __ bind(slow_path);
963 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native));
964 return entry;
965 }
966 return NULL;
967 }
968
969 /**
970 * Method entry for static native methods:
971 * int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len)
972 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)
973 */
generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind)974 address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
975 if (UseCRC32Intrinsics) {
976 address entry = __ pc();
977
978 // rmethod,: Method*
979 // r13: senderSP must preserved for slow path
980
981 Label slow_path;
982 // If we need a safepoint check, generate full interpreter entry.
983 __ safepoint_poll(slow_path, false /* at_return */, false /* acquire */, false /* in_nmethod */);
984
985 // We don't generate local frame and don't align stack because
986 // we call stub code and there is no safepoint on this path.
987
988 // Load parameters
989 const Register crc = c_rarg0; // crc
990 const Register buf = c_rarg1; // source java byte array address
991 const Register len = c_rarg2; // length
992 const Register off = len; // offset (never overlaps with 'len')
993
994 // Arguments are reversed on java expression stack
995 // Calculate address of start element
996 if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) {
997 __ ldr(buf, Address(esp, 2*wordSize)); // long buf
998 __ ldrw(off, Address(esp, wordSize)); // offset
999 __ add(buf, buf, off); // + offset
1000 __ ldrw(crc, Address(esp, 4*wordSize)); // Initial CRC
1001 } else {
1002 __ ldr(buf, Address(esp, 2*wordSize)); // byte[] array
1003 __ add(buf, buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size
1004 __ ldrw(off, Address(esp, wordSize)); // offset
1005 __ add(buf, buf, off); // + offset
1006 __ ldrw(crc, Address(esp, 3*wordSize)); // Initial CRC
1007 }
1008 // Can now load 'len' since we're finished with 'off'
1009 __ ldrw(len, Address(esp, 0x0)); // Length
1010
1011 __ andr(sp, r13, -16); // Restore the caller's SP
1012
1013 // We are frameless so we can just jump to the stub.
1014 __ b(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32()));
1015
1016 // generate a vanilla native entry as the slow path
1017 __ bind(slow_path);
1018 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native));
1019 return entry;
1020 }
1021 return NULL;
1022 }
1023
1024 /**
1025 * Method entry for intrinsic-candidate (non-native) methods:
1026 * int java.util.zip.CRC32C.updateBytes(int crc, byte[] b, int off, int end)
1027 * int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end)
1028 * Unlike CRC32, CRC32C does not have any methods marked as native
1029 * CRC32C also uses an "end" variable instead of the length variable CRC32 uses
1030 */
generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind)1031 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
1032 if (UseCRC32CIntrinsics) {
1033 address entry = __ pc();
1034
1035 // Prepare jump to stub using parameters from the stack
1036 const Register crc = c_rarg0; // initial crc
1037 const Register buf = c_rarg1; // source java byte array address
1038 const Register len = c_rarg2; // len argument to the kernel
1039
1040 const Register end = len; // index of last element to process
1041 const Register off = crc; // offset
1042
1043 __ ldrw(end, Address(esp)); // int end
1044 __ ldrw(off, Address(esp, wordSize)); // int offset
1045 __ sub(len, end, off);
1046 __ ldr(buf, Address(esp, 2*wordSize)); // byte[] buf | long buf
1047 __ add(buf, buf, off); // + offset
1048 if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) {
1049 __ ldrw(crc, Address(esp, 4*wordSize)); // long crc
1050 } else {
1051 __ add(buf, buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size
1052 __ ldrw(crc, Address(esp, 3*wordSize)); // long crc
1053 }
1054
1055 __ andr(sp, r13, -16); // Restore the caller's SP
1056
1057 // Jump to the stub.
1058 __ b(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32C()));
1059
1060 return entry;
1061 }
1062 return NULL;
1063 }
1064
bang_stack_shadow_pages(bool native_call)1065 void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {
1066 // Bang each page in the shadow zone. We can't assume it's been done for
1067 // an interpreter frame with greater than a page of locals, so each page
1068 // needs to be checked. Only true for non-native.
1069 const int n_shadow_pages = (int)(StackOverflow::stack_shadow_zone_size() / os::vm_page_size());
1070 const int start_page = native_call ? n_shadow_pages : 1;
1071 const int page_size = os::vm_page_size();
1072 for (int pages = start_page; pages <= n_shadow_pages ; pages++) {
1073 __ sub(rscratch2, sp, pages*page_size);
1074 __ str(zr, Address(rscratch2));
1075 }
1076 }
1077
1078
1079 // Interpreter stub for calling a native method. (asm interpreter)
1080 // This sets up a somewhat different looking stack for calling the
1081 // native method than the typical interpreter frame setup.
generate_native_entry(bool synchronized)1082 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
1083 // determine code generation flags
1084 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods;
1085
1086 // r1: Method*
1087 // rscratch1: sender sp
1088
1089 address entry_point = __ pc();
1090
1091 const Address constMethod (rmethod, Method::const_offset());
1092 const Address access_flags (rmethod, Method::access_flags_offset());
1093 const Address size_of_parameters(r2, ConstMethod::
1094 size_of_parameters_offset());
1095
1096 // get parameter size (always needed)
1097 __ ldr(r2, constMethod);
1098 __ load_unsigned_short(r2, size_of_parameters);
1099
1100 // Native calls don't need the stack size check since they have no
1101 // expression stack and the arguments are already on the stack and
1102 // we only add a handful of words to the stack.
1103
1104 // rmethod: Method*
1105 // r2: size of parameters
1106 // rscratch1: sender sp
1107
1108 // for natives the size of locals is zero
1109
1110 // compute beginning of parameters (rlocals)
1111 __ add(rlocals, esp, r2, ext::uxtx, 3);
1112 __ add(rlocals, rlocals, -wordSize);
1113
1114 // Pull SP back to minimum size: this avoids holes in the stack
1115 __ andr(sp, esp, -16);
1116
1117 // initialize fixed part of activation frame
1118 generate_fixed_frame(true);
1119
1120 // make sure method is native & not abstract
1121 #ifdef ASSERT
1122 __ ldrw(r0, access_flags);
1123 {
1124 Label L;
1125 __ tst(r0, JVM_ACC_NATIVE);
1126 __ br(Assembler::NE, L);
1127 __ stop("tried to execute non-native method as native");
1128 __ bind(L);
1129 }
1130 {
1131 Label L;
1132 __ tst(r0, JVM_ACC_ABSTRACT);
1133 __ br(Assembler::EQ, L);
1134 __ stop("tried to execute abstract method in interpreter");
1135 __ bind(L);
1136 }
1137 #endif
1138
1139 // Since at this point in the method invocation the exception
1140 // handler would try to exit the monitor of synchronized methods
1141 // which hasn't been entered yet, we set the thread local variable
1142 // _do_not_unlock_if_synchronized to true. The remove_activation
1143 // will check this flag.
1144
1145 const Address do_not_unlock_if_synchronized(rthread,
1146 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
1147 __ mov(rscratch2, true);
1148 __ strb(rscratch2, do_not_unlock_if_synchronized);
1149
1150 // increment invocation count & check for overflow
1151 Label invocation_counter_overflow;
1152 if (inc_counter) {
1153 generate_counter_incr(&invocation_counter_overflow);
1154 }
1155
1156 Label continue_after_compile;
1157 __ bind(continue_after_compile);
1158
1159 bang_stack_shadow_pages(true);
1160
1161 // reset the _do_not_unlock_if_synchronized flag
1162 __ strb(zr, do_not_unlock_if_synchronized);
1163
1164 // check for synchronized methods
1165 // Must happen AFTER invocation_counter check and stack overflow check,
1166 // so method is not locked if overflows.
1167 if (synchronized) {
1168 lock_method();
1169 } else {
1170 // no synchronization necessary
1171 #ifdef ASSERT
1172 {
1173 Label L;
1174 __ ldrw(r0, access_flags);
1175 __ tst(r0, JVM_ACC_SYNCHRONIZED);
1176 __ br(Assembler::EQ, L);
1177 __ stop("method needs synchronization");
1178 __ bind(L);
1179 }
1180 #endif
1181 }
1182
1183 // start execution
1184 #ifdef ASSERT
1185 {
1186 Label L;
1187 const Address monitor_block_top(rfp,
1188 frame::interpreter_frame_monitor_block_top_offset * wordSize);
1189 __ ldr(rscratch1, monitor_block_top);
1190 __ cmp(esp, rscratch1);
1191 __ br(Assembler::EQ, L);
1192 __ stop("broken stack frame setup in interpreter");
1193 __ bind(L);
1194 }
1195 #endif
1196
1197 // jvmti support
1198 __ notify_method_entry();
1199
1200 // work registers
1201 const Register t = r17;
1202 const Register result_handler = r19;
1203
1204 // allocate space for parameters
1205 __ ldr(t, Address(rmethod, Method::const_offset()));
1206 __ load_unsigned_short(t, Address(t, ConstMethod::size_of_parameters_offset()));
1207
1208 __ sub(rscratch1, esp, t, ext::uxtx, Interpreter::logStackElementSize);
1209 __ andr(sp, rscratch1, -16);
1210 __ mov(esp, rscratch1);
1211
1212 // get signature handler
1213 {
1214 Label L;
1215 __ ldr(t, Address(rmethod, Method::signature_handler_offset()));
1216 __ cbnz(t, L);
1217 __ call_VM(noreg,
1218 CAST_FROM_FN_PTR(address,
1219 InterpreterRuntime::prepare_native_call),
1220 rmethod);
1221 __ ldr(t, Address(rmethod, Method::signature_handler_offset()));
1222 __ bind(L);
1223 }
1224
1225 // call signature handler
1226 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rlocals,
1227 "adjust this code");
1228 assert(InterpreterRuntime::SignatureHandlerGenerator::to() == sp,
1229 "adjust this code");
1230 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == rscratch1,
1231 "adjust this code");
1232
1233 // The generated handlers do not touch rmethod (the method).
1234 // However, large signatures cannot be cached and are generated
1235 // each time here. The slow-path generator can do a GC on return,
1236 // so we must reload it after the call.
1237 __ blr(t);
1238 __ get_method(rmethod); // slow path can do a GC, reload rmethod
1239
1240
1241 // result handler is in r0
1242 // set result handler
1243 __ mov(result_handler, r0);
1244 // pass mirror handle if static call
1245 {
1246 Label L;
1247 __ ldrw(t, Address(rmethod, Method::access_flags_offset()));
1248 __ tbz(t, exact_log2(JVM_ACC_STATIC), L);
1249 // get mirror
1250 __ load_mirror(t, rmethod);
1251 // copy mirror into activation frame
1252 __ str(t, Address(rfp, frame::interpreter_frame_oop_temp_offset * wordSize));
1253 // pass handle to mirror
1254 __ add(c_rarg1, rfp, frame::interpreter_frame_oop_temp_offset * wordSize);
1255 __ bind(L);
1256 }
1257
1258 // get native function entry point in r10
1259 {
1260 Label L;
1261 __ ldr(r10, Address(rmethod, Method::native_function_offset()));
1262 address unsatisfied = (SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
1263 __ mov(rscratch2, unsatisfied);
1264 __ ldr(rscratch2, rscratch2);
1265 __ cmp(r10, rscratch2);
1266 __ br(Assembler::NE, L);
1267 __ call_VM(noreg,
1268 CAST_FROM_FN_PTR(address,
1269 InterpreterRuntime::prepare_native_call),
1270 rmethod);
1271 __ get_method(rmethod);
1272 __ ldr(r10, Address(rmethod, Method::native_function_offset()));
1273 __ bind(L);
1274 }
1275
1276 // pass JNIEnv
1277 __ add(c_rarg0, rthread, in_bytes(JavaThread::jni_environment_offset()));
1278
1279 // Set the last Java PC in the frame anchor to be the return address from
1280 // the call to the native method: this will allow the debugger to
1281 // generate an accurate stack trace.
1282 Label native_return;
1283 __ set_last_Java_frame(esp, rfp, native_return, rscratch1);
1284
1285 // change thread state
1286 #ifdef ASSERT
1287 {
1288 Label L;
1289 __ ldrw(t, Address(rthread, JavaThread::thread_state_offset()));
1290 __ cmp(t, (u1)_thread_in_Java);
1291 __ br(Assembler::EQ, L);
1292 __ stop("Wrong thread state in native stub");
1293 __ bind(L);
1294 }
1295 #endif
1296
1297 // Change state to native
1298 __ mov(rscratch1, _thread_in_native);
1299 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset()));
1300 __ stlrw(rscratch1, rscratch2);
1301
1302 // Call the native method.
1303 __ blr(r10);
1304 __ bind(native_return);
1305 __ get_method(rmethod);
1306 // result potentially in r0 or v0
1307
1308 // make room for the pushes we're about to do
1309 __ sub(rscratch1, esp, 4 * wordSize);
1310 __ andr(sp, rscratch1, -16);
1311
1312 // NOTE: The order of these pushes is known to frame::interpreter_frame_result
1313 // in order to extract the result of a method call. If the order of these
1314 // pushes change or anything else is added to the stack then the code in
1315 // interpreter_frame_result must also change.
1316 __ push(dtos);
1317 __ push(ltos);
1318
1319 __ verify_sve_vector_length();
1320
1321 // change thread state
1322 __ mov(rscratch1, _thread_in_native_trans);
1323 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset()));
1324 __ stlrw(rscratch1, rscratch2);
1325
1326 // Force this write out before the read below
1327 __ dmb(Assembler::ISH);
1328
1329 // check for safepoint operation in progress and/or pending suspend requests
1330 {
1331 Label L, Continue;
1332
1333 // We need an acquire here to ensure that any subsequent load of the
1334 // global SafepointSynchronize::_state flag is ordered after this load
1335 // of the thread-local polling word. We don't want this poll to
1336 // return false (i.e. not safepointing) and a later poll of the global
1337 // SafepointSynchronize::_state spuriously to return true.
1338 //
1339 // This is to avoid a race when we're in a native->Java transition
1340 // racing the code which wakes up from a safepoint.
1341 __ safepoint_poll(L, true /* at_return */, true /* acquire */, false /* in_nmethod */);
1342 __ ldrw(rscratch2, Address(rthread, JavaThread::suspend_flags_offset()));
1343 __ cbz(rscratch2, Continue);
1344 __ bind(L);
1345
1346 // Don't use call_VM as it will see a possible pending exception
1347 // and forward it and never return here preventing us from
1348 // clearing _last_native_pc down below. So we do a runtime call by
1349 // hand.
1350 //
1351 __ mov(c_rarg0, rthread);
1352 __ mov(rscratch2, CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans));
1353 __ blr(rscratch2);
1354 __ get_method(rmethod);
1355 __ reinit_heapbase();
1356 __ bind(Continue);
1357 }
1358
1359 // change thread state
1360 __ mov(rscratch1, _thread_in_Java);
1361 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset()));
1362 __ stlrw(rscratch1, rscratch2);
1363
1364 // reset_last_Java_frame
1365 __ reset_last_Java_frame(true);
1366
1367 if (CheckJNICalls) {
1368 // clear_pending_jni_exception_check
1369 __ str(zr, Address(rthread, JavaThread::pending_jni_exception_check_fn_offset()));
1370 }
1371
1372 // reset handle block
1373 __ ldr(t, Address(rthread, JavaThread::active_handles_offset()));
1374 __ str(zr, Address(t, JNIHandleBlock::top_offset_in_bytes()));
1375
1376 // If result is an oop unbox and store it in frame where gc will see it
1377 // and result handler will pick it up
1378
1379 {
1380 Label no_oop;
1381 __ adr(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT)));
1382 __ cmp(t, result_handler);
1383 __ br(Assembler::NE, no_oop);
1384 // Unbox oop result, e.g. JNIHandles::resolve result.
1385 __ pop(ltos);
1386 __ resolve_jobject(r0, rthread, t);
1387 __ str(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize));
1388 // keep stack depth as expected by pushing oop which will eventually be discarded
1389 __ push(ltos);
1390 __ bind(no_oop);
1391 }
1392
1393 {
1394 Label no_reguard;
1395 __ lea(rscratch1, Address(rthread, in_bytes(JavaThread::stack_guard_state_offset())));
1396 __ ldrw(rscratch1, Address(rscratch1));
1397 __ cmp(rscratch1, (u1)StackOverflow::stack_guard_yellow_reserved_disabled);
1398 __ br(Assembler::NE, no_reguard);
1399
1400 __ pusha(); // XXX only save smashed registers
1401 __ mov(c_rarg0, rthread);
1402 __ mov(rscratch2, CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages));
1403 __ blr(rscratch2);
1404 __ popa(); // XXX only restore smashed registers
1405 __ bind(no_reguard);
1406 }
1407
1408 // The method register is junk from after the thread_in_native transition
1409 // until here. Also can't call_VM until the bcp has been
1410 // restored. Need bcp for throwing exception below so get it now.
1411 __ get_method(rmethod);
1412
1413 // restore bcp to have legal interpreter frame, i.e., bci == 0 <=>
1414 // rbcp == code_base()
1415 __ ldr(rbcp, Address(rmethod, Method::const_offset())); // get ConstMethod*
1416 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset())); // get codebase
1417 // handle exceptions (exception handling will handle unlocking!)
1418 {
1419 Label L;
1420 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset()));
1421 __ cbz(rscratch1, L);
1422 // Note: At some point we may want to unify this with the code
1423 // used in call_VM_base(); i.e., we should use the
1424 // StubRoutines::forward_exception code. For now this doesn't work
1425 // here because the rsp is not correctly set at this point.
1426 __ MacroAssembler::call_VM(noreg,
1427 CAST_FROM_FN_PTR(address,
1428 InterpreterRuntime::throw_pending_exception));
1429 __ should_not_reach_here();
1430 __ bind(L);
1431 }
1432
1433 // do unlocking if necessary
1434 {
1435 Label L;
1436 __ ldrw(t, Address(rmethod, Method::access_flags_offset()));
1437 __ tbz(t, exact_log2(JVM_ACC_SYNCHRONIZED), L);
1438 // the code below should be shared with interpreter macro
1439 // assembler implementation
1440 {
1441 Label unlock;
1442 // BasicObjectLock will be first in list, since this is a
1443 // synchronized method. However, need to check that the object
1444 // has not been unlocked by an explicit monitorexit bytecode.
1445
1446 // monitor expect in c_rarg1 for slow unlock path
1447 __ lea (c_rarg1, Address(rfp, // address of first monitor
1448 (intptr_t)(frame::interpreter_frame_initial_sp_offset *
1449 wordSize - sizeof(BasicObjectLock))));
1450
1451 __ ldr(t, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
1452 __ cbnz(t, unlock);
1453
1454 // Entry already unlocked, need to throw exception
1455 __ MacroAssembler::call_VM(noreg,
1456 CAST_FROM_FN_PTR(address,
1457 InterpreterRuntime::throw_illegal_monitor_state_exception));
1458 __ should_not_reach_here();
1459
1460 __ bind(unlock);
1461 __ unlock_object(c_rarg1);
1462 }
1463 __ bind(L);
1464 }
1465
1466 // jvmti support
1467 // Note: This must happen _after_ handling/throwing any exceptions since
1468 // the exception handler code notifies the runtime of method exits
1469 // too. If this happens before, method entry/exit notifications are
1470 // not properly paired (was bug - gri 11/22/99).
1471 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
1472
1473 // restore potential result in r0:d0, call result handler to
1474 // restore potential result in ST0 & handle result
1475
1476 __ pop(ltos);
1477 __ pop(dtos);
1478
1479 __ blr(result_handler);
1480
1481 // remove activation
1482 __ ldr(esp, Address(rfp,
1483 frame::interpreter_frame_sender_sp_offset *
1484 wordSize)); // get sender sp
1485 // remove frame anchor
1486 __ leave();
1487
1488 // resture sender sp
1489 __ mov(sp, esp);
1490
1491 __ ret(lr);
1492
1493 if (inc_counter) {
1494 // Handle overflow of counter and compile method
1495 __ bind(invocation_counter_overflow);
1496 generate_counter_overflow(continue_after_compile);
1497 }
1498
1499 return entry_point;
1500 }
1501
1502 //
1503 // Generic interpreted method entry to (asm) interpreter
1504 //
generate_normal_entry(bool synchronized)1505 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) {
1506 // determine code generation flags
1507 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods;
1508
1509 // rscratch1: sender sp
1510 address entry_point = __ pc();
1511
1512 const Address constMethod(rmethod, Method::const_offset());
1513 const Address access_flags(rmethod, Method::access_flags_offset());
1514 const Address size_of_parameters(r3,
1515 ConstMethod::size_of_parameters_offset());
1516 const Address size_of_locals(r3, ConstMethod::size_of_locals_offset());
1517
1518 // get parameter size (always needed)
1519 // need to load the const method first
1520 __ ldr(r3, constMethod);
1521 __ load_unsigned_short(r2, size_of_parameters);
1522
1523 // r2: size of parameters
1524
1525 __ load_unsigned_short(r3, size_of_locals); // get size of locals in words
1526 __ sub(r3, r3, r2); // r3 = no. of additional locals
1527
1528 // see if we've got enough room on the stack for locals plus overhead.
1529 generate_stack_overflow_check();
1530
1531 // compute beginning of parameters (rlocals)
1532 __ add(rlocals, esp, r2, ext::uxtx, 3);
1533 __ sub(rlocals, rlocals, wordSize);
1534
1535 __ mov(rscratch1, esp);
1536
1537 // r3 - # of additional locals
1538 // allocate space for locals
1539 // explicitly initialize locals
1540 // Initializing memory allocated for locals in the same direction as
1541 // the stack grows to ensure page initialization order according
1542 // to windows-aarch64 stack page growth requirement (see
1543 // https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-160#stack)
1544 {
1545 Label exit, loop;
1546 __ ands(zr, r3, r3);
1547 __ br(Assembler::LE, exit); // do nothing if r3 <= 0
1548 __ bind(loop);
1549 __ str(zr, Address(__ pre(rscratch1, -wordSize)));
1550 __ sub(r3, r3, 1); // until everything initialized
1551 __ cbnz(r3, loop);
1552 __ bind(exit);
1553 }
1554
1555 // Padding between locals and fixed part of activation frame to ensure
1556 // SP is always 16-byte aligned.
1557 __ andr(sp, rscratch1, -16);
1558
1559 // And the base dispatch table
1560 __ get_dispatch();
1561
1562 // initialize fixed part of activation frame
1563 generate_fixed_frame(false);
1564
1565 // make sure method is not native & not abstract
1566 #ifdef ASSERT
1567 __ ldrw(r0, access_flags);
1568 {
1569 Label L;
1570 __ tst(r0, JVM_ACC_NATIVE);
1571 __ br(Assembler::EQ, L);
1572 __ stop("tried to execute native method as non-native");
1573 __ bind(L);
1574 }
1575 {
1576 Label L;
1577 __ tst(r0, JVM_ACC_ABSTRACT);
1578 __ br(Assembler::EQ, L);
1579 __ stop("tried to execute abstract method in interpreter");
1580 __ bind(L);
1581 }
1582 #endif
1583
1584 // Since at this point in the method invocation the exception
1585 // handler would try to exit the monitor of synchronized methods
1586 // which hasn't been entered yet, we set the thread local variable
1587 // _do_not_unlock_if_synchronized to true. The remove_activation
1588 // will check this flag.
1589
1590 const Address do_not_unlock_if_synchronized(rthread,
1591 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
1592 __ mov(rscratch2, true);
1593 __ strb(rscratch2, do_not_unlock_if_synchronized);
1594
1595 Register mdp = r3;
1596 __ profile_parameters_type(mdp, r1, r2);
1597
1598 // increment invocation count & check for overflow
1599 Label invocation_counter_overflow;
1600 if (inc_counter) {
1601 generate_counter_incr(&invocation_counter_overflow);
1602 }
1603
1604 Label continue_after_compile;
1605 __ bind(continue_after_compile);
1606
1607 bang_stack_shadow_pages(false);
1608
1609 // reset the _do_not_unlock_if_synchronized flag
1610 __ strb(zr, do_not_unlock_if_synchronized);
1611
1612 // check for synchronized methods
1613 // Must happen AFTER invocation_counter check and stack overflow check,
1614 // so method is not locked if overflows.
1615 if (synchronized) {
1616 // Allocate monitor and lock method
1617 lock_method();
1618 } else {
1619 // no synchronization necessary
1620 #ifdef ASSERT
1621 {
1622 Label L;
1623 __ ldrw(r0, access_flags);
1624 __ tst(r0, JVM_ACC_SYNCHRONIZED);
1625 __ br(Assembler::EQ, L);
1626 __ stop("method needs synchronization");
1627 __ bind(L);
1628 }
1629 #endif
1630 }
1631
1632 // start execution
1633 #ifdef ASSERT
1634 {
1635 Label L;
1636 const Address monitor_block_top (rfp,
1637 frame::interpreter_frame_monitor_block_top_offset * wordSize);
1638 __ ldr(rscratch1, monitor_block_top);
1639 __ cmp(esp, rscratch1);
1640 __ br(Assembler::EQ, L);
1641 __ stop("broken stack frame setup in interpreter");
1642 __ bind(L);
1643 }
1644 #endif
1645
1646 // jvmti support
1647 __ notify_method_entry();
1648
1649 __ dispatch_next(vtos);
1650
1651 // invocation counter overflow
1652 if (inc_counter) {
1653 // Handle overflow of counter and compile method
1654 __ bind(invocation_counter_overflow);
1655 generate_counter_overflow(continue_after_compile);
1656 }
1657
1658 return entry_point;
1659 }
1660
1661 //-----------------------------------------------------------------------------
1662 // Exceptions
1663
generate_throw_exception()1664 void TemplateInterpreterGenerator::generate_throw_exception() {
1665 // Entry point in previous activation (i.e., if the caller was
1666 // interpreted)
1667 Interpreter::_rethrow_exception_entry = __ pc();
1668 // Restore sp to interpreter_frame_last_sp even though we are going
1669 // to empty the expression stack for the exception processing.
1670 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1671 // r0: exception
1672 // r3: return address/pc that threw exception
1673 __ restore_bcp(); // rbcp points to call/send
1674 __ restore_locals();
1675 __ restore_constant_pool_cache();
1676 __ reinit_heapbase(); // restore rheapbase as heapbase.
1677 __ get_dispatch();
1678
1679 // Entry point for exceptions thrown within interpreter code
1680 Interpreter::_throw_exception_entry = __ pc();
1681 // If we came here via a NullPointerException on the receiver of a
1682 // method, rmethod may be corrupt.
1683 __ get_method(rmethod);
1684 // expression stack is undefined here
1685 // r0: exception
1686 // rbcp: exception bcp
1687 __ verify_oop(r0);
1688 __ mov(c_rarg1, r0);
1689
1690 // expression stack must be empty before entering the VM in case of
1691 // an exception
1692 __ empty_expression_stack();
1693 // find exception handler address and preserve exception oop
1694 __ call_VM(r3,
1695 CAST_FROM_FN_PTR(address,
1696 InterpreterRuntime::exception_handler_for_exception),
1697 c_rarg1);
1698
1699 // Calculate stack limit
1700 __ ldr(rscratch1, Address(rmethod, Method::const_offset()));
1701 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset()));
1702 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 4);
1703 __ ldr(rscratch2,
1704 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize));
1705 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtx, 3);
1706 __ andr(sp, rscratch1, -16);
1707
1708 // r0: exception handler entry point
1709 // r3: preserved exception oop
1710 // rbcp: bcp for exception handler
1711 __ push_ptr(r3); // push exception which is now the only value on the stack
1712 __ br(r0); // jump to exception handler (may be _remove_activation_entry!)
1713
1714 // If the exception is not handled in the current frame the frame is
1715 // removed and the exception is rethrown (i.e. exception
1716 // continuation is _rethrow_exception).
1717 //
1718 // Note: At this point the bci is still the bxi for the instruction
1719 // which caused the exception and the expression stack is
1720 // empty. Thus, for any VM calls at this point, GC will find a legal
1721 // oop map (with empty expression stack).
1722
1723 //
1724 // JVMTI PopFrame support
1725 //
1726
1727 Interpreter::_remove_activation_preserving_args_entry = __ pc();
1728 __ empty_expression_stack();
1729 // Set the popframe_processing bit in pending_popframe_condition
1730 // indicating that we are currently handling popframe, so that
1731 // call_VMs that may happen later do not trigger new popframe
1732 // handling cycles.
1733 __ ldrw(r3, Address(rthread, JavaThread::popframe_condition_offset()));
1734 __ orr(r3, r3, JavaThread::popframe_processing_bit);
1735 __ strw(r3, Address(rthread, JavaThread::popframe_condition_offset()));
1736
1737 {
1738 // Check to see whether we are returning to a deoptimized frame.
1739 // (The PopFrame call ensures that the caller of the popped frame is
1740 // either interpreted or compiled and deoptimizes it if compiled.)
1741 // In this case, we can't call dispatch_next() after the frame is
1742 // popped, but instead must save the incoming arguments and restore
1743 // them after deoptimization has occurred.
1744 //
1745 // Note that we don't compare the return PC against the
1746 // deoptimization blob's unpack entry because of the presence of
1747 // adapter frames in C2.
1748 Label caller_not_deoptimized;
1749 __ ldr(c_rarg1, Address(rfp, frame::return_addr_offset * wordSize));
1750 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
1751 InterpreterRuntime::interpreter_contains), c_rarg1);
1752 __ cbnz(r0, caller_not_deoptimized);
1753
1754 // Compute size of arguments for saving when returning to
1755 // deoptimized caller
1756 __ get_method(r0);
1757 __ ldr(r0, Address(r0, Method::const_offset()));
1758 __ load_unsigned_short(r0, Address(r0, in_bytes(ConstMethod::
1759 size_of_parameters_offset())));
1760 __ lsl(r0, r0, Interpreter::logStackElementSize);
1761 __ restore_locals(); // XXX do we need this?
1762 __ sub(rlocals, rlocals, r0);
1763 __ add(rlocals, rlocals, wordSize);
1764 // Save these arguments
1765 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
1766 Deoptimization::
1767 popframe_preserve_args),
1768 rthread, r0, rlocals);
1769
1770 __ remove_activation(vtos,
1771 /* throw_monitor_exception */ false,
1772 /* install_monitor_exception */ false,
1773 /* notify_jvmdi */ false);
1774
1775 // Inform deoptimization that it is responsible for restoring
1776 // these arguments
1777 __ mov(rscratch1, JavaThread::popframe_force_deopt_reexecution_bit);
1778 __ strw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset()));
1779
1780 // Continue in deoptimization handler
1781 __ ret(lr);
1782
1783 __ bind(caller_not_deoptimized);
1784 }
1785
1786 __ remove_activation(vtos,
1787 /* throw_monitor_exception */ false,
1788 /* install_monitor_exception */ false,
1789 /* notify_jvmdi */ false);
1790
1791 // Restore the last_sp and null it out
1792 __ ldr(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1793 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1794
1795 __ restore_bcp();
1796 __ restore_locals();
1797 __ restore_constant_pool_cache();
1798 __ get_method(rmethod);
1799 __ get_dispatch();
1800
1801 // The method data pointer was incremented already during
1802 // call profiling. We have to restore the mdp for the current bcp.
1803 if (ProfileInterpreter) {
1804 __ set_method_data_pointer_for_bcp();
1805 }
1806
1807 // Clear the popframe condition flag
1808 __ strw(zr, Address(rthread, JavaThread::popframe_condition_offset()));
1809 assert(JavaThread::popframe_inactive == 0, "fix popframe_inactive");
1810
1811 #if INCLUDE_JVMTI
1812 {
1813 Label L_done;
1814
1815 __ ldrb(rscratch1, Address(rbcp, 0));
1816 __ cmpw(rscratch1, Bytecodes::_invokestatic);
1817 __ br(Assembler::NE, L_done);
1818
1819 // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call.
1820 // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL.
1821
1822 __ ldr(c_rarg0, Address(rlocals, 0));
1823 __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), c_rarg0, rmethod, rbcp);
1824
1825 __ cbz(r0, L_done);
1826
1827 __ str(r0, Address(esp, 0));
1828 __ bind(L_done);
1829 }
1830 #endif // INCLUDE_JVMTI
1831
1832 // Restore machine SP
1833 __ ldr(rscratch1, Address(rmethod, Method::const_offset()));
1834 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset()));
1835 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 4);
1836 __ ldr(rscratch2,
1837 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize));
1838 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtw, 3);
1839 __ andr(sp, rscratch1, -16);
1840
1841 __ dispatch_next(vtos);
1842 // end of PopFrame support
1843
1844 Interpreter::_remove_activation_entry = __ pc();
1845
1846 // preserve exception over this code sequence
1847 __ pop_ptr(r0);
1848 __ str(r0, Address(rthread, JavaThread::vm_result_offset()));
1849 // remove the activation (without doing throws on illegalMonitorExceptions)
1850 __ remove_activation(vtos, false, true, false);
1851 // restore exception
1852 __ get_vm_result(r0, rthread);
1853
1854 // In between activations - previous activation type unknown yet
1855 // compute continuation point - the continuation point expects the
1856 // following registers set up:
1857 //
1858 // r0: exception
1859 // lr: return address/pc that threw exception
1860 // esp: expression stack of caller
1861 // rfp: fp of caller
1862 __ stp(r0, lr, Address(__ pre(sp, -2 * wordSize))); // save exception & return address
1863 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
1864 SharedRuntime::exception_handler_for_return_address),
1865 rthread, lr);
1866 __ mov(r1, r0); // save exception handler
1867 __ ldp(r0, lr, Address(__ post(sp, 2 * wordSize))); // restore exception & return address
1868 // We might be returning to a deopt handler that expects r3 to
1869 // contain the exception pc
1870 __ mov(r3, lr);
1871 // Note that an "issuing PC" is actually the next PC after the call
1872 __ br(r1); // jump to exception
1873 // handler of caller
1874 }
1875
1876
1877 //
1878 // JVMTI ForceEarlyReturn support
1879 //
generate_earlyret_entry_for(TosState state)1880 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
1881 address entry = __ pc();
1882
1883 __ restore_bcp();
1884 __ restore_locals();
1885 __ empty_expression_stack();
1886 __ load_earlyret_value(state);
1887
1888 __ ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
1889 Address cond_addr(rscratch1, JvmtiThreadState::earlyret_state_offset());
1890
1891 // Clear the earlyret state
1892 assert(JvmtiThreadState::earlyret_inactive == 0, "should be");
1893 __ str(zr, cond_addr);
1894
1895 __ remove_activation(state,
1896 false, /* throw_monitor_exception */
1897 false, /* install_monitor_exception */
1898 true); /* notify_jvmdi */
1899 __ ret(lr);
1900
1901 return entry;
1902 } // end of ForceEarlyReturn support
1903
1904
1905
1906 //-----------------------------------------------------------------------------
1907 // Helper for vtos entry point generation
1908
set_vtos_entry_points(Template * t,address & bep,address & cep,address & sep,address & aep,address & iep,address & lep,address & fep,address & dep,address & vep)1909 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
1910 address& bep,
1911 address& cep,
1912 address& sep,
1913 address& aep,
1914 address& iep,
1915 address& lep,
1916 address& fep,
1917 address& dep,
1918 address& vep) {
1919 assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
1920 Label L;
1921 aep = __ pc(); __ push_ptr(); __ b(L);
1922 fep = __ pc(); __ push_f(); __ b(L);
1923 dep = __ pc(); __ push_d(); __ b(L);
1924 lep = __ pc(); __ push_l(); __ b(L);
1925 bep = cep = sep =
1926 iep = __ pc(); __ push_i();
1927 vep = __ pc();
1928 __ bind(L);
1929 generate_and_dispatch(t);
1930 }
1931
1932 //-----------------------------------------------------------------------------
1933
1934 // Non-product code
1935 #ifndef PRODUCT
generate_trace_code(TosState state)1936 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
1937 address entry = __ pc();
1938
1939 __ push(lr);
1940 __ push(state);
1941 __ push(RegSet::range(r0, r15), sp);
1942 __ mov(c_rarg2, r0); // Pass itos
1943 __ call_VM(noreg,
1944 CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode),
1945 c_rarg1, c_rarg2, c_rarg3);
1946 __ pop(RegSet::range(r0, r15), sp);
1947 __ pop(state);
1948 __ pop(lr);
1949 __ ret(lr); // return from result handler
1950
1951 return entry;
1952 }
1953
count_bytecode()1954 void TemplateInterpreterGenerator::count_bytecode() {
1955 Register rscratch3 = r0;
1956 __ push(rscratch1);
1957 __ push(rscratch2);
1958 __ push(rscratch3);
1959 __ mov(rscratch3, (address) &BytecodeCounter::_counter_value);
1960 __ atomic_add(noreg, 1, rscratch3);
1961 __ pop(rscratch3);
1962 __ pop(rscratch2);
1963 __ pop(rscratch1);
1964 }
1965
histogram_bytecode(Template * t)1966 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) { ; }
1967
histogram_bytecode_pair(Template * t)1968 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) { ; }
1969
1970
trace_bytecode(Template * t)1971 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
1972 // Call a little run-time stub to avoid blow-up for each bytecode.
1973 // The run-time runtime saves the right registers, depending on
1974 // the tosca in-state for the given template.
1975
1976 assert(Interpreter::trace_code(t->tos_in()) != NULL,
1977 "entry must have been generated");
1978 __ bl(Interpreter::trace_code(t->tos_in()));
1979 __ reinit_heapbase();
1980 }
1981
1982
stop_interpreter_at()1983 void TemplateInterpreterGenerator::stop_interpreter_at() {
1984 Label L;
1985 __ push(rscratch1);
1986 __ mov(rscratch1, (address) &BytecodeCounter::_counter_value);
1987 __ ldr(rscratch1, Address(rscratch1));
1988 __ mov(rscratch2, StopInterpreterAt);
1989 __ cmpw(rscratch1, rscratch2);
1990 __ br(Assembler::NE, L);
1991 __ brk(0);
1992 __ bind(L);
1993 __ pop(rscratch1);
1994 }
1995
1996 #endif // !PRODUCT
1997