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