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