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