Tue, 05 Mar 2019 17:00:17 +0800
#8573 Cleanup: x86 registers in comments; comment style; deadcode
Reviewed-by: zhaixiang
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2019, Loongson Technology. 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 */
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/templateTable.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/methodData.hpp"
35 #include "oops/method.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "prims/jvmtiExport.hpp"
38 #include "prims/jvmtiThreadState.hpp"
39 #include "runtime/arguments.hpp"
40 #include "runtime/deoptimization.hpp"
41 #include "runtime/frame.inline.hpp"
42 #include "runtime/sharedRuntime.hpp"
43 #include "runtime/stubRoutines.hpp"
44 #include "runtime/synchronizer.hpp"
45 #include "runtime/timer.hpp"
46 #include "runtime/vframeArray.hpp"
47 #include "utilities/debug.hpp"
49 #define __ _masm->
51 #ifndef CC_INTERP
53 // asm based interpreter deoptimization helpers
54 int AbstractInterpreter::size_activation(int max_stack,
55 int temps,
56 int extra_args,
57 int monitors,
58 int callee_params,
59 int callee_locals,
60 bool is_top_frame) {
61 // Note: This calculation must exactly parallel the frame setup
62 // in AbstractInterpreterGenerator::generate_method_entry.
64 // fixed size of an interpreter frame:
65 int overhead = frame::sender_sp_offset -
66 frame::interpreter_frame_initial_sp_offset;
67 // Our locals were accounted for by the caller (or last_frame_adjust
68 // on the transistion) Since the callee parameters already account
69 // for the callee's params we only need to account for the extra
70 // locals.
71 int size = overhead +
72 (callee_locals - callee_params)*Interpreter::stackElementWords +
73 monitors * frame::interpreter_frame_monitor_size() +
74 temps* Interpreter::stackElementWords + extra_args;
76 return size;
77 }
80 const int Interpreter::return_sentinel = 0xfeedbeed;
81 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
82 const int bci_offset = frame::interpreter_frame_bcx_offset * wordSize;
83 const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
85 //-----------------------------------------------------------------------------
87 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
88 address entry = __ pc();
90 #ifdef ASSERT
91 {
92 Label L;
93 __ addi(T1, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
94 __ sub(T1, T1, SP); // T1 = maximal sp for current fp
95 __ bgez(T1, L); // check if frame is complete
96 __ delayed()->nop();
97 __ stop("interpreter frame not set up");
98 __ bind(L);
99 }
100 #endif // ASSERT
101 // Restore bcp under the assumption that the current frame is still
102 // interpreted
103 // FIXME: please change the func restore_bcp
104 // S0 is the conventional register for bcp
105 __ restore_bcp();
107 // expression stack must be empty before entering the VM if an
108 // exception happened
109 __ empty_expression_stack();
110 // throw exception
111 // FIXME: why do not pass parameter thread ?
112 __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
113 return entry;
114 }
116 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(
117 const char* name) {
118 address entry = __ pc();
119 // expression stack must be empty before entering the VM if an
120 // exception happened
121 __ empty_expression_stack();
122 __ li(A1, (long)name);
123 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
124 InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), A1, A2);
125 return entry;
126 }
128 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
129 address entry = __ pc();
131 // expression stack must be empty before entering the VM if an
132 // exception happened
133 __ empty_expression_stack();
134 __ empty_FPU_stack();
135 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException), FSR);
136 return entry;
137 }
139 address TemplateInterpreterGenerator::generate_exception_handler_common(
140 const char* name, const char* message, bool pass_oop) {
141 assert(!pass_oop || message == NULL, "either oop or message but not both");
142 address entry = __ pc();
144 // expression stack must be empty before entering the VM if an exception happened
145 __ empty_expression_stack();
146 // setup parameters
147 __ li(A1, (long)name);
148 if (pass_oop) {
149 __ call_VM(V0,
150 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), A1, FSR);
151 } else {
152 __ li(A2, (long)message);
153 __ call_VM(V0,
154 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), A1, A2);
155 }
156 // throw exception
157 __ jmp(Interpreter::throw_exception_entry(), relocInfo::none);
158 __ delayed()->nop();
159 return entry;
160 }
163 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
164 address entry = __ pc();
165 // NULL last_sp until next java call
166 __ sd(R0,Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
167 __ dispatch_next(state);
168 return entry;
169 }
172 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
174 address entry = __ pc();
176 // Restore stack bottom in case i2c adjusted stack
177 __ ld(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
178 // and NULL it as marker that sp is now tos until next java call
179 __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
181 __ restore_bcp();
182 __ restore_locals();
184 // 2014/11/24 Fu
185 // mdp: T8
186 // ret: FSR
187 // tmp: T9
188 if (state == atos) {
189 Register mdp = T8;
190 Register tmp = T9;
191 __ profile_return_type(mdp, FSR, tmp);
192 }
195 const Register cache = T9;
196 const Register index = T3;
197 __ get_cache_and_index_at_bcp(cache, index, 1, index_size);
199 const Register flags = cache;
200 __ dsll(AT, index, Address::times_ptr);
201 __ daddu(AT, cache, AT);
202 __ lw(flags, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
203 __ andi(flags, flags, ConstantPoolCacheEntry::parameter_size_mask);
204 __ dsll(AT, flags, Interpreter::stackElementScale());
205 __ daddu(SP, SP, AT);
207 __ dispatch_next(state, step);
209 return entry;
210 }
213 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
214 int step) {
215 address entry = __ pc();
216 // NULL last_sp until next java call
217 __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
218 __ restore_bcp();
219 __ restore_locals();
220 // handle exceptions
221 {
222 Label L;
223 const Register thread = TREG;
224 #ifndef OPT_THREAD
225 __ get_thread(thread);
226 #endif
227 __ lw(AT, thread, in_bytes(Thread::pending_exception_offset()));
228 __ beq(AT, R0, L);
229 __ delayed()->nop();
230 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
231 __ should_not_reach_here();
232 __ bind(L);
233 }
234 __ dispatch_next(state, step);
235 return entry;
236 }
238 int AbstractInterpreter::BasicType_as_index(BasicType type) {
239 int i = 0;
240 switch (type) {
241 case T_BOOLEAN: i = 0; break;
242 case T_CHAR : i = 1; break;
243 case T_BYTE : i = 2; break;
244 case T_SHORT : i = 3; break;
245 case T_INT : // fall through
246 case T_LONG : // fall through
247 case T_VOID : i = 4; break;
248 case T_FLOAT : i = 5; break;
249 case T_DOUBLE : i = 6; break;
250 case T_OBJECT : // fall through
251 case T_ARRAY : i = 7; break;
252 default : ShouldNotReachHere();
253 }
254 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
255 "index out of bounds");
256 return i;
257 }
260 address TemplateInterpreterGenerator::generate_result_handler_for(
261 BasicType type) {
262 address entry = __ pc();
263 switch (type) {
264 case T_BOOLEAN: __ c2bool(V0); break;
265 case T_CHAR : __ andi(V0, V0, 0xFFFF); break;
266 case T_BYTE : __ sign_extend_byte (V0); break;
267 case T_SHORT : __ sign_extend_short(V0); break;
268 case T_INT : /* nothing to do */ break;
269 case T_FLOAT : /* nothing to do */ break;
270 case T_DOUBLE : /* nothing to do */ break;
271 case T_OBJECT :
272 {
273 __ ld(V0, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
274 __ verify_oop(V0); // and verify it
275 }
276 break;
277 default : ShouldNotReachHere();
278 }
279 __ jr(RA); // return from result handler
280 __ delayed()->nop();
281 return entry;
282 }
284 address TemplateInterpreterGenerator::generate_safept_entry_for(
285 TosState state,
286 address runtime_entry) {
287 address entry = __ pc();
288 __ push(state);
289 __ call_VM(noreg, runtime_entry);
290 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
291 return entry;
292 }
296 // Helpers for commoning out cases in the various type of method entries.
297 //
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 // T3 : invocation counter
307 //
308 void InterpreterGenerator::generate_counter_incr(
309 Label* overflow,
310 Label* profile_method,
311 Label* profile_method_continue) {
312 Label done;
313 if (TieredCompilation) {
314 int increment = InvocationCounter::count_increment;
315 int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
316 Label no_mdo;
317 if (ProfileInterpreter) {
318 // Are we profiling?
319 __ ld(FSR, Address(Rmethod, Method::method_data_offset()));
320 __ beq(FSR, R0, no_mdo);
321 __ delayed()->nop();
322 // Increment counter in the MDO
323 const Address mdo_invocation_counter(FSR, in_bytes(MethodData::invocation_counter_offset()) +
324 in_bytes(InvocationCounter::counter_offset()));
325 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, T3, false, Assembler::zero, overflow);
326 __ beq(R0, R0, done);
327 __ delayed()->nop();
328 }
329 __ bind(no_mdo);
330 // Increment counter in MethodCounters
331 const Address invocation_counter(FSR,
332 MethodCounters::invocation_counter_offset() +
333 InvocationCounter::counter_offset());
334 __ get_method_counters(Rmethod, FSR, done);
335 __ increment_mask_and_jump(invocation_counter, increment, mask, T3, false, Assembler::zero, overflow);
336 __ bind(done);
337 } else {
338 const Address invocation_counter(FSR, in_bytes(MethodCounters::invocation_counter_offset())
339 + in_bytes(InvocationCounter::counter_offset()));
340 const Address backedge_counter (FSR, in_bytes(MethodCounters::backedge_counter_offset())
341 + in_bytes(InvocationCounter::counter_offset()));
343 __ get_method_counters(Rmethod, FSR, done);
345 if (ProfileInterpreter) { // %%% Merge this into methodDataOop
346 __ lw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
347 __ incrementl(T9, 1);
348 __ sw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
349 }
350 // Update standard invocation counters
351 __ lw(T3, invocation_counter);
352 __ increment(T3, InvocationCounter::count_increment);
353 __ sw(T3, invocation_counter); // save invocation count
355 __ lw(FSR, backedge_counter); // load backedge counter
356 __ li(AT, InvocationCounter::count_mask_value); // mask out the status bits
357 __ andr(FSR, FSR, AT);
359 __ dadd(T3, T3, FSR); // add both counters
361 if (ProfileInterpreter && profile_method != NULL) {
362 // Test to see if we should create a method data oop
363 if (Assembler::is_simm16(InvocationCounter::InterpreterProfileLimit)) {
364 __ slti(AT, T3, InvocationCounter::InterpreterProfileLimit);
365 } else {
366 __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
367 __ lw(AT, AT, 0);
368 __ slt(AT, T3, AT);
369 }
371 __ bne_far(AT, R0, *profile_method_continue);
372 __ delayed()->nop();
374 // if no method data exists, go to profile_method
375 __ test_method_data_pointer(FSR, *profile_method);
376 }
378 if (Assembler::is_simm16(CompileThreshold)) {
379 __ srl(AT, T3, InvocationCounter::count_shift);
380 __ slti(AT, AT, CompileThreshold);
381 } else {
382 __ li(AT, (long)&InvocationCounter::InterpreterInvocationLimit);
383 __ lw(AT, AT, 0);
384 __ slt(AT, T3, AT);
385 }
387 __ beq_far(AT, R0, *overflow);
388 __ delayed()->nop();
389 __ bind(done);
390 }
391 }
393 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
395 // Asm interpreter on entry
396 // S7 - locals
397 // S0 - bcp
398 // Rmethod - method
399 // FP - interpreter frame
401 // On return (i.e. jump to entry_point)
402 // Rmethod - method
403 // RA - return address of interpreter caller
404 // tos - the last parameter to Java method
405 // SP - sender_sp
407 //const Address size_of_parameters(Rmethod,in_bytes( Method::size_of_parameters_offset()));
409 // the bcp is valid if and only if it's not null
410 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
411 InterpreterRuntime::frequency_counter_overflow), R0);
412 __ ld(Rmethod, FP, method_offset);
413 // Preserve invariant that S0/S7 contain bcp/locals of sender frame
414 __ b_far(*do_continue);
415 __ delayed()->nop();
416 }
418 // See if we've got enough room on the stack for locals plus overhead.
419 // The expression stack grows down incrementally, so the normal guard
420 // page mechanism will work for that.
421 //
422 // NOTE: Since the additional locals are also always pushed (wasn't
423 // obvious in generate_method_entry) so the guard should work for them
424 // too.
425 //
426 // Args:
427 // T2: number of additional locals this frame needs (what we must check)
428 // T0: Method*
429 //
430 void InterpreterGenerator::generate_stack_overflow_check(void) {
431 // see if we've got enough room on the stack for locals plus overhead.
432 // the expression stack grows down incrementally, so the normal guard
433 // page mechanism will work for that.
434 //
435 // Registers live on entry:
436 //
437 // T0: Method*
438 // T2: number of additional locals this frame needs (what we must check)
440 // NOTE: since the additional locals are also always pushed (wasn't obvious in
441 // generate_method_entry) so the guard should work for them too.
442 //
444 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
446 // total overhead size: entry_size + (saved fp thru expr stack bottom).
447 // be sure to change this if you add/subtract anything to/from the overhead area
448 const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize)
449 + entry_size;
451 const int page_size = os::vm_page_size();
453 Label after_frame_check;
455 // see if the frame is greater than one page in size. If so,
456 // then we need to verify there is enough stack space remaining
457 // for the additional locals.
458 __ move(AT, (page_size - overhead_size) / Interpreter::stackElementSize);
459 __ slt(AT, AT, T2);
460 __ beq(AT, R0, after_frame_check);
461 __ delayed()->nop();
463 // compute sp as if this were going to be the last frame on
464 // the stack before the red zone
465 #ifndef OPT_THREAD
466 Register thread = T1;
467 __ get_thread(thread);
468 #else
469 Register thread = TREG;
470 #endif
472 // locals + overhead, in bytes
473 __ dsll(T3, T2, Interpreter::stackElementScale());
474 __ daddiu(T3, T3, overhead_size); // locals * 4 + overhead_size --> T3
476 #ifdef ASSERT
477 Label stack_base_okay, stack_size_okay;
478 // verify that thread stack base is non-zero
479 __ ld(AT, thread, in_bytes(Thread::stack_base_offset()));
480 __ bne(AT, R0, stack_base_okay);
481 __ delayed()->nop();
482 __ stop("stack base is zero");
483 __ bind(stack_base_okay);
484 // verify that thread stack size is non-zero
485 __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));
486 __ bne(AT, R0, stack_size_okay);
487 __ delayed()->nop();
488 __ stop("stack size is zero");
489 __ bind(stack_size_okay);
490 #endif
492 // Add stack base to locals and subtract stack size
493 __ ld(AT, thread, in_bytes(Thread::stack_base_offset())); // stack_base --> AT
494 __ dadd(T3, T3, AT); // locals * 4 + overhead_size + stack_base--> T3
495 __ ld(AT, thread, in_bytes(Thread::stack_size_offset())); // stack_size --> AT
496 __ dsub(T3, T3, AT); // locals * 4 + overhead_size + stack_base - stack_size --> T3
499 // add in the redzone and yellow size
500 __ move(AT, (StackRedPages+StackYellowPages) * page_size);
501 __ add(T3, T3, AT);
503 // check against the current stack bottom
504 __ slt(AT, T3, SP);
505 __ bne(AT, R0, after_frame_check);
506 __ delayed()->nop();
508 // Note: the restored frame is not necessarily interpreted.
509 // Use the shared runtime version of the StackOverflowError.
510 __ move(SP, Rsender);
511 assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated");
512 __ jmp(StubRoutines::throw_StackOverflowError_entry(), relocInfo::runtime_call_type);
513 __ delayed()->nop();
515 // all done with frame size check
516 __ bind(after_frame_check);
517 }
519 // Allocate monitor and lock method (asm interpreter)
520 // Rmethod - Method*
521 void InterpreterGenerator::lock_method(void) {
522 // synchronize method
523 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
525 #ifdef ASSERT
526 { Label L;
527 __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
528 __ andi(T0, T0, JVM_ACC_SYNCHRONIZED);
529 __ bne(T0, R0, L);
530 __ delayed()->nop();
531 __ stop("method doesn't need synchronization");
532 __ bind(L);
533 }
534 #endif // ASSERT
535 // get synchronization object
536 {
537 Label done;
538 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
539 __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
540 __ andi(T2, T0, JVM_ACC_STATIC);
541 __ ld(T0, LVP, Interpreter::local_offset_in_bytes(0));
542 __ beq(T2, R0, done);
543 __ delayed()->nop();
544 __ ld(T0, Rmethod, in_bytes(Method::const_offset()));
545 __ ld(T0, T0, in_bytes(ConstMethod::constants_offset()));
546 __ ld(T0, T0, ConstantPool::pool_holder_offset_in_bytes());
547 __ ld(T0, T0, mirror_offset);
548 __ bind(done);
549 }
550 // add space for monitor & lock
551 __ daddi(SP, SP, (-1) * entry_size); // add space for a monitor entry
552 __ sd(SP, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
553 // set new monitor block top
554 __ sd(T0, SP, BasicObjectLock::obj_offset_in_bytes()); // store object
555 // FIXME: I do not know what lock_object will do and what it will need
556 __ move(c_rarg0, SP); // object address
557 __ lock_object(c_rarg0);
558 }
560 // Generate a fixed interpreter frame. This is identical setup for
561 // interpreted methods and for native methods hence the shared code.
562 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
564 // [ local var m-1 ] <--- sp
565 // ...
566 // [ local var 0 ]
567 // [ argumnet word n-1 ] <--- T0(sender's sp)
568 // ...
569 // [ argument word 0 ] <--- S7
571 // initialize fixed part of activation frame
572 // sender's sp in Rsender
573 int i = 0;
574 __ sd(RA, SP, (-1) * wordSize); // save return address
575 __ sd(FP, SP, (-2) * wordSize); // save sender's fp
576 __ daddiu(FP, SP, (-2) * wordSize);
577 __ sd(Rsender, FP, (-++i) * wordSize); // save sender's sp
578 __ sd(R0, FP,(-++i)*wordSize); //save last_sp as null
579 __ sd(LVP, FP, (-++i) * wordSize); // save locals offset
580 __ ld(BCP, Rmethod, in_bytes(Method::const_offset())); // get constMethodOop
581 __ daddiu(BCP, BCP, in_bytes(ConstMethod::codes_offset())); // get codebase
582 __ sd(Rmethod, FP, (-++i) * wordSize); // save Method*
583 #ifndef CORE
584 if (ProfileInterpreter) {
585 Label method_data_continue;
586 __ ld(AT, Rmethod, in_bytes(Method::method_data_offset()));
587 __ beq(AT, R0, method_data_continue);
588 __ delayed()->nop();
589 __ daddi(AT, AT, in_bytes(MethodData::data_offset()));
590 __ bind(method_data_continue);
591 __ sd(AT, FP, (-++i) * wordSize);
592 } else {
593 __ sd(R0, FP, (-++i) * wordSize);
594 }
595 #endif // !CORE
597 __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
598 __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
599 __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
600 __ sd(T2, FP, (-++i) * wordSize); // set constant pool cache
601 if (native_call) {
602 __ sd(R0, FP, (-++i) * wordSize); // no bcp
603 } else {
604 __ sd(BCP, FP, (-++i) * wordSize); // set bcp
605 }
606 __ daddiu(SP, FP, (-++i) * wordSize);
607 __ sd(SP, FP, (-i) * wordSize); // reserve word for pointer to expression stack bottom
608 }
610 // End of helpers
612 // Various method entries
613 //------------------------------------------------------------------------------------------------------------------------
614 //
615 //
617 // Call an accessor method (assuming it is resolved, otherwise drop
618 // into vanilla (slow path) entry
619 address InterpreterGenerator::generate_accessor_entry(void) {
621 // Rmethod: Method*
622 // V0: receiver (preserve for slow entry into asm interpreter)
623 // Rsender: senderSP must preserved for slow path, set SP to it on fast path
625 address entry_point = __ pc();
626 Label xreturn_path;
627 // do fastpath for resolved accessor methods
628 if (UseFastAccessorMethods) {
629 Label slow_path;
630 __ li(T2, SafepointSynchronize::address_of_state());
631 __ lw(AT, T2, 0);
632 __ daddi(AT, AT, -(SafepointSynchronize::_not_synchronized));
633 __ bne(AT, R0, slow_path);
634 __ delayed()->nop();
635 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
636 // parameter size = 1
637 // Note: We can only use this code if the getfield has been resolved
638 // and if we don't have a null-pointer exception => check for
639 // these conditions first and use slow path if necessary.
640 // Rmethod: method
641 // V0: receiver
643 // [ receiver ] <-- sp
644 __ ld(T0, SP, 0);
646 // check if local 0 != NULL and read field
647 __ beq(T0, R0, slow_path);
648 __ delayed()->nop();
649 __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
650 __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
651 // read first instruction word and extract bytecode @ 1 and index @ 2
652 __ ld(T3, Rmethod, in_bytes(Method::const_offset()));
653 __ lw(T3, T3, in_bytes(ConstMethod::codes_offset()));
654 // Shift codes right to get the index on the right.
655 // The bytecode fetched looks like <index><0xb4><0x2a>
656 __ dsrl(T3, T3, 2 * BitsPerByte);
657 // FIXME: maybe it's wrong
658 __ dsll(T3, T3, exact_log2(in_words(ConstantPoolCacheEntry::size())));
659 __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
661 // T0: local 0
662 // Rmethod: method
663 // V0: receiver - do not destroy since it is needed for slow path!
664 // T1: scratch use which register instead ?
665 // T3: constant pool cache index
666 // T2: constant pool cache
667 // Rsender: send's sp
668 // check if getfield has been resolved and read constant pool cache entry
669 // check the validity of the cache entry by testing whether _indices field
670 // contains Bytecode::_getfield in b1 byte.
671 assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
673 __ dsll(T8, T3, Address::times_8);
674 __ move(T1, in_bytes(ConstantPoolCache::base_offset()
675 + ConstantPoolCacheEntry::indices_offset()));
676 __ dadd(T1, T8, T1);
677 __ dadd(T1, T1, T2);
678 __ lw(T1, T1, 0);
679 __ dsrl(T1, T1, 2 * BitsPerByte);
680 __ andi(T1, T1, 0xFF);
681 __ daddi(T1, T1, (-1) * Bytecodes::_getfield);
682 __ bne(T1, R0, slow_path);
683 __ delayed()->nop();
685 // Note: constant pool entry is not valid before bytecode is resolved
687 __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
688 __ dadd(T1, T1, T8);
689 __ dadd(T1, T1, T2);
690 __ lw(AT, T1, 0);
692 __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
693 __ dadd(T1, T1, T8);
694 __ dadd(T1, T1, T2);
695 __ lw(T3, T1, 0);
697 Label notByte, notBool, notShort, notChar, notObj;
699 // Need to differentiate between igetfield, agetfield, bgetfield etc.
700 // because they are different sizes.
701 // Use the type from the constant pool cache
702 __ srl(T3, T3, ConstantPoolCacheEntry::tos_state_shift);
703 // Make sure we don't need to mask T3 for tosBits after the above shift
704 ConstantPoolCacheEntry::verify_tos_state_shift();
705 // btos = 0
706 __ bne(T3, R0, notByte);
707 __ delayed()->dadd(T0, T0, AT);
709 __ lb(V0, T0, 0);
710 __ b(xreturn_path);
711 __ delayed()->nop();
713 //ztos
714 __ bind(notByte);
715 __ daddi(T1, T3, (-1) * ztos);
716 __ bne(T1, R0, notBool);
717 __ delayed()->nop();
718 __ lb(V0, T0, 0);
719 __ b(xreturn_path);
720 __ delayed()->nop();
722 //stos
723 __ bind(notBool);
724 __ daddi(T1, T3, (-1) * stos);
725 __ bne(T1, R0, notShort);
726 __ delayed()->nop();
727 __ lh(V0, T0, 0);
728 __ b(xreturn_path);
729 __ delayed()->nop();
731 //ctos
732 __ bind(notShort);
733 __ daddi(T1, T3, (-1) * ctos);
734 __ bne(T1, R0, notChar);
735 __ delayed()->nop();
736 __ lhu(V0, T0, 0);
737 __ b(xreturn_path);
738 __ delayed()->nop();
740 //atos
741 __ bind(notChar);
742 __ daddi(T1, T3, (-1) * atos);
743 __ bne(T1, R0, notObj);
744 __ delayed()->nop();
745 //add for compressedoops
746 __ load_heap_oop(V0, Address(T0, 0));
747 __ b(xreturn_path);
748 __ delayed()->nop();
750 //itos
751 __ bind(notObj);
752 #ifdef ASSERT
753 Label okay;
754 __ daddi(T1, T3, (-1) * itos);
755 __ beq(T1, R0, okay);
756 __ delayed()->nop();
757 __ stop("what type is this?");
758 __ bind(okay);
759 #endif // ASSERT
760 __ lw(V0, T0, 0);
762 __ bind(xreturn_path);
764 // _ireturn/_areturn
765 //FIXME
766 __ move(SP, Rsender);//FIXME, set sender's fp to SP
767 __ jr(RA);
768 __ delayed()->nop();
770 // generate a vanilla interpreter entry as the slow path
771 __ bind(slow_path);
772 (void) generate_normal_entry(false);
773 } else {
774 (void) generate_normal_entry(false);
775 }
777 return entry_point;
778 }
780 // Method entry for java.lang.ref.Reference.get.
781 address InterpreterGenerator::generate_Reference_get_entry(void) {
782 #if INCLUDE_ALL_GCS
783 // Code: _aload_0, _getfield, _areturn
784 // parameter size = 1
785 //
786 // The code that gets generated by this routine is split into 2 parts:
787 // 1. The "intrinsified" code for G1 (or any SATB based GC),
788 // 2. The slow path - which is an expansion of the regular method entry.
789 //
790 // Notes:-
791 // * In the G1 code we do not check whether we need to block for
792 // a safepoint. If G1 is enabled then we must execute the specialized
793 // code for Reference.get (except when the Reference object is null)
794 // so that we can log the value in the referent field with an SATB
795 // update buffer.
796 // If the code for the getfield template is modified so that the
797 // G1 pre-barrier code is executed when the current method is
798 // Reference.get() then going through the normal method entry
799 // will be fine.
800 // * The G1 code can, however, check the receiver object (the instance
801 // of java.lang.Reference) and jump to the slow path if null. If the
802 // Reference object is null then we obviously cannot fetch the referent
803 // and so we don't need to call the G1 pre-barrier. Thus we can use the
804 // regular method entry code to generate the NPE.
805 //
806 // This code is based on generate_accessor_enty.
807 //
808 // Rmethod: Method*
810 // Rsender: senderSP must preserve for slow path, set SP to it on fast path (Rsender)
812 address entry = __ pc();
814 const int referent_offset = java_lang_ref_Reference::referent_offset;
815 guarantee(referent_offset > 0, "referent offset not initialized");
817 if (UseG1GC) {
818 Label slow_path;
820 // Check if local 0 != NULL
821 // If the receiver is null then it is OK to jump to the slow path.
822 __ ld(V0, SP, 0);
824 __ beq(V0, R0, slow_path);
825 __ delayed()->nop();
827 // Generate the G1 pre-barrier code to log the value of
828 // the referent field in an SATB buffer.
830 // Load the value of the referent field.
831 const Address field_address(V0, referent_offset);
832 __ load_heap_oop(V0, field_address);
834 __ push(RA);
835 // Generate the G1 pre-barrier code to log the value of
836 // the referent field in an SATB buffer.
837 __ g1_write_barrier_pre(noreg /* obj */,
838 V0 /* pre_val */,
839 TREG /* thread */,
840 Rmethod /* tmp */,
841 true /* tosca_live */,
842 true /* expand_call */);
843 __ pop(RA);
845 __ jr(RA);
846 __ delayed()->daddu(SP, Rsender, R0); // set sp to sender sp
848 // generate a vanilla interpreter entry as the slow path
849 __ bind(slow_path);
850 (void) generate_normal_entry(false);
852 return entry;
853 }
854 #endif // INCLUDE_ALL_GCS
856 // If G1 is not enabled then attempt to go through the accessor entry point
857 // Reference.get is an accessor
858 return generate_accessor_entry();
859 }
861 // Interpreter stub for calling a native method. (asm interpreter)
862 // This sets up a somewhat different looking stack for calling the
863 // native method than the typical interpreter frame setup.
864 address InterpreterGenerator::generate_native_entry(bool synchronized) {
865 // determine code generation flags
866 bool inc_counter = UseCompiler || CountCompiledCalls;
867 // Rsender: sender's sp
868 // Rmethod: Method*
869 address entry_point = __ pc();
871 #ifndef CORE
872 const Address invocation_counter(Rmethod,in_bytes(MethodCounters::invocation_counter_offset() + // Fu: 20130814
873 InvocationCounter::counter_offset()));
874 #endif
876 // get parameter size (always needed)
877 // the size in the java stack
878 __ ld(V0, Rmethod, in_bytes(Method::const_offset()));
879 __ lhu(V0, V0, in_bytes(ConstMethod::size_of_parameters_offset())); // Fu: 20130814
881 // native calls don't need the stack size check since they have no expression stack
882 // and the arguments are already on the stack and we only add a handful of words
883 // to the stack
885 // Rmethod: Method*
886 // V0: size of parameters
887 // Layout of frame at this point
888 //
889 // [ argument word n-1 ] <--- sp
890 // ...
891 // [ argument word 0 ]
893 // for natives the size of locals is zero
895 // compute beginning of parameters (S7)
896 __ dsll(LVP, V0, Address::times_8);
897 __ daddiu(LVP, LVP, (-1) * wordSize);
898 __ dadd(LVP, LVP, SP);
901 // add 2 zero-initialized slots for native calls
902 __ daddi(SP, SP, (-2) * wordSize);
903 __ sd(R0, SP, 1 * wordSize); // slot for native oop temp offset (setup via runtime)
904 __ sd(R0, SP, 0 * wordSize); // slot for static native result handler3 (setup via runtime)
906 // Layout of frame at this point
907 // [ method holder mirror ] <--- sp
908 // [ result type info ]
909 // [ argument word n-1 ] <--- T0
910 // ...
911 // [ argument word 0 ] <--- LVP
914 #ifndef CORE
915 if (inc_counter) __ lw(T3, invocation_counter); // (pre-)fetch invocation count
916 #endif
918 // initialize fixed part of activation frame
919 generate_fixed_frame(true);
920 // after this function, the layout of frame is as following
921 //
922 // [ monitor block top ] <--- sp ( the top monitor entry )
923 // [ byte code pointer (0) ] (if native, bcp = 0)
924 // [ constant pool cache ]
925 // [ Method* ]
926 // [ locals offset ]
927 // [ sender's sp ]
928 // [ sender's fp ]
929 // [ return address ] <--- fp
930 // [ method holder mirror ]
931 // [ result type info ]
932 // [ argumnet word n-1 ] <--- sender's sp
933 // ...
934 // [ argument word 0 ] <--- S7
937 // make sure method is native & not abstract
938 #ifdef ASSERT
939 __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
940 {
941 Label L;
942 __ andi(AT, T0, JVM_ACC_NATIVE);
943 __ bne(AT, R0, L);
944 __ delayed()->nop();
945 __ stop("tried to execute native method as non-native");
946 __ bind(L);
947 }
948 {
949 Label L;
950 __ andi(AT, T0, JVM_ACC_ABSTRACT);
951 __ beq(AT, R0, L);
952 __ delayed()->nop();
953 __ stop("tried to execute abstract method in interpreter");
954 __ bind(L);
955 }
956 #endif
958 // Since at this point in the method invocation the exception handler
959 // would try to exit the monitor of synchronized methods which hasn't
960 // been entered yet, we set the thread local variable
961 // _do_not_unlock_if_synchronized to true. The remove_activation will
962 // check this flag.
963 Register thread = TREG;
964 #ifndef OPT_THREAD
965 __ get_thread(thread);
966 #endif
967 __ move(AT, (int)true);
968 __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
970 #ifndef CORE
971 // increment invocation count & check for overflow
972 Label invocation_counter_overflow;
973 if (inc_counter) {
974 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
975 }
977 Label continue_after_compile;
978 __ bind(continue_after_compile);
979 #endif // CORE
981 bang_stack_shadow_pages(true);
983 // reset the _do_not_unlock_if_synchronized flag
984 #ifndef OPT_THREAD
985 __ get_thread(thread);
986 #endif
987 __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
989 // check for synchronized methods
990 // Must happen AFTER invocation_counter check and stack overflow check,
991 // so method is not locked if overflows.
992 if (synchronized) {
993 lock_method();
994 } else {
995 // no synchronization necessary
996 #ifdef ASSERT
997 {
998 Label L;
999 __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
1000 __ andi(AT, T0, JVM_ACC_SYNCHRONIZED);
1001 __ beq(AT, R0, L);
1002 __ delayed()->nop();
1003 __ stop("method needs synchronization");
1004 __ bind(L);
1005 }
1006 #endif
1007 }
1009 // after method_lock, the layout of frame is as following
1010 //
1011 // [ monitor entry ] <--- sp
1012 // ...
1013 // [ monitor entry ]
1014 // [ monitor block top ] ( the top monitor entry )
1015 // [ byte code pointer (0) ] (if native, bcp = 0)
1016 // [ constant pool cache ]
1017 // [ Method* ]
1018 // [ locals offset ]
1019 // [ sender's sp ]
1020 // [ sender's fp ]
1021 // [ return address ] <--- fp
1022 // [ method holder mirror ]
1023 // [ result type info ]
1024 // [ argumnet word n-1 ] <--- ( sender's sp )
1025 // ...
1026 // [ argument word 0 ] <--- S7
1028 // start execution
1029 #ifdef ASSERT
1030 {
1031 Label L;
1032 __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
1033 __ beq(AT, SP, L);
1034 __ delayed()->nop();
1035 __ stop("broken stack frame setup in interpreter in asm");
1036 __ bind(L);
1037 }
1038 #endif
1040 // jvmti/jvmpi support
1041 __ notify_method_entry();
1043 // work registers
1044 const Register method = Rmethod;
1045 //const Register thread = T2;
1046 const Register t = RT4;
1048 __ get_method(method);
1049 __ verify_oop(method);
1050 {
1051 Label L, Lstatic;
1052 __ ld(t,method,in_bytes(Method::const_offset()));
1053 __ lhu(t, t, in_bytes(ConstMethod::size_of_parameters_offset()));
1054 // MIPS n64 ABI: caller does not reserve space for the register auguments.
1055 // A0 and A1(if needed)
1056 __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
1057 __ andi(AT, AT, JVM_ACC_STATIC);
1058 __ beq(AT, R0, Lstatic);
1059 __ delayed()->nop();
1060 __ daddiu(t, t, 1);
1061 __ bind(Lstatic);
1062 __ daddiu(t, t, -7);
1063 __ blez(t, L);
1064 __ delayed()->nop();
1065 __ dsll(t, t, Address::times_8);
1066 __ dsub(SP, SP, t);
1067 __ bind(L);
1068 }
1069 __ move(AT, -(StackAlignmentInBytes));
1070 __ andr(SP, SP, AT);
1071 __ move(AT, SP);
1072 // [ ] <--- sp
1073 // ... (size of parameters - 8 )
1074 // [ monitor entry ]
1075 // ...
1076 // [ monitor entry ]
1077 // [ monitor block top ] ( the top monitor entry )
1078 // [ byte code pointer (0) ] (if native, bcp = 0)
1079 // [ constant pool cache ]
1080 // [ Method* ]
1081 // [ locals offset ]
1082 // [ sender's sp ]
1083 // [ sender's fp ]
1084 // [ return address ] <--- fp
1085 // [ method holder mirror ]
1086 // [ result type info ]
1087 // [ argumnet word n-1 ] <--- ( sender's sp )
1088 // ...
1089 // [ argument word 0 ] <--- LVP
1091 // get signature handler
1092 {
1093 Label L;
1094 __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
1095 __ bne(T9, R0, L);
1096 __ delayed()->nop();
1097 __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
1098 InterpreterRuntime::prepare_native_call), method);
1099 __ get_method(method);
1100 __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
1101 __ bind(L);
1102 }
1104 // call signature handler
1105 // FIXME: when change codes in InterpreterRuntime, note this point
1106 // from: begin of parameters
1107 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == LVP, "adjust this code");
1108 // to: current sp
1109 assert(InterpreterRuntime::SignatureHandlerGenerator::to () == SP, "adjust this code");
1110 // temp: T3
1111 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t , "adjust this code");
1113 __ jalr(T9);
1114 __ delayed()->nop();
1115 __ get_method(method);
1117 //
1118 // if native function is static, and its second parameter has type length of double word,
1119 // and first parameter has type length of word, we have to reserve one word
1120 // for the first parameter, according to mips o32 abi.
1121 // if native function is not static, and its third parameter has type length of double word,
1122 // and second parameter has type length of word, we have to reserve one word for the second
1123 // parameter.
1124 //
1127 // result handler is in V0
1128 // set result handler
1129 __ sd(V0, FP, (frame::interpreter_frame_result_handler_offset)*wordSize);
1131 #define FIRSTPARA_SHIFT_COUNT 5
1132 #define SECONDPARA_SHIFT_COUNT 9
1133 #define THIRDPARA_SHIFT_COUNT 13
1134 #define PARA_MASK 0xf
1136 // pass mirror handle if static call
1137 {
1138 Label L;
1139 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
1140 __ lw(t, method, in_bytes(Method::access_flags_offset()));
1141 __ andi(AT, t, JVM_ACC_STATIC);
1142 __ beq(AT, R0, L);
1143 __ delayed()->nop();
1145 // get mirror
1146 __ ld(t, method, in_bytes(Method:: const_offset()));
1147 __ ld(t, t, in_bytes(ConstMethod::constants_offset())); //??
1148 __ ld(t, t, ConstantPool::pool_holder_offset_in_bytes());
1149 __ ld(t, t, mirror_offset);
1150 // copy mirror into activation frame
1151 //__ sw(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
1152 // pass handle to mirror
1153 __ sd(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
1154 __ daddi(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
1155 __ move(A1, t);
1156 __ bind(L);
1157 }
1159 // [ mthd holder mirror ptr ] <--- sp --------------------| (only for static method)
1160 // [ ] |
1161 // ... size of parameters(or +1) |
1162 // [ monitor entry ] |
1163 // ... |
1164 // [ monitor entry ] |
1165 // [ monitor block top ] ( the top monitor entry ) |
1166 // [ byte code pointer (0) ] (if native, bcp = 0) |
1167 // [ constant pool cache ] |
1168 // [ Method* ] |
1169 // [ locals offset ] |
1170 // [ sender's sp ] |
1171 // [ sender's fp ] |
1172 // [ return address ] <--- fp |
1173 // [ method holder mirror ] <----------------------------|
1174 // [ result type info ]
1175 // [ argumnet word n-1 ] <--- ( sender's sp )
1176 // ...
1177 // [ argument word 0 ] <--- S7
1179 // get native function entry point
1180 { Label L;
1181 __ ld(T9, method, in_bytes(Method::native_function_offset()));
1182 __ li(V1, SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
1183 __ bne(V1, T9, L);
1184 __ delayed()->nop();
1185 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
1186 __ get_method(method);
1187 __ verify_oop(method);
1188 __ ld(T9, method, in_bytes(Method::native_function_offset()));
1189 __ bind(L);
1190 }
1192 // pass JNIEnv
1193 // native function in T9
1194 #ifndef OPT_THREAD
1195 __ get_thread(thread);
1196 #endif
1197 __ daddi(t, thread, in_bytes(JavaThread::jni_environment_offset()));
1198 __ move(A0, t);
1199 // [ jni environment ] <--- sp
1200 // [ mthd holder mirror ptr ] ---------------------------->| (only for static method)
1201 // [ ] |
1202 // ... size of parameters |
1203 // [ monitor entry ] |
1204 // ... |
1205 // [ monitor entry ] |
1206 // [ monitor block top ] ( the top monitor entry ) |
1207 // [ byte code pointer (0) ] (if native, bcp = 0) |
1208 // [ constant pool cache ] |
1209 // [ Method* ] |
1210 // [ locals offset ] |
1211 // [ sender's sp ] |
1212 // [ sender's fp ] |
1213 // [ return address ] <--- fp |
1214 // [ method holder mirror ] <----------------------------|
1215 // [ result type info ]
1216 // [ argumnet word n-1 ] <--- ( sender's sp )
1217 // ...
1218 // [ argument word 0 ] <--- S7
1220 // set_last_Java_frame_before_call
1221 __ sd(FP, thread, in_bytes(JavaThread::last_Java_fp_offset()));
1222 // Change state to native (we save the return address in the thread, since it might not
1223 // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
1224 // points into the right code segment. It does not have to be the correct return pc.
1225 __ li(t, __ pc());
1226 __ sd(t, thread, in_bytes(JavaThread::last_Java_pc_offset()));
1227 __ sd(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
1229 // change thread state
1230 #ifdef ASSERT
1231 {
1232 Label L;
1233 __ lw(t, thread, in_bytes(JavaThread::thread_state_offset()));
1234 __ daddi(t, t, (-1) * _thread_in_Java);
1235 __ beq(t, R0, L);
1236 __ delayed()->nop();
1237 __ stop("Wrong thread state in native stub");
1238 __ bind(L);
1239 }
1240 #endif
1242 __ move(t, _thread_in_native);
1243 __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
1245 // call native method
1246 __ jalr(T9);
1247 __ delayed()->nop();
1248 // result potentially in V0 or F0
1251 // via _last_native_pc and not via _last_jave_sp
1252 // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
1253 // If the order changes or anything else is added to the stack the code in
1254 // interpreter_frame_result will have to be changed.
1255 //FIXME, should modify here
1256 // save return value to keep the value from being destroyed by other calls
1257 __ push(dtos);
1258 __ push(ltos);
1260 // change thread state
1261 __ get_thread(thread);
1262 __ move(t, _thread_in_native_trans);
1263 __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
1265 if( os::is_MP() ) __ sync(); // Force this write out before the read below
1267 // check for safepoint operation in progress and/or pending suspend requests
1268 { Label Continue;
1270 // Don't use call_VM as it will see a possible pending exception and forward it
1271 // and never return here preventing us from clearing _last_native_pc down below.
1272 // Also can't use call_VM_leaf either as it will check to see if BCP & LVP are
1273 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
1274 // by hand.
1275 //
1276 Label L;
1277 __ li(AT, SafepointSynchronize::address_of_state());
1278 __ lw(AT, AT, 0);
1279 __ bne(AT, R0, L);
1280 __ delayed()->nop();
1281 __ lw(AT, thread, in_bytes(JavaThread::suspend_flags_offset()));
1282 __ beq(AT, R0, Continue);
1283 __ delayed()->nop();
1284 __ bind(L);
1285 __ move(A0, thread);
1286 __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
1287 relocInfo::runtime_call_type);
1288 __ delayed()->nop();
1290 #ifndef OPT_THREAD
1291 __ get_thread(thread);
1292 #endif
1293 //add for compressedoops
1294 __ reinit_heapbase();
1295 __ bind(Continue);
1296 }
1298 // change thread state
1299 __ move(t, _thread_in_Java);
1300 __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
1301 __ reset_last_Java_frame(thread, true);
1303 // reset handle block
1304 __ ld(t, thread, in_bytes(JavaThread::active_handles_offset()));
1305 __ sw(R0, t, JNIHandleBlock::top_offset_in_bytes());
1307 // If result was an oop then unbox and save it in the frame
1308 { Label L;
1309 Label no_oop, store_result;
1310 //FIXME, addi only support 16-bit imeditate
1311 __ ld(AT, FP, frame::interpreter_frame_result_handler_offset*wordSize);
1312 __ li(T0, AbstractInterpreter::result_handler(T_OBJECT));
1313 __ bne(AT, T0, no_oop);
1314 __ delayed()->nop();
1315 __ pop(ltos);
1316 __ beq(V0, R0, store_result);
1317 __ delayed()->nop();
1318 // unbox
1319 __ ld(V0, V0, 0);
1320 __ bind(store_result);
1321 __ sd(V0, FP, (frame::interpreter_frame_oop_temp_offset)*wordSize);
1322 // keep stack depth as expected by pushing oop which will eventually be discarded
1323 __ push(ltos);
1324 __ bind(no_oop);
1325 }
1326 {
1327 Label no_reguard;
1328 __ lw(t, thread, in_bytes(JavaThread::stack_guard_state_offset()));
1329 __ move(AT,(int) JavaThread::stack_guard_yellow_disabled);
1330 __ bne(t, AT, no_reguard);
1331 __ delayed()->nop();
1332 __ pushad();
1333 __ move(S5_heapbase, SP);
1334 __ move(AT, -StackAlignmentInBytes);
1335 __ andr(SP, SP, AT);
1336 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::runtime_call_type);
1337 __ delayed()->nop();
1338 __ move(SP, S5_heapbase);
1339 __ popad();
1340 //add for compressedoops
1341 __ reinit_heapbase();
1342 __ bind(no_reguard);
1343 }
1344 // restore BCP to have legal interpreter frame,
1345 // i.e., bci == 0 <=> BCP == code_base()
1346 // Can't call_VM until bcp is within reasonable.
1347 __ get_method(method); // method is junk from thread_in_native to now.
1348 __ verify_oop(method);
1349 __ ld(BCP, method, in_bytes(Method::const_offset()));
1350 __ lea(BCP, Address(BCP, in_bytes(ConstMethod::codes_offset())));
1351 // handle exceptions (exception handling will handle unlocking!)
1352 {
1353 Label L;
1354 __ lw(t, thread, in_bytes(Thread::pending_exception_offset()));
1355 __ beq(t, R0, L);
1356 __ delayed()->nop();
1357 // Note: At some point we may want to unify this with the code used in
1358 // call_VM_base();
1359 // i.e., we should use the StubRoutines::forward_exception code. For now this
1360 // doesn't work here because the sp is not correctly set at this point.
1361 __ MacroAssembler::call_VM(noreg,
1362 CAST_FROM_FN_PTR(address,
1363 InterpreterRuntime::throw_pending_exception));
1364 __ should_not_reach_here();
1365 __ bind(L);
1366 }
1368 // do unlocking if necessary
1369 {
1370 Label L;
1371 __ lw(t, method, in_bytes(Method::access_flags_offset()));
1372 __ andi(t, t, JVM_ACC_SYNCHRONIZED);
1373 __ beq(t, R0, L);
1374 // the code below should be shared with interpreter macro assembler implementation
1375 {
1376 Label unlock;
1377 // BasicObjectLock will be first in list,
1378 // since this is a synchronized method. However, need
1379 // to check that the object has not been unlocked by
1380 // an explicit monitorexit bytecode.
1381 __ delayed()->daddi(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
1382 // address of first monitor
1384 __ ld(t, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
1385 __ bne(t, R0, unlock);
1386 __ delayed()->nop();
1388 // Entry already unlocked, need to throw exception
1389 __ MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
1390 InterpreterRuntime::throw_illegal_monitor_state_exception));
1391 __ should_not_reach_here();
1393 __ bind(unlock);
1394 __ unlock_object(c_rarg0);
1395 }
1396 __ bind(L);
1397 }
1399 // jvmti/jvmpi support
1400 // Note: This must happen _after_ handling/throwing any exceptions since
1401 // the exception handler code notifies the runtime of method exits
1402 // too. If this happens before, method entry/exit notifications are
1403 // not properly paired (was bug - gri 11/22/99).
1404 __ notify_method_exit(false, vtos, InterpreterMacroAssembler::NotifyJVMTI);
1406 // restore potential result in V0,
1407 // call result handler to restore potential result in ST0 & handle result
1409 __ pop(ltos);
1410 __ pop(dtos);
1412 __ ld(t, FP, (frame::interpreter_frame_result_handler_offset) * wordSize);
1413 __ jalr(t);
1414 __ delayed()->nop();
1417 // remove activation
1418 __ ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); // get sender sp
1419 __ ld(RA, FP, frame::interpreter_frame_return_addr_offset * wordSize); // get return address
1420 __ ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize); // restore sender's fp
1421 __ jr(RA);
1422 __ delayed()->nop();
1424 #ifndef CORE
1425 if (inc_counter) {
1426 // Handle overflow of counter and compile method
1427 __ bind(invocation_counter_overflow);
1428 generate_counter_overflow(&continue_after_compile);
1429 // entry_point is the beginning of this
1430 // function and checks again for compiled code
1431 }
1432 #endif
1433 return entry_point;
1434 }
1436 //
1437 // Generic interpreted method entry to (asm) interpreter
1438 //
1439 // Layout of frame just at the entry
1440 //
1441 // [ argument word n-1 ] <--- sp
1442 // ...
1443 // [ argument word 0 ]
1444 // assume Method* in Rmethod before call this method.
1445 // prerequisites to the generated stub : the callee Method* in Rmethod
1446 // note you must save the caller bcp before call the generated stub
1447 //
1448 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
1449 // determine code generation flags
1450 bool inc_counter = UseCompiler || CountCompiledCalls;
1452 // Rmethod: Method*
1453 // Rsender: sender 's sp
1454 address entry_point = __ pc();
1456 const Address invocation_counter(Rmethod,
1457 in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()));
1459 // get parameter size (always needed)
1460 __ ld(T3, Rmethod, in_bytes(Method::const_offset())); //T3 --> Rmethod._constMethod
1461 __ lhu(V0, T3, in_bytes(ConstMethod::size_of_parameters_offset()));
1463 // Rmethod: Method*
1464 // V0: size of parameters
1465 // Rsender: sender 's sp ,could be different frome sp+ wordSize if we call via c2i
1466 // get size of locals in words to T2
1467 __ lhu(T2, T3, in_bytes(ConstMethod::size_of_locals_offset()));
1468 // T2 = no. of additional locals, locals include parameters
1469 __ dsub(T2, T2, V0);
1471 // see if we've got enough room on the stack for locals plus overhead.
1472 // Layout of frame at this point
1473 //
1474 // [ argument word n-1 ] <--- sp
1475 // ...
1476 // [ argument word 0 ]
1477 generate_stack_overflow_check();
1478 // after this function, the layout of frame does not change
1480 // compute beginning of parameters (LVP)
1481 __ dsll(LVP, V0, LogBytesPerWord);
1482 __ daddiu(LVP, LVP, (-1) * wordSize);
1483 __ dadd(LVP, LVP, SP);
1485 // T2 - # of additional locals
1486 // allocate space for locals
1487 // explicitly initialize locals
1488 {
1489 Label exit, loop;
1490 __ beq(T2, R0, exit);
1491 __ delayed()->nop();
1493 __ bind(loop);
1494 __ sd(R0, SP, -1 * wordSize); // initialize local variables
1495 __ daddiu(T2, T2, -1); // until everything initialized
1496 __ bne(T2, R0, loop);
1497 __ delayed();
1499 __ daddiu(SP, SP, (-1) * wordSize); //fill delay slot
1501 __ bind(exit);
1502 }
1504 //
1505 // [ local var m-1 ] <--- sp
1506 // ...
1507 // [ local var 0 ]
1508 // [ argument word n-1 ] <--- T0?
1509 // ...
1510 // [ argument word 0 ] <--- LVP
1512 // initialize fixed part of activation frame
1514 generate_fixed_frame(false);
1517 // after this function, the layout of frame is as following
1518 //
1519 // [ monitor block top ] <--- sp ( the top monitor entry )
1520 // [ byte code pointer ] (if native, bcp = 0)
1521 // [ constant pool cache ]
1522 // [ Method* ]
1523 // [ locals offset ]
1524 // [ sender's sp ]
1525 // [ sender's fp ] <--- fp
1526 // [ return address ]
1527 // [ local var m-1 ]
1528 // ...
1529 // [ local var 0 ]
1530 // [ argumnet word n-1 ] <--- ( sender's sp )
1531 // ...
1532 // [ argument word 0 ] <--- LVP
1535 // make sure method is not native & not abstract
1536 #ifdef ASSERT
1537 __ ld(AT, Rmethod, in_bytes(Method::access_flags_offset()));
1538 {
1539 Label L;
1540 __ andi(T2, AT, JVM_ACC_NATIVE);
1541 __ beq(T2, R0, L);
1542 __ delayed()->nop();
1543 __ stop("tried to execute native method as non-native");
1544 __ bind(L);
1545 }
1546 {
1547 Label L;
1548 __ andi(T2, AT, JVM_ACC_ABSTRACT);
1549 __ beq(T2, R0, L);
1550 __ delayed()->nop();
1551 __ stop("tried to execute abstract method in interpreter");
1552 __ bind(L);
1553 }
1554 #endif
1556 // Since at this point in the method invocation the exception handler
1557 // would try to exit the monitor of synchronized methods which hasn't
1558 // been entered yet, we set the thread local variable
1559 // _do_not_unlock_if_synchronized to true. The remove_activation will
1560 // check this flag.
1562 #ifndef OPT_THREAD
1563 Register thread = T8;
1564 __ get_thread(thread);
1565 #else
1566 Register thread = TREG;
1567 #endif
1568 __ move(AT, (int)true);
1569 __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
1571 #ifndef CORE
1573 // 2014/11/24 Fu
1574 // mdp : T8
1575 // tmp1: T9
1576 // tmp2: T2
1577 __ profile_parameters_type(T8, T9, T2);
1579 // increment invocation count & check for overflow
1580 Label invocation_counter_overflow;
1581 Label profile_method;
1582 Label profile_method_continue;
1583 if (inc_counter) {
1584 generate_counter_incr(&invocation_counter_overflow,
1585 &profile_method,
1586 &profile_method_continue);
1587 if (ProfileInterpreter) {
1588 __ bind(profile_method_continue);
1589 }
1590 }
1592 Label continue_after_compile;
1593 __ bind(continue_after_compile);
1595 #endif // CORE
1597 bang_stack_shadow_pages(false);
1599 // reset the _do_not_unlock_if_synchronized flag
1600 #ifndef OPT_THREAD
1601 __ get_thread(thread);
1602 #endif
1603 __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
1605 // check for synchronized methods
1606 // Must happen AFTER invocation_counter check and stack overflow check,
1607 // so method is not locked if overflows.
1608 //
1609 if (synchronized) {
1610 // Allocate monitor and lock method
1611 lock_method();
1612 } else {
1613 // no synchronization necessary
1614 #ifdef ASSERT
1615 { Label L;
1616 __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
1617 __ andi(T2, AT, JVM_ACC_SYNCHRONIZED);
1618 __ beq(T2, R0, L);
1619 __ delayed()->nop();
1620 __ stop("method needs synchronization");
1621 __ bind(L);
1622 }
1623 #endif
1624 }
1626 // layout of frame after lock_method
1627 // [ monitor entry ] <--- sp
1628 // ...
1629 // [ monitor entry ]
1630 // [ monitor block top ] ( the top monitor entry )
1631 // [ byte code pointer ] (if native, bcp = 0)
1632 // [ constant pool cache ]
1633 // [ Method* ]
1634 // [ locals offset ]
1635 // [ sender's sp ]
1636 // [ sender's fp ]
1637 // [ return address ] <--- fp
1638 // [ local var m-1 ]
1639 // ...
1640 // [ local var 0 ]
1641 // [ argumnet word n-1 ] <--- ( sender's sp )
1642 // ...
1643 // [ argument word 0 ] <--- LVP
1646 // start execution
1647 #ifdef ASSERT
1648 {
1649 Label L;
1650 __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
1651 __ beq(AT, SP, L);
1652 __ delayed()->nop();
1653 __ stop("broken stack frame setup in interpreter in native");
1654 __ bind(L);
1655 }
1656 #endif
1658 // jvmti/jvmpi support
1659 __ notify_method_entry();
1661 __ dispatch_next(vtos);
1663 // invocation counter overflow
1664 if (inc_counter) {
1665 if (ProfileInterpreter) {
1666 // We have decided to profile this method in the interpreter
1667 __ bind(profile_method);
1668 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
1669 InterpreterRuntime::profile_method));
1670 __ set_method_data_pointer_for_bcp();
1671 __ get_method(Rmethod);
1672 __ b(profile_method_continue);
1673 __ delayed()->nop();
1674 }
1675 // Handle overflow of counter and compile method
1676 __ bind(invocation_counter_overflow);
1677 generate_counter_overflow(&continue_after_compile);
1678 }
1680 return entry_point;
1681 }
1683 // Entry points
1684 //
1685 // Here we generate the various kind of entries into the interpreter.
1686 // The two main entry type are generic bytecode methods and native
1687 // call method. These both come in synchronized and non-synchronized
1688 // versions but the frame layout they create is very similar. The
1689 // other method entry types are really just special purpose entries
1690 // that are really entry and interpretation all in one. These are for
1691 // trivial methods like accessor, empty, or special math methods.
1692 //
1693 // When control flow reaches any of the entry types for the interpreter
1694 // the following holds ->
1695 //
1696 // Arguments:
1697 //
1698 // Rmethod: Method*
1699 // V0: receiver
1700 //
1701 //
1702 // Stack layout immediately at entry
1703 //
1704 // [ parameter n-1 ] <--- sp
1705 // ...
1706 // [ parameter 0 ]
1707 // [ expression stack ] (caller's java expression stack)
1709 // Assuming that we don't go to one of the trivial specialized entries
1710 // the stack will look like below when we are ready to execute the
1711 // first bytecode (or call the native routine). The register usage
1712 // will be as the template based interpreter expects (see
1713 // interpreter_mips_64.hpp).
1714 //
1715 // local variables follow incoming parameters immediately; i.e.
1716 // the return address is moved to the end of the locals).
1717 //
1718 // [ monitor entry ] <--- sp
1719 // ...
1720 // [ monitor entry ]
1721 // [ monitor block top ] ( the top monitor entry )
1722 // [ byte code pointer ] (if native, bcp = 0)
1723 // [ constant pool cache ]
1724 // [ Method* ]
1725 // [ locals offset ]
1726 // [ sender's sp ]
1727 // [ sender's fp ]
1728 // [ return address ] <--- fp
1729 // [ local var m-1 ]
1730 // ...
1731 // [ local var 0 ]
1732 // [ argumnet word n-1 ] <--- ( sender's sp )
1733 // ...
1734 // [ argument word 0 ] <--- S7
1736 address AbstractInterpreterGenerator::generate_method_entry(
1737 AbstractInterpreter::MethodKind kind) {
1738 // determine code generation flags
1739 bool synchronized = false;
1740 address entry_point = NULL;
1741 switch (kind) {
1742 case Interpreter::zerolocals :
1743 break;
1744 case Interpreter::zerolocals_synchronized:
1745 synchronized = true;
1746 break;
1747 case Interpreter::native :
1748 entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);
1749 break;
1750 case Interpreter::native_synchronized :
1751 entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);
1752 break;
1753 case Interpreter::empty :
1754 entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();
1755 break;
1756 case Interpreter::accessor :
1757 entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();
1758 break;
1759 case Interpreter::abstract :
1760 entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();
1761 break;
1763 case Interpreter::java_lang_math_sin : // fall thru
1764 case Interpreter::java_lang_math_cos : // fall thru
1765 case Interpreter::java_lang_math_tan : // fall thru
1766 case Interpreter::java_lang_math_log : // fall thru
1767 case Interpreter::java_lang_math_log10 : // fall thru
1768 case Interpreter::java_lang_math_pow : // fall thru
1769 case Interpreter::java_lang_math_exp : break;
1770 case Interpreter::java_lang_math_abs : // fall thru
1771 case Interpreter::java_lang_math_sqrt :
1772 entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
1773 case Interpreter::java_lang_ref_reference_get:
1774 entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
1775 default:
1776 fatal(err_msg("unexpected method kind: %d", kind));
1777 break;
1778 }
1779 if (entry_point) return entry_point;
1781 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
1782 }
1784 // These should never be compiled since the interpreter will prefer
1785 // the compiled version to the intrinsic version.
1786 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
1787 switch (method_kind(m)) {
1788 case Interpreter::java_lang_math_sin : // fall thru
1789 case Interpreter::java_lang_math_cos : // fall thru
1790 case Interpreter::java_lang_math_tan : // fall thru
1791 case Interpreter::java_lang_math_abs : // fall thru
1792 case Interpreter::java_lang_math_log : // fall thru
1793 case Interpreter::java_lang_math_log10 : // fall thru
1794 case Interpreter::java_lang_math_sqrt : // fall thru
1795 case Interpreter::java_lang_math_pow : // fall thru
1796 case Interpreter::java_lang_math_exp :
1797 return false;
1798 default:
1799 return true;
1800 }
1801 }
1803 // How much stack a method activation needs in words.
1804 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1806 const int entry_size = frame::interpreter_frame_monitor_size();
1808 // total overhead size: entry_size + (saved fp thru expr stack bottom).
1809 // be sure to change this if you add/subtract anything to/from the overhead area
1810 const int overhead_size = -(frame::interpreter_frame_initial_sp_offset) + entry_size;
1812 const int stub_code = 6; // see generate_call_stub
1813 // return overhead_size + method->max_locals() + method->max_stack() + stub_code;
1814 const int method_stack = (method->max_locals() + method->max_stack()) *
1815 Interpreter::stackElementWords;
1816 return overhead_size + method_stack + stub_code;
1817 }
1819 void AbstractInterpreter::layout_activation(Method* method,
1820 int tempcount,
1821 int popframe_extra_args,
1822 int moncount,
1823 int caller_actual_parameters,
1824 int callee_param_count,
1825 int callee_locals,
1826 frame* caller,
1827 frame* interpreter_frame,
1828 bool is_top_frame,
1829 bool is_bottom_frame) {
1830 // Note: This calculation must exactly parallel the frame setup
1831 // in AbstractInterpreterGenerator::generate_method_entry.
1832 // If interpreter_frame!=NULL, set up the method, locals, and monitors.
1833 // The frame interpreter_frame, if not NULL, is guaranteed to be the
1834 // right size, as determined by a previous call to this method.
1835 // It is also guaranteed to be walkable even though it is in a skeletal state
1837 // fixed size of an interpreter frame:
1839 int max_locals = method->max_locals() * Interpreter::stackElementWords;
1840 int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords;
1842 #ifdef ASSERT
1843 if (!EnableInvokeDynamic) {
1844 // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
1845 // Probably, since deoptimization doesn't work yet.
1846 assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
1847 }
1848 assert(caller->sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable(2)");
1849 #endif
1851 interpreter_frame->interpreter_frame_set_method(method);
1852 // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
1853 // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
1854 // and sender_sp is fp+8
1855 intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
1857 #ifdef ASSERT
1858 if (caller->is_interpreted_frame()) {
1859 assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
1860 }
1861 #endif
1863 interpreter_frame->interpreter_frame_set_locals(locals);
1864 BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
1865 BasicObjectLock* monbot = montop - moncount;
1866 interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount);
1868 //set last sp;
1869 intptr_t* sp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords -
1870 popframe_extra_args;
1871 interpreter_frame->interpreter_frame_set_last_sp(sp);
1872 // All frames but the initial interpreter frame we fill in have a
1873 // value for sender_sp that allows walking the stack but isn't
1874 // truly correct. Correct the value here.
1875 //
1876 if (extra_locals != 0 &&
1877 interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
1878 interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
1879 }
1880 *interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache();
1881 }
1883 //-----------------------------------------------------------------------------
1884 // Exceptions
1886 void TemplateInterpreterGenerator::generate_throw_exception() {
1887 // Entry point in previous activation (i.e., if the caller was
1888 // interpreted)
1889 Interpreter::_rethrow_exception_entry = __ pc();
1890 // Restore sp to interpreter_frame_last_sp even though we are going
1891 // to empty the expression stack for the exception processing.
1892 __ sd(R0,FP, frame::interpreter_frame_last_sp_offset * wordSize);
1894 // V0: exception
1895 // V1: return address/pc that threw exception
1896 __ restore_bcp(); // BCP points to call/send
1897 __ restore_locals();
1899 //add for compressedoops
1900 __ reinit_heapbase();
1901 // Entry point for exceptions thrown within interpreter code
1902 Interpreter::_throw_exception_entry = __ pc();
1903 // expression stack is undefined here
1904 // V0: exception
1905 // BCP: exception bcp
1906 __ verify_oop(V0);
1908 // expression stack must be empty before entering the VM in case of an exception
1909 __ empty_expression_stack();
1910 // find exception handler address and preserve exception oop
1911 __ move(A1, V0);
1912 __ call_VM(V1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), A1);
1913 // V0: exception handler entry point
1914 // V1: preserved exception oop
1915 // S0: bcp for exception handler
1916 __ daddi(SP, SP, (-1) * wordSize);
1917 __ sd(V1, SP, 0); // push exception which is now the only value on the stack
1918 __ jr(V0); // jump to exception handler (may be _remove_activation_entry!)
1919 __ delayed()->nop();
1921 // If the exception is not handled in the current frame the frame is removed and
1922 // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
1923 //
1924 // Note: At this point the bci is still the bxi for the instruction which caused
1925 // the exception and the expression stack is empty. Thus, for any VM calls
1926 // at this point, GC will find a legal oop map (with empty expression stack).
1928 // In current activation
1929 // V0: exception
1930 // BCP: exception bcp
1932 //
1933 // JVMTI PopFrame support
1934 //
1936 Interpreter::_remove_activation_preserving_args_entry = __ pc();
1937 __ empty_expression_stack();
1938 // Set the popframe_processing bit in pending_popframe_condition indicating that we are
1939 // currently handling popframe, so that call_VMs that may happen later do not trigger new
1940 // popframe handling cycles.
1941 #ifndef OPT_THREAD
1942 Register thread = T2;
1943 __ get_thread(T2);
1944 #else
1945 Register thread = TREG;
1946 #endif
1947 __ lw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
1948 __ ori(T3, T3, JavaThread::popframe_processing_bit);
1949 __ sw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
1951 #ifndef CORE
1952 {
1953 // Check to see whether we are returning to a deoptimized frame.
1954 // (The PopFrame call ensures that the caller of the popped frame is
1955 // either interpreted or compiled and deoptimizes it if compiled.)
1956 // In this case, we can't call dispatch_next() after the frame is
1957 // popped, but instead must save the incoming arguments and restore
1958 // them after deoptimization has occurred.
1959 //
1960 // Note that we don't compare the return PC against the
1961 // deoptimization blob's unpack entry because of the presence of
1962 // adapter frames in C2.
1963 Label caller_not_deoptimized;
1964 __ ld(A0, FP, frame::return_addr_offset * wordSize);
1965 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), A0);
1966 __ bne(V0, R0, caller_not_deoptimized);
1967 __ delayed()->nop();
1969 // Compute size of arguments for saving when returning to deoptimized caller
1970 __ get_method(A1);
1971 __ verify_oop(A1);
1972 __ ld(A1, A1, in_bytes(Method::const_offset()));
1973 __ lhu(A1, A1, in_bytes(ConstMethod::size_of_parameters_offset()));
1974 __ shl(A1, Interpreter::logStackElementSize);
1975 __ restore_locals();
1976 __ dsub(A2, LVP, A1);
1977 __ daddiu(A2, A2, wordSize);
1978 // Save these arguments
1979 #ifndef OPT_THREAD
1980 __ get_thread(A0);
1981 #else
1982 __ move(A0, TREG);
1983 #endif
1984 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), A0, A1, A2);
1986 __ remove_activation(vtos, T9, false, false, false);
1988 // Inform deoptimization that it is responsible for restoring these arguments
1989 #ifndef OPT_THREAD
1990 __ get_thread(thread);
1991 #endif
1992 __ move(AT, JavaThread::popframe_force_deopt_reexecution_bit);
1993 __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
1994 // Continue in deoptimization handler
1995 __ jr(T9);
1996 __ delayed()->nop();
1998 __ bind(caller_not_deoptimized);
1999 }
2000 #endif /* !CORE */
2002 __ remove_activation(vtos, T3,
2003 /* throw_monitor_exception */ false,
2004 /* install_monitor_exception */ false,
2005 /* notify_jvmdi */ false);
2007 // Clear the popframe condition flag
2008 // Finish with popframe handling
2009 // A previous I2C followed by a deoptimization might have moved the
2010 // outgoing arguments further up the stack. PopFrame expects the
2011 // mutations to those outgoing arguments to be preserved and other
2012 // constraints basically require this frame to look exactly as
2013 // though it had previously invoked an interpreted activation with
2014 // no space between the top of the expression stack (current
2015 // last_sp) and the top of stack. Rather than force deopt to
2016 // maintain this kind of invariant all the time we call a small
2017 // fixup routine to move the mutated arguments onto the top of our
2018 // expression stack if necessary.
2019 __ move(T8, SP);
2020 __ ld(A2, FP, frame::interpreter_frame_last_sp_offset * wordSize);
2021 #ifndef OPT_THREAD
2022 __ get_thread(thread);
2023 #endif
2024 // PC must point into interpreter here
2025 __ set_last_Java_frame(thread, noreg, FP, __ pc());
2026 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, T8, A2);
2027 __ reset_last_Java_frame(thread, true);
2028 // Restore the last_sp and null it out
2029 __ ld(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
2030 __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
2034 __ move(AT, JavaThread::popframe_inactive);
2035 __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
2037 // Finish with popframe handling
2038 __ restore_bcp();
2039 __ restore_locals();
2040 #ifndef CORE
2041 // The method data pointer was incremented already during
2042 // call profiling. We have to restore the mdp for the current bcp.
2043 if (ProfileInterpreter) {
2044 __ set_method_data_pointer_for_bcp();
2045 }
2046 #endif // !CORE
2047 // Clear the popframe condition flag
2048 #ifndef OPT_THREAD
2049 __ get_thread(thread);
2050 #endif
2051 __ move(AT, JavaThread::popframe_inactive);
2052 __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
2053 __ dispatch_next(vtos);
2054 // end of PopFrame support
2056 Interpreter::_remove_activation_entry = __ pc();
2058 // preserve exception over this code sequence
2059 __ ld(T0, SP, 0);
2060 __ daddi(SP, SP, wordSize);
2061 #ifndef OPT_THREAD
2062 __ get_thread(thread);
2063 #endif
2064 __ sd(T0, thread, in_bytes(JavaThread::vm_result_offset()));
2065 // remove the activation (without doing throws on illegalMonitorExceptions)
2066 __ remove_activation(vtos, T3, false, true, false);
2067 // restore exception
2068 __ get_vm_result(T0, thread);
2069 __ verify_oop(T0);
2071 // In between activations - previous activation type unknown yet
2072 // compute continuation point - the continuation point expects
2073 // the following registers set up:
2074 //
2075 // T0: exception
2076 // T1: return address/pc that threw exception
2077 // SP: expression stack of caller
2078 // FP: fp of caller
2079 __ daddi(SP, SP, (-2) * wordSize);
2080 __ sd(T0, SP, wordSize); // save exception
2081 __ sd(T3, SP, 0); // save return address
2082 __ move(A1, T3);
2083 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, A1);
2084 __ move(T9, V0); // save exception handler
2085 __ ld(V0, SP, wordSize); // restore exception
2086 __ ld(V1, SP, 0); // restore return address
2087 __ daddi(SP, SP, 2 * wordSize);
2089 // Note that an "issuing PC" is actually the next PC after the call
2090 __ jr(T9); // jump to exception handler of caller
2091 __ delayed()->nop();
2092 }
2095 //
2096 // JVMTI ForceEarlyReturn support
2097 //
2098 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
2099 address entry = __ pc();
2100 __ restore_bcp();
2101 __ restore_locals();
2102 __ empty_expression_stack();
2103 __ empty_FPU_stack();
2104 __ load_earlyret_value(state);
2106 #ifndef OPT_THREAD
2107 __ get_thread(TREG);
2108 #endif
2109 __ ld_ptr(T9, TREG, in_bytes(JavaThread::jvmti_thread_state_offset()));
2110 const Address cond_addr(T9, in_bytes(JvmtiThreadState::earlyret_state_offset()));
2111 // Clear the earlyret state
2112 __ move(AT, JvmtiThreadState::earlyret_inactive);
2113 __ sw(AT, cond_addr);
2114 __ sync();
2117 __ remove_activation(state, T0,
2118 false, /* throw_monitor_exception */
2119 false, /* install_monitor_exception */
2120 true); /* notify_jvmdi */
2121 __ sync();
2122 __ jr(T0);
2123 __ delayed()->nop();
2124 return entry;
2125 } // end of ForceEarlyReturn support
2128 //-----------------------------------------------------------------------------
2129 // Helper for vtos entry point generation
2131 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
2132 address& bep,
2133 address& cep,
2134 address& sep,
2135 address& aep,
2136 address& iep,
2137 address& lep,
2138 address& fep,
2139 address& dep,
2140 address& vep) {
2141 assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
2142 Label L;
2143 fep = __ pc(); __ push(ftos); __ b(L); __ delayed()->nop();
2144 dep = __ pc(); __ push(dtos); __ b(L); __ delayed()->nop();
2145 lep = __ pc(); __ push(ltos); __ b(L); __ delayed()->nop();
2146 aep =__ pc(); __ push(atos); __ b(L); __ delayed()->nop();
2147 bep = cep = sep =
2148 iep = __ pc(); __ push(itos);
2149 vep = __ pc();
2150 __ bind(L);
2151 generate_and_dispatch(t);
2152 }
2155 //-----------------------------------------------------------------------------
2156 // Generation of individual instructions
2158 // helpers for generate_and_dispatch
2161 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
2162 : TemplateInterpreterGenerator(code) {
2163 generate_all(); // down here so it can be "virtual"
2164 }
2166 //-----------------------------------------------------------------------------
2168 // Non-product code
2169 #ifndef PRODUCT
2170 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
2171 address entry = __ pc();
2173 // prepare expression stack
2174 __ push(state); // save tosca
2176 // tos & tos2
2177 // trace_bytecode need actually 4 args, the last two is tos&tos2
2178 // this work fine for x86. but mips o32 call convention will store A2-A3
2179 // to the stack position it think is the tos&tos2
2180 // when the expression stack have no more than 2 data, error occur.
2181 __ ld(A2, SP, 0);
2182 __ ld(A3, SP, 1 * wordSize);
2184 // pass arguments & call tracer
2185 __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), RA, A2, A3);
2186 __ move(RA, V0); // make sure return address is not destroyed by pop(state)
2188 // restore expression stack
2189 __ pop(state); // restore tosca
2191 // return
2192 __ jr(RA);
2193 __ delayed()->nop();
2195 return entry;
2196 }
2198 void TemplateInterpreterGenerator::count_bytecode() {
2199 __ li(T8, (long)&BytecodeCounter::_counter_value);
2200 __ lw(AT, T8, 0);
2201 __ daddi(AT, AT, 1);
2202 __ sw(AT, T8, 0);
2203 }
2205 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
2206 __ li(T8, (long)&BytecodeHistogram::_counters[t->bytecode()]);
2207 __ lw(AT, T8, 0);
2208 __ daddi(AT, AT, 1);
2209 __ sw(AT, T8, 0);
2210 }
2212 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
2213 __ li(T8, (long)&BytecodePairHistogram::_index);
2214 __ lw(T9, T8, 0);
2215 __ dsrl(T9, T9, BytecodePairHistogram::log2_number_of_codes);
2216 __ li(T8, ((long)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
2217 __ orr(T9, T9, T8);
2218 __ li(T8, (long)&BytecodePairHistogram::_index);
2219 __ sw(T9, T8, 0);
2220 __ dsll(T9, T9, 2);
2221 __ li(T8, (long)BytecodePairHistogram::_counters);
2222 __ dadd(T8, T8, T9);
2223 __ lw(AT, T8, 0);
2224 __ daddi(AT, AT, 1);
2225 __ sw(AT, T8, 0);
2226 }
2229 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
2230 // Call a little run-time stub to avoid blow-up for each bytecode.
2231 // The run-time runtime saves the right registers, depending on
2232 // the tosca in-state for the given template.
2234 address entry = Interpreter::trace_code(t->tos_in());
2235 assert(entry != NULL, "entry must have been generated");
2236 __ call(entry, relocInfo::none);
2237 __ delayed()->nop();
2238 //add for compressedoops
2239 __ reinit_heapbase();
2240 }
2243 void TemplateInterpreterGenerator::stop_interpreter_at() {
2244 Label L;
2245 __ li(T8, long(&BytecodeCounter::_counter_value));
2246 __ lw(T8, T8, 0);
2247 __ move(AT, StopInterpreterAt);
2248 __ bne(T8, AT, L);
2249 __ delayed()->nop();
2250 __ call(CAST_FROM_FN_PTR(address, os::breakpoint), relocInfo::runtime_call_type);
2251 __ delayed()->nop();
2252 __ bind(L);
2253 }
2254 #endif // !PRODUCT
2255 #endif // ! CC_INTERP