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