src/cpu/mips/vm/templateInterpreter_mips_64.cpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
child 32
3b95e10c12fa
permissions
-rw-r--r--

Added MIPS 64-bit port.

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

mercurial