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