annotate src/cpu/x86/vm/templateInterpreter_x86_32.cpp @ 2700:38fa55e5e792

7055355: JSR 292: crash while throwing WrongMethodTypeException Reviewed-by: jrose, twisti, bdelsart
author never
date Thu, 16 Jun 2011 13:46:55 -0700
parents 3d2ab563047a
children b20d64f83668
rev   line source
duke@0 1 /*
iveresov@2131 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1992 25 #include "precompiled.hpp"
stefank@1992 26 #include "asm/assembler.hpp"
stefank@1992 27 #include "interpreter/bytecodeHistogram.hpp"
stefank@1992 28 #include "interpreter/interpreter.hpp"
stefank@1992 29 #include "interpreter/interpreterGenerator.hpp"
stefank@1992 30 #include "interpreter/interpreterRuntime.hpp"
stefank@1992 31 #include "interpreter/templateTable.hpp"
stefank@1992 32 #include "oops/arrayOop.hpp"
stefank@1992 33 #include "oops/methodDataOop.hpp"
stefank@1992 34 #include "oops/methodOop.hpp"
stefank@1992 35 #include "oops/oop.inline.hpp"
stefank@1992 36 #include "prims/jvmtiExport.hpp"
stefank@1992 37 #include "prims/jvmtiThreadState.hpp"
stefank@1992 38 #include "runtime/arguments.hpp"
stefank@1992 39 #include "runtime/deoptimization.hpp"
stefank@1992 40 #include "runtime/frame.inline.hpp"
stefank@1992 41 #include "runtime/sharedRuntime.hpp"
stefank@1992 42 #include "runtime/stubRoutines.hpp"
stefank@1992 43 #include "runtime/synchronizer.hpp"
stefank@1992 44 #include "runtime/timer.hpp"
stefank@1992 45 #include "runtime/vframeArray.hpp"
stefank@1992 46 #include "utilities/debug.hpp"
duke@0 47
duke@0 48 #define __ _masm->
duke@0 49
duke@0 50
duke@0 51 #ifndef CC_INTERP
duke@0 52 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
duke@0 53 const int bci_offset = frame::interpreter_frame_bcx_offset * wordSize;
duke@0 54 const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
duke@0 55
duke@0 56 //------------------------------------------------------------------------------------------------------------------------
duke@0 57
duke@0 58 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
duke@0 59 address entry = __ pc();
duke@0 60
duke@0 61 // Note: There should be a minimal interpreter frame set up when stack
duke@0 62 // overflow occurs since we check explicitly for it now.
duke@0 63 //
duke@0 64 #ifdef ASSERT
duke@0 65 { Label L;
never@307 66 __ lea(rax, Address(rbp,
duke@0 67 frame::interpreter_frame_monitor_block_top_offset * wordSize));
never@307 68 __ cmpptr(rax, rsp); // rax, = maximal rsp for current rbp,
duke@0 69 // (stack grows negative)
duke@0 70 __ jcc(Assembler::aboveEqual, L); // check if frame is complete
duke@0 71 __ stop ("interpreter frame not set up");
duke@0 72 __ bind(L);
duke@0 73 }
duke@0 74 #endif // ASSERT
duke@0 75 // Restore bcp under the assumption that the current frame is still
duke@0 76 // interpreted
duke@0 77 __ restore_bcp();
duke@0 78
duke@0 79 // expression stack must be empty before entering the VM if an exception
duke@0 80 // happened
duke@0 81 __ empty_expression_stack();
duke@0 82 __ empty_FPU_stack();
duke@0 83 // throw exception
duke@0 84 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
duke@0 85 return entry;
duke@0 86 }
duke@0 87
duke@0 88 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) {
duke@0 89 address entry = __ pc();
duke@0 90 // expression stack must be empty before entering the VM if an exception happened
duke@0 91 __ empty_expression_stack();
duke@0 92 __ empty_FPU_stack();
duke@0 93 // setup parameters
duke@0 94 // ??? convention: expect aberrant index in register rbx,
duke@0 95 __ lea(rax, ExternalAddress((address)name));
duke@0 96 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), rax, rbx);
duke@0 97 return entry;
duke@0 98 }
duke@0 99
duke@0 100 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
duke@0 101 address entry = __ pc();
duke@0 102 // object is at TOS
never@307 103 __ pop(rax);
duke@0 104 // expression stack must be empty before entering the VM if an exception
duke@0 105 // happened
duke@0 106 __ empty_expression_stack();
duke@0 107 __ empty_FPU_stack();
duke@0 108 __ call_VM(noreg,
duke@0 109 CAST_FROM_FN_PTR(address,
duke@0 110 InterpreterRuntime::throw_ClassCastException),
duke@0 111 rax);
duke@0 112 return entry;
duke@0 113 }
duke@0 114
duke@0 115 address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) {
duke@0 116 assert(!pass_oop || message == NULL, "either oop or message but not both");
duke@0 117 address entry = __ pc();
duke@0 118 if (pass_oop) {
duke@0 119 // object is at TOS
never@307 120 __ pop(rbx);
duke@0 121 }
duke@0 122 // expression stack must be empty before entering the VM if an exception happened
duke@0 123 __ empty_expression_stack();
duke@0 124 __ empty_FPU_stack();
duke@0 125 // setup parameters
duke@0 126 __ lea(rax, ExternalAddress((address)name));
duke@0 127 if (pass_oop) {
duke@0 128 __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), rax, rbx);
duke@0 129 } else {
duke@0 130 if (message != NULL) {
duke@0 131 __ lea(rbx, ExternalAddress((address)message));
duke@0 132 } else {
xlu@520 133 __ movptr(rbx, NULL_WORD);
duke@0 134 }
duke@0 135 __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), rax, rbx);
duke@0 136 }
duke@0 137 // throw exception
duke@0 138 __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
duke@0 139 return entry;
duke@0 140 }
duke@0 141
duke@0 142
duke@0 143 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
duke@0 144 address entry = __ pc();
duke@0 145 // NULL last_sp until next java call
xlu@520 146 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 147 __ dispatch_next(state);
duke@0 148 return entry;
duke@0 149 }
duke@0 150
duke@0 151
jrose@1133 152 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step) {
jrose@764 153 TosState incoming_state = state;
twisti@2247 154 address entry = __ pc();
duke@0 155
duke@0 156 #ifdef COMPILER2
duke@0 157 // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
jrose@764 158 if ((incoming_state == ftos && UseSSE < 1) || (incoming_state == dtos && UseSSE < 2)) {
duke@0 159 for (int i = 1; i < 8; i++) {
duke@0 160 __ ffree(i);
duke@0 161 }
duke@0 162 } else if (UseSSE < 2) {
duke@0 163 __ empty_FPU_stack();
duke@0 164 }
duke@0 165 #endif
jrose@764 166 if ((incoming_state == ftos && UseSSE < 1) || (incoming_state == dtos && UseSSE < 2)) {
duke@0 167 __ MacroAssembler::verify_FPU(1, "generate_return_entry_for compiled");
duke@0 168 } else {
duke@0 169 __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
duke@0 170 }
duke@0 171
duke@0 172 // In SSE mode, interpreter returns FP results in xmm0 but they need
duke@0 173 // to end up back on the FPU so it can operate on them.
jrose@764 174 if (incoming_state == ftos && UseSSE >= 1) {
never@307 175 __ subptr(rsp, wordSize);
duke@0 176 __ movflt(Address(rsp, 0), xmm0);
duke@0 177 __ fld_s(Address(rsp, 0));
never@307 178 __ addptr(rsp, wordSize);
jrose@764 179 } else if (incoming_state == dtos && UseSSE >= 2) {
never@307 180 __ subptr(rsp, 2*wordSize);
duke@0 181 __ movdbl(Address(rsp, 0), xmm0);
duke@0 182 __ fld_d(Address(rsp, 0));
never@307 183 __ addptr(rsp, 2*wordSize);
duke@0 184 }
duke@0 185
duke@0 186 __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_return_entry_for in interpreter");
duke@0 187
duke@0 188 // Restore stack bottom in case i2c adjusted stack
never@307 189 __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
duke@0 190 // and NULL it as marker that rsp is now tos until next java call
xlu@520 191 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 192
duke@0 193 __ restore_bcp();
duke@0 194 __ restore_locals();
jrose@764 195
jrose@764 196 Label L_got_cache, L_giant_index;
jrose@764 197 if (EnableInvokeDynamic) {
jrose@764 198 __ cmpb(Address(rsi, 0), Bytecodes::_invokedynamic);
jrose@764 199 __ jcc(Assembler::equal, L_giant_index);
jrose@764 200 }
jrose@1578 201 __ get_cache_and_index_at_bcp(rbx, rcx, 1, sizeof(u2));
jrose@764 202 __ bind(L_got_cache);
duke@0 203 __ movl(rbx, Address(rbx, rcx,
never@307 204 Address::times_ptr, constantPoolCacheOopDesc::base_offset() +
duke@0 205 ConstantPoolCacheEntry::flags_offset()));
never@307 206 __ andptr(rbx, 0xFF);
never@307 207 __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale()));
duke@0 208 __ dispatch_next(state, step);
jrose@764 209
jrose@764 210 // out of the main line of code...
jrose@764 211 if (EnableInvokeDynamic) {
jrose@764 212 __ bind(L_giant_index);
jrose@1578 213 __ get_cache_and_index_at_bcp(rbx, rcx, 1, sizeof(u4));
jrose@764 214 __ jmp(L_got_cache);
jrose@764 215 }
jrose@764 216
duke@0 217 return entry;
duke@0 218 }
duke@0 219
duke@0 220
duke@0 221 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
duke@0 222 address entry = __ pc();
duke@0 223
duke@0 224 // In SSE mode, FP results are in xmm0
duke@0 225 if (state == ftos && UseSSE > 0) {
never@307 226 __ subptr(rsp, wordSize);
duke@0 227 __ movflt(Address(rsp, 0), xmm0);
duke@0 228 __ fld_s(Address(rsp, 0));
never@307 229 __ addptr(rsp, wordSize);
duke@0 230 } else if (state == dtos && UseSSE >= 2) {
never@307 231 __ subptr(rsp, 2*wordSize);
duke@0 232 __ movdbl(Address(rsp, 0), xmm0);
duke@0 233 __ fld_d(Address(rsp, 0));
never@307 234 __ addptr(rsp, 2*wordSize);
duke@0 235 }
duke@0 236
duke@0 237 __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_deopt_entry_for in interpreter");
duke@0 238
duke@0 239 // The stack is not extended by deopt but we must NULL last_sp as this
duke@0 240 // entry is like a "return".
xlu@520 241 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 242 __ restore_bcp();
duke@0 243 __ restore_locals();
duke@0 244 // handle exceptions
duke@0 245 { Label L;
duke@0 246 const Register thread = rcx;
duke@0 247 __ get_thread(thread);
never@307 248 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
duke@0 249 __ jcc(Assembler::zero, L);
duke@0 250 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
duke@0 251 __ should_not_reach_here();
duke@0 252 __ bind(L);
duke@0 253 }
duke@0 254 __ dispatch_next(state, step);
duke@0 255 return entry;
duke@0 256 }
duke@0 257
duke@0 258
duke@0 259 int AbstractInterpreter::BasicType_as_index(BasicType type) {
duke@0 260 int i = 0;
duke@0 261 switch (type) {
duke@0 262 case T_BOOLEAN: i = 0; break;
duke@0 263 case T_CHAR : i = 1; break;
duke@0 264 case T_BYTE : i = 2; break;
duke@0 265 case T_SHORT : i = 3; break;
duke@0 266 case T_INT : // fall through
duke@0 267 case T_LONG : // fall through
duke@0 268 case T_VOID : i = 4; break;
duke@0 269 case T_FLOAT : i = 5; break; // have to treat float and double separately for SSE
duke@0 270 case T_DOUBLE : i = 6; break;
duke@0 271 case T_OBJECT : // fall through
duke@0 272 case T_ARRAY : i = 7; break;
duke@0 273 default : ShouldNotReachHere();
duke@0 274 }
duke@0 275 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
duke@0 276 return i;
duke@0 277 }
duke@0 278
duke@0 279
duke@0 280 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
duke@0 281 address entry = __ pc();
duke@0 282 switch (type) {
duke@0 283 case T_BOOLEAN: __ c2bool(rax); break;
never@307 284 case T_CHAR : __ andptr(rax, 0xFFFF); break;
duke@0 285 case T_BYTE : __ sign_extend_byte (rax); break;
duke@0 286 case T_SHORT : __ sign_extend_short(rax); break;
duke@0 287 case T_INT : /* nothing to do */ break;
duke@0 288 case T_DOUBLE :
duke@0 289 case T_FLOAT :
duke@0 290 { const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
never@307 291 __ pop(t); // remove return address first
duke@0 292 // Must return a result for interpreter or compiler. In SSE
duke@0 293 // mode, results are returned in xmm0 and the FPU stack must
duke@0 294 // be empty.
duke@0 295 if (type == T_FLOAT && UseSSE >= 1) {
duke@0 296 // Load ST0
duke@0 297 __ fld_d(Address(rsp, 0));
duke@0 298 // Store as float and empty fpu stack
duke@0 299 __ fstp_s(Address(rsp, 0));
duke@0 300 // and reload
duke@0 301 __ movflt(xmm0, Address(rsp, 0));
duke@0 302 } else if (type == T_DOUBLE && UseSSE >= 2 ) {
duke@0 303 __ movdbl(xmm0, Address(rsp, 0));
duke@0 304 } else {
duke@0 305 // restore ST0
duke@0 306 __ fld_d(Address(rsp, 0));
duke@0 307 }
duke@0 308 // and pop the temp
never@307 309 __ addptr(rsp, 2 * wordSize);
never@307 310 __ push(t); // restore return address
duke@0 311 }
duke@0 312 break;
duke@0 313 case T_OBJECT :
duke@0 314 // retrieve result from frame
never@307 315 __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize));
duke@0 316 // and verify it
duke@0 317 __ verify_oop(rax);
duke@0 318 break;
duke@0 319 default : ShouldNotReachHere();
duke@0 320 }
duke@0 321 __ ret(0); // return from result handler
duke@0 322 return entry;
duke@0 323 }
duke@0 324
duke@0 325 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
duke@0 326 address entry = __ pc();
duke@0 327 __ push(state);
duke@0 328 __ call_VM(noreg, runtime_entry);
duke@0 329 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
duke@0 330 return entry;
duke@0 331 }
duke@0 332
duke@0 333
duke@0 334 // Helpers for commoning out cases in the various type of method entries.
duke@0 335 //
duke@0 336
duke@0 337 // increment invocation count & check for overflow
duke@0 338 //
duke@0 339 // Note: checking for negative value instead of overflow
duke@0 340 // so we have a 'sticky' overflow test
duke@0 341 //
duke@0 342 // rbx,: method
duke@0 343 // rcx: invocation counter
duke@0 344 //
duke@0 345 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
iveresov@1805 346 const Address invocation_counter(rbx, in_bytes(methodOopDesc::invocation_counter_offset()) +
iveresov@1805 347 in_bytes(InvocationCounter::counter_offset()));
iveresov@1805 348 // Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not.
iveresov@1805 349 if (TieredCompilation) {
iveresov@1805 350 int increment = InvocationCounter::count_increment;
iveresov@1805 351 int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
iveresov@1805 352 Label no_mdo, done;
iveresov@1805 353 if (ProfileInterpreter) {
iveresov@1805 354 // Are we profiling?
iveresov@1805 355 __ movptr(rax, Address(rbx, methodOopDesc::method_data_offset()));
iveresov@1805 356 __ testptr(rax, rax);
iveresov@1805 357 __ jccb(Assembler::zero, no_mdo);
iveresov@1805 358 // Increment counter in the MDO
iveresov@1805 359 const Address mdo_invocation_counter(rax, in_bytes(methodDataOopDesc::invocation_counter_offset()) +
iveresov@1805 360 in_bytes(InvocationCounter::counter_offset()));
iveresov@1805 361 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rcx, false, Assembler::zero, overflow);
iveresov@1805 362 __ jmpb(done);
iveresov@1805 363 }
iveresov@1805 364 __ bind(no_mdo);
iveresov@1805 365 // Increment counter in methodOop (we don't need to load it, it's in rcx).
iveresov@1805 366 __ increment_mask_and_jump(invocation_counter, increment, mask, rcx, true, Assembler::zero, overflow);
iveresov@1805 367 __ bind(done);
iveresov@1805 368 } else {
iveresov@1805 369 const Address backedge_counter (rbx, methodOopDesc::backedge_counter_offset() +
iveresov@1805 370 InvocationCounter::counter_offset());
duke@0 371
iveresov@1805 372 if (ProfileInterpreter) { // %%% Merge this into methodDataOop
iveresov@1805 373 __ incrementl(Address(rbx,methodOopDesc::interpreter_invocation_counter_offset()));
iveresov@1805 374 }
iveresov@1805 375 // Update standard invocation counters
iveresov@1805 376 __ movl(rax, backedge_counter); // load backedge counter
duke@0 377
iveresov@1805 378 __ incrementl(rcx, InvocationCounter::count_increment);
iveresov@1805 379 __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits
iveresov@1805 380
iveresov@1805 381 __ movl(invocation_counter, rcx); // save invocation count
iveresov@1805 382 __ addl(rcx, rax); // add both counters
iveresov@1805 383
iveresov@1805 384 // profile_method is non-null only for interpreted method so
iveresov@1805 385 // profile_method != NULL == !native_call
iveresov@1805 386 // BytecodeInterpreter only calls for native so code is elided.
iveresov@1805 387
iveresov@1805 388 if (ProfileInterpreter && profile_method != NULL) {
iveresov@1805 389 // Test to see if we should create a method data oop
iveresov@1805 390 __ cmp32(rcx,
iveresov@1805 391 ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit));
iveresov@1805 392 __ jcc(Assembler::less, *profile_method_continue);
iveresov@1805 393
iveresov@1805 394 // if no method data exists, go to profile_method
iveresov@1805 395 __ test_method_data_pointer(rax, *profile_method);
iveresov@1805 396 }
iveresov@1805 397
iveresov@1805 398 __ cmp32(rcx,
iveresov@1805 399 ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
iveresov@1805 400 __ jcc(Assembler::aboveEqual, *overflow);
duke@0 401 }
duke@0 402 }
duke@0 403
duke@0 404 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
duke@0 405
duke@0 406 // Asm interpreter on entry
duke@0 407 // rdi - locals
duke@0 408 // rsi - bcp
duke@0 409 // rbx, - method
duke@0 410 // rdx - cpool
duke@0 411 // rbp, - interpreter frame
duke@0 412
duke@0 413 // C++ interpreter on entry
duke@0 414 // rsi - new interpreter state pointer
duke@0 415 // rbp - interpreter frame pointer
duke@0 416 // rbx - method
duke@0 417
duke@0 418 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
duke@0 419 // rbx, - method
duke@0 420 // rcx - rcvr (assuming there is one)
duke@0 421 // top of stack return address of interpreter caller
duke@0 422 // rsp - sender_sp
duke@0 423
duke@0 424 // C++ interpreter only
duke@0 425 // rsi - previous interpreter state pointer
duke@0 426
duke@0 427 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
duke@0 428
duke@0 429 // InterpreterRuntime::frequency_counter_overflow takes one argument
duke@0 430 // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
duke@0 431 // The call returns the address of the verified entry point for the method or NULL
duke@0 432 // if the compilation did not complete (either went background or bailed out).
glewis@522 433 __ movptr(rax, (intptr_t)false);
duke@0 434 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
duke@0 435
never@307 436 __ movptr(rbx, Address(rbp, method_offset)); // restore methodOop
duke@0 437
duke@0 438 // Preserve invariant that rsi/rdi contain bcp/locals of sender frame
duke@0 439 // and jump to the interpreted entry.
duke@0 440 __ jmp(*do_continue, relocInfo::none);
duke@0 441
duke@0 442 }
duke@0 443
duke@0 444 void InterpreterGenerator::generate_stack_overflow_check(void) {
duke@0 445 // see if we've got enough room on the stack for locals plus overhead.
duke@0 446 // the expression stack grows down incrementally, so the normal guard
duke@0 447 // page mechanism will work for that.
duke@0 448 //
duke@0 449 // Registers live on entry:
duke@0 450 //
duke@0 451 // Asm interpreter
duke@0 452 // rdx: number of additional locals this frame needs (what we must check)
duke@0 453 // rbx,: methodOop
duke@0 454
duke@0 455 // destroyed on exit
duke@0 456 // rax,
duke@0 457
duke@0 458 // NOTE: since the additional locals are also always pushed (wasn't obvious in
duke@0 459 // generate_method_entry) so the guard should work for them too.
duke@0 460 //
duke@0 461
duke@0 462 // monitor entry size: see picture of stack set (generate_method_entry) and frame_x86.hpp
duke@0 463 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
duke@0 464
duke@0 465 // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
duke@0 466 // be sure to change this if you add/subtract anything to/from the overhead area
duke@0 467 const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize) + entry_size;
duke@0 468
duke@0 469 const int page_size = os::vm_page_size();
duke@0 470
duke@0 471 Label after_frame_check;
duke@0 472
duke@0 473 // see if the frame is greater than one page in size. If so,
duke@0 474 // then we need to verify there is enough stack space remaining
duke@0 475 // for the additional locals.
twisti@1517 476 __ cmpl(rdx, (page_size - overhead_size)/Interpreter::stackElementSize);
duke@0 477 __ jcc(Assembler::belowEqual, after_frame_check);
duke@0 478
duke@0 479 // compute rsp as if this were going to be the last frame on
duke@0 480 // the stack before the red zone
duke@0 481
duke@0 482 Label after_frame_check_pop;
duke@0 483
never@307 484 __ push(rsi);
duke@0 485
duke@0 486 const Register thread = rsi;
duke@0 487
duke@0 488 __ get_thread(thread);
duke@0 489
duke@0 490 const Address stack_base(thread, Thread::stack_base_offset());
duke@0 491 const Address stack_size(thread, Thread::stack_size_offset());
duke@0 492
duke@0 493 // locals + overhead, in bytes
never@307 494 __ lea(rax, Address(noreg, rdx, Interpreter::stackElementScale(), overhead_size));
duke@0 495
duke@0 496 #ifdef ASSERT
duke@0 497 Label stack_base_okay, stack_size_okay;
duke@0 498 // verify that thread stack base is non-zero
never@307 499 __ cmpptr(stack_base, (int32_t)NULL_WORD);
duke@0 500 __ jcc(Assembler::notEqual, stack_base_okay);
duke@0 501 __ stop("stack base is zero");
duke@0 502 __ bind(stack_base_okay);
duke@0 503 // verify that thread stack size is non-zero
never@307 504 __ cmpptr(stack_size, 0);
duke@0 505 __ jcc(Assembler::notEqual, stack_size_okay);
duke@0 506 __ stop("stack size is zero");
duke@0 507 __ bind(stack_size_okay);
duke@0 508 #endif
duke@0 509
duke@0 510 // Add stack base to locals and subtract stack size
never@307 511 __ addptr(rax, stack_base);
never@307 512 __ subptr(rax, stack_size);
duke@0 513
duke@0 514 // Use the maximum number of pages we might bang.
duke@0 515 const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
duke@0 516 (StackRedPages+StackYellowPages);
never@307 517 __ addptr(rax, max_pages * page_size);
duke@0 518
duke@0 519 // check against the current stack bottom
never@307 520 __ cmpptr(rsp, rax);
duke@0 521 __ jcc(Assembler::above, after_frame_check_pop);
duke@0 522
never@307 523 __ pop(rsi); // get saved bcp / (c++ prev state ).
duke@0 524
never@307 525 __ pop(rax); // get return address
duke@0 526 __ jump(ExternalAddress(Interpreter::throw_StackOverflowError_entry()));
duke@0 527
duke@0 528 // all done with frame size check
duke@0 529 __ bind(after_frame_check_pop);
never@307 530 __ pop(rsi);
duke@0 531
duke@0 532 __ bind(after_frame_check);
duke@0 533 }
duke@0 534
duke@0 535 // Allocate monitor and lock method (asm interpreter)
duke@0 536 // rbx, - methodOop
duke@0 537 //
duke@0 538 void InterpreterGenerator::lock_method(void) {
duke@0 539 // synchronize method
duke@0 540 const Address access_flags (rbx, methodOopDesc::access_flags_offset());
duke@0 541 const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
duke@0 542 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
duke@0 543
duke@0 544 #ifdef ASSERT
duke@0 545 { Label L;
duke@0 546 __ movl(rax, access_flags);
duke@0 547 __ testl(rax, JVM_ACC_SYNCHRONIZED);
duke@0 548 __ jcc(Assembler::notZero, L);
duke@0 549 __ stop("method doesn't need synchronization");
duke@0 550 __ bind(L);
duke@0 551 }
duke@0 552 #endif // ASSERT
duke@0 553 // get synchronization object
duke@0 554 { Label done;
duke@0 555 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
duke@0 556 __ movl(rax, access_flags);
duke@0 557 __ testl(rax, JVM_ACC_STATIC);
never@307 558 __ movptr(rax, Address(rdi, Interpreter::local_offset_in_bytes(0))); // get receiver (assume this is frequent case)
duke@0 559 __ jcc(Assembler::zero, done);
never@307 560 __ movptr(rax, Address(rbx, methodOopDesc::constants_offset()));
never@307 561 __ movptr(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes()));
never@307 562 __ movptr(rax, Address(rax, mirror_offset));
duke@0 563 __ bind(done);
duke@0 564 }
duke@0 565 // add space for monitor & lock
never@307 566 __ subptr(rsp, entry_size); // add space for a monitor entry
never@307 567 __ movptr(monitor_block_top, rsp); // set new monitor block top
never@307 568 __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object
never@307 569 __ mov(rdx, rsp); // object address
duke@0 570 __ lock_object(rdx);
duke@0 571 }
duke@0 572
duke@0 573 //
duke@0 574 // Generate a fixed interpreter frame. This is identical setup for interpreted methods
duke@0 575 // and for native methods hence the shared code.
duke@0 576
duke@0 577 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
duke@0 578 // initialize fixed part of activation frame
never@307 579 __ push(rax); // save return address
duke@0 580 __ enter(); // save old & set new rbp,
duke@0 581
duke@0 582
never@307 583 __ push(rsi); // set sender sp
never@307 584 __ push((int32_t)NULL_WORD); // leave last_sp as null
never@307 585 __ movptr(rsi, Address(rbx,methodOopDesc::const_offset())); // get constMethodOop
never@307 586 __ lea(rsi, Address(rsi,constMethodOopDesc::codes_offset())); // get codebase
never@307 587 __ push(rbx); // save methodOop
duke@0 588 if (ProfileInterpreter) {
duke@0 589 Label method_data_continue;
never@307 590 __ movptr(rdx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
never@307 591 __ testptr(rdx, rdx);
duke@0 592 __ jcc(Assembler::zero, method_data_continue);
never@307 593 __ addptr(rdx, in_bytes(methodDataOopDesc::data_offset()));
duke@0 594 __ bind(method_data_continue);
never@307 595 __ push(rdx); // set the mdp (method data pointer)
duke@0 596 } else {
never@307 597 __ push(0);
duke@0 598 }
duke@0 599
never@307 600 __ movptr(rdx, Address(rbx, methodOopDesc::constants_offset()));
never@307 601 __ movptr(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes()));
never@307 602 __ push(rdx); // set constant pool cache
never@307 603 __ push(rdi); // set locals pointer
duke@0 604 if (native_call) {
never@307 605 __ push(0); // no bcp
duke@0 606 } else {
never@307 607 __ push(rsi); // set bcp
duke@0 608 }
never@307 609 __ push(0); // reserve word for pointer to expression stack bottom
never@307 610 __ movptr(Address(rsp, 0), rsp); // set expression stack bottom
duke@0 611 }
duke@0 612
duke@0 613 // End of helpers
duke@0 614
duke@0 615 //
duke@0 616 // Various method entries
duke@0 617 //------------------------------------------------------------------------------------------------------------------------
duke@0 618 //
duke@0 619 //
duke@0 620
duke@0 621 // Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry
duke@0 622
duke@0 623 address InterpreterGenerator::generate_accessor_entry(void) {
duke@0 624
duke@0 625 // rbx,: methodOop
duke@0 626 // rcx: receiver (preserve for slow entry into asm interpreter)
duke@0 627
duke@0 628 // rsi: senderSP must preserved for slow path, set SP to it on fast path
duke@0 629
duke@0 630 address entry_point = __ pc();
duke@0 631 Label xreturn_path;
duke@0 632
duke@0 633 // do fastpath for resolved accessor methods
duke@0 634 if (UseFastAccessorMethods) {
duke@0 635 Label slow_path;
duke@0 636 // If we need a safepoint check, generate full interpreter entry.
duke@0 637 ExternalAddress state(SafepointSynchronize::address_of_state());
duke@0 638 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
duke@0 639 SafepointSynchronize::_not_synchronized);
duke@0 640
duke@0 641 __ jcc(Assembler::notEqual, slow_path);
duke@0 642 // ASM/C++ Interpreter
duke@0 643 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1
duke@0 644 // Note: We can only use this code if the getfield has been resolved
duke@0 645 // and if we don't have a null-pointer exception => check for
duke@0 646 // these conditions first and use slow path if necessary.
duke@0 647 // rbx,: method
duke@0 648 // rcx: receiver
never@307 649 __ movptr(rax, Address(rsp, wordSize));
duke@0 650
duke@0 651 // check if local 0 != NULL and read field
never@307 652 __ testptr(rax, rax);
duke@0 653 __ jcc(Assembler::zero, slow_path);
duke@0 654
never@307 655 __ movptr(rdi, Address(rbx, methodOopDesc::constants_offset()));
duke@0 656 // read first instruction word and extract bytecode @ 1 and index @ 2
never@307 657 __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
duke@0 658 __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
duke@0 659 // Shift codes right to get the index on the right.
duke@0 660 // The bytecode fetched looks like <index><0xb4><0x2a>
duke@0 661 __ shrl(rdx, 2*BitsPerByte);
duke@0 662 __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
never@307 663 __ movptr(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes()));
duke@0 664
duke@0 665 // rax,: local 0
duke@0 666 // rbx,: method
duke@0 667 // rcx: receiver - do not destroy since it is needed for slow path!
duke@0 668 // rcx: scratch
duke@0 669 // rdx: constant pool cache index
duke@0 670 // rdi: constant pool cache
duke@0 671 // rsi: sender sp
duke@0 672
duke@0 673 // check if getfield has been resolved and read constant pool cache entry
duke@0 674 // check the validity of the cache entry by testing whether _indices field
duke@0 675 // contains Bytecode::_getfield in b1 byte.
duke@0 676 assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
duke@0 677 __ movl(rcx,
duke@0 678 Address(rdi,
duke@0 679 rdx,
never@307 680 Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
duke@0 681 __ shrl(rcx, 2*BitsPerByte);
duke@0 682 __ andl(rcx, 0xFF);
duke@0 683 __ cmpl(rcx, Bytecodes::_getfield);
duke@0 684 __ jcc(Assembler::notEqual, slow_path);
duke@0 685
duke@0 686 // Note: constant pool entry is not valid before bytecode is resolved
never@307 687 __ movptr(rcx,
never@307 688 Address(rdi,
never@307 689 rdx,
never@307 690 Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset()));
duke@0 691 __ movl(rdx,
duke@0 692 Address(rdi,
duke@0 693 rdx,
never@307 694 Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset()));
duke@0 695
duke@0 696 Label notByte, notShort, notChar;
duke@0 697 const Address field_address (rax, rcx, Address::times_1);
duke@0 698
duke@0 699 // Need to differentiate between igetfield, agetfield, bgetfield etc.
duke@0 700 // because they are different sizes.
duke@0 701 // Use the type from the constant pool cache
duke@0 702 __ shrl(rdx, ConstantPoolCacheEntry::tosBits);
duke@0 703 // Make sure we don't need to mask rdx for tosBits after the above shift
duke@0 704 ConstantPoolCacheEntry::verify_tosBits();
duke@0 705 __ cmpl(rdx, btos);
duke@0 706 __ jcc(Assembler::notEqual, notByte);
duke@0 707 __ load_signed_byte(rax, field_address);
duke@0 708 __ jmp(xreturn_path);
duke@0 709
duke@0 710 __ bind(notByte);
duke@0 711 __ cmpl(rdx, stos);
duke@0 712 __ jcc(Assembler::notEqual, notShort);
jrose@660 713 __ load_signed_short(rax, field_address);
duke@0 714 __ jmp(xreturn_path);
duke@0 715
duke@0 716 __ bind(notShort);
duke@0 717 __ cmpl(rdx, ctos);
duke@0 718 __ jcc(Assembler::notEqual, notChar);
jrose@660 719 __ load_unsigned_short(rax, field_address);
duke@0 720 __ jmp(xreturn_path);
duke@0 721
duke@0 722 __ bind(notChar);
duke@0 723 #ifdef ASSERT
duke@0 724 Label okay;
duke@0 725 __ cmpl(rdx, atos);
duke@0 726 __ jcc(Assembler::equal, okay);
duke@0 727 __ cmpl(rdx, itos);
duke@0 728 __ jcc(Assembler::equal, okay);
duke@0 729 __ stop("what type is this?");
duke@0 730 __ bind(okay);
duke@0 731 #endif // ASSERT
duke@0 732 // All the rest are a 32 bit wordsize
never@307 733 // This is ok for now. Since fast accessors should be going away
never@307 734 __ movptr(rax, field_address);
duke@0 735
duke@0 736 __ bind(xreturn_path);
duke@0 737
duke@0 738 // _ireturn/_areturn
never@307 739 __ pop(rdi); // get return address
never@307 740 __ mov(rsp, rsi); // set sp to sender sp
duke@0 741 __ jmp(rdi);
duke@0 742
duke@0 743 // generate a vanilla interpreter entry as the slow path
duke@0 744 __ bind(slow_path);
duke@0 745
duke@0 746 (void) generate_normal_entry(false);
duke@0 747 return entry_point;
duke@0 748 }
duke@0 749 return NULL;
duke@0 750
duke@0 751 }
duke@0 752
johnc@2488 753 // Method entry for java.lang.ref.Reference.get.
johnc@2488 754 address InterpreterGenerator::generate_Reference_get_entry(void) {
johnc@2488 755 #ifndef SERIALGC
johnc@2488 756 // Code: _aload_0, _getfield, _areturn
johnc@2488 757 // parameter size = 1
johnc@2488 758 //
johnc@2488 759 // The code that gets generated by this routine is split into 2 parts:
johnc@2488 760 // 1. The "intrinsified" code for G1 (or any SATB based GC),
johnc@2488 761 // 2. The slow path - which is an expansion of the regular method entry.
johnc@2488 762 //
johnc@2488 763 // Notes:-
johnc@2488 764 // * In the G1 code we do not check whether we need to block for
johnc@2488 765 // a safepoint. If G1 is enabled then we must execute the specialized
johnc@2488 766 // code for Reference.get (except when the Reference object is null)
johnc@2488 767 // so that we can log the value in the referent field with an SATB
johnc@2488 768 // update buffer.
johnc@2488 769 // If the code for the getfield template is modified so that the
johnc@2488 770 // G1 pre-barrier code is executed when the current method is
johnc@2488 771 // Reference.get() then going through the normal method entry
johnc@2488 772 // will be fine.
johnc@2488 773 // * The G1 code below can, however, check the receiver object (the instance
johnc@2488 774 // of java.lang.Reference) and jump to the slow path if null. If the
johnc@2488 775 // Reference object is null then we obviously cannot fetch the referent
johnc@2488 776 // and so we don't need to call the G1 pre-barrier. Thus we can use the
johnc@2488 777 // regular method entry code to generate the NPE.
johnc@2488 778 //
johnc@2488 779 // This code is based on generate_accessor_enty.
johnc@2488 780
johnc@2488 781 // rbx,: methodOop
johnc@2488 782 // rcx: receiver (preserve for slow entry into asm interpreter)
johnc@2488 783
johnc@2488 784 // rsi: senderSP must preserved for slow path, set SP to it on fast path
johnc@2488 785
johnc@2488 786 address entry = __ pc();
johnc@2488 787
johnc@2488 788 const int referent_offset = java_lang_ref_Reference::referent_offset;
johnc@2488 789 guarantee(referent_offset > 0, "referent offset not initialized");
johnc@2488 790
johnc@2488 791 if (UseG1GC) {
johnc@2488 792 Label slow_path;
johnc@2488 793
johnc@2488 794 // Check if local 0 != NULL
johnc@2488 795 // If the receiver is null then it is OK to jump to the slow path.
johnc@2488 796 __ movptr(rax, Address(rsp, wordSize));
johnc@2488 797 __ testptr(rax, rax);
johnc@2488 798 __ jcc(Assembler::zero, slow_path);
johnc@2488 799
johnc@2488 800 // rax: local 0 (must be preserved across the G1 barrier call)
johnc@2488 801 //
johnc@2488 802 // rbx: method (at this point it's scratch)
johnc@2488 803 // rcx: receiver (at this point it's scratch)
johnc@2488 804 // rdx: scratch
johnc@2488 805 // rdi: scratch
johnc@2488 806 //
johnc@2488 807 // rsi: sender sp
johnc@2488 808
johnc@2488 809 // Preserve the sender sp in case the pre-barrier
johnc@2488 810 // calls the runtime
johnc@2488 811 __ push(rsi);
johnc@2488 812
johnc@2488 813 // Load the value of the referent field.
johnc@2488 814 const Address field_address(rax, referent_offset);
johnc@2488 815 __ movptr(rax, field_address);
johnc@2488 816
johnc@2488 817 // Generate the G1 pre-barrier code to log the value of
johnc@2488 818 // the referent field in an SATB buffer.
johnc@2488 819 __ get_thread(rcx);
johnc@2488 820 __ g1_write_barrier_pre(noreg /* obj */,
johnc@2488 821 rax /* pre_val */,
johnc@2488 822 rcx /* thread */,
johnc@2488 823 rbx /* tmp */,
johnc@2488 824 true /* tosca_save */,
johnc@2488 825 true /* expand_call */);
johnc@2488 826
johnc@2488 827 // _areturn
johnc@2488 828 __ pop(rsi); // get sender sp
johnc@2488 829 __ pop(rdi); // get return address
johnc@2488 830 __ mov(rsp, rsi); // set sp to sender sp
johnc@2488 831 __ jmp(rdi);
johnc@2488 832
johnc@2488 833 __ bind(slow_path);
johnc@2488 834 (void) generate_normal_entry(false);
johnc@2488 835
johnc@2488 836 return entry;
johnc@2488 837 }
johnc@2488 838 #endif // SERIALGC
johnc@2488 839
johnc@2488 840 // If G1 is not enabled then attempt to go through the accessor entry point
johnc@2488 841 // Reference.get is an accessor
johnc@2488 842 return generate_accessor_entry();
johnc@2488 843 }
johnc@2488 844
duke@0 845 //
duke@0 846 // Interpreter stub for calling a native method. (asm interpreter)
duke@0 847 // This sets up a somewhat different looking stack for calling the native method
duke@0 848 // than the typical interpreter frame setup.
duke@0 849 //
duke@0 850
duke@0 851 address InterpreterGenerator::generate_native_entry(bool synchronized) {
duke@0 852 // determine code generation flags
duke@0 853 bool inc_counter = UseCompiler || CountCompiledCalls;
duke@0 854
duke@0 855 // rbx,: methodOop
duke@0 856 // rsi: sender sp
duke@0 857 // rsi: previous interpreter state (C++ interpreter) must preserve
duke@0 858 address entry_point = __ pc();
duke@0 859
duke@0 860
duke@0 861 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
duke@0 862 const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
duke@0 863 const Address access_flags (rbx, methodOopDesc::access_flags_offset());
duke@0 864
duke@0 865 // get parameter size (always needed)
jrose@660 866 __ load_unsigned_short(rcx, size_of_parameters);
duke@0 867
duke@0 868 // native calls don't need the stack size check since they have no expression stack
duke@0 869 // and the arguments are already on the stack and we only add a handful of words
duke@0 870 // to the stack
duke@0 871
duke@0 872 // rbx,: methodOop
duke@0 873 // rcx: size of parameters
duke@0 874 // rsi: sender sp
duke@0 875
never@307 876 __ pop(rax); // get return address
duke@0 877 // for natives the size of locals is zero
duke@0 878
duke@0 879 // compute beginning of parameters (rdi)
never@307 880 __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
duke@0 881
duke@0 882
duke@0 883 // add 2 zero-initialized slots for native calls
duke@0 884 // NULL result handler
never@307 885 __ push((int32_t)NULL_WORD);
duke@0 886 // NULL oop temp (mirror or jni oop result)
never@307 887 __ push((int32_t)NULL_WORD);
duke@0 888
duke@0 889 if (inc_counter) __ movl(rcx, invocation_counter); // (pre-)fetch invocation count
duke@0 890 // initialize fixed part of activation frame
duke@0 891
duke@0 892 generate_fixed_frame(true);
duke@0 893
duke@0 894 // make sure method is native & not abstract
duke@0 895 #ifdef ASSERT
duke@0 896 __ movl(rax, access_flags);
duke@0 897 {
duke@0 898 Label L;
duke@0 899 __ testl(rax, JVM_ACC_NATIVE);
duke@0 900 __ jcc(Assembler::notZero, L);
duke@0 901 __ stop("tried to execute non-native method as native");
duke@0 902 __ bind(L);
duke@0 903 }
duke@0 904 { Label L;
duke@0 905 __ testl(rax, JVM_ACC_ABSTRACT);
duke@0 906 __ jcc(Assembler::zero, L);
duke@0 907 __ stop("tried to execute abstract method in interpreter");
duke@0 908 __ bind(L);
duke@0 909 }
duke@0 910 #endif
duke@0 911
duke@0 912 // Since at this point in the method invocation the exception handler
duke@0 913 // would try to exit the monitor of synchronized methods which hasn't
duke@0 914 // been entered yet, we set the thread local variable
duke@0 915 // _do_not_unlock_if_synchronized to true. The remove_activation will
duke@0 916 // check this flag.
duke@0 917
duke@0 918 __ get_thread(rax);
duke@0 919 const Address do_not_unlock_if_synchronized(rax,
duke@0 920 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
duke@0 921 __ movbool(do_not_unlock_if_synchronized, true);
duke@0 922
duke@0 923 // increment invocation count & check for overflow
duke@0 924 Label invocation_counter_overflow;
duke@0 925 if (inc_counter) {
duke@0 926 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
duke@0 927 }
duke@0 928
duke@0 929 Label continue_after_compile;
duke@0 930 __ bind(continue_after_compile);
duke@0 931
duke@0 932 bang_stack_shadow_pages(true);
duke@0 933
duke@0 934 // reset the _do_not_unlock_if_synchronized flag
duke@0 935 __ get_thread(rax);
duke@0 936 __ movbool(do_not_unlock_if_synchronized, false);
duke@0 937
duke@0 938 // check for synchronized methods
duke@0 939 // Must happen AFTER invocation_counter check and stack overflow check,
duke@0 940 // so method is not locked if overflows.
duke@0 941 //
duke@0 942 if (synchronized) {
duke@0 943 lock_method();
duke@0 944 } else {
duke@0 945 // no synchronization necessary
duke@0 946 #ifdef ASSERT
duke@0 947 { Label L;
duke@0 948 __ movl(rax, access_flags);
duke@0 949 __ testl(rax, JVM_ACC_SYNCHRONIZED);
duke@0 950 __ jcc(Assembler::zero, L);
duke@0 951 __ stop("method needs synchronization");
duke@0 952 __ bind(L);
duke@0 953 }
duke@0 954 #endif
duke@0 955 }
duke@0 956
duke@0 957 // start execution
duke@0 958 #ifdef ASSERT
duke@0 959 { Label L;
duke@0 960 const Address monitor_block_top (rbp,
duke@0 961 frame::interpreter_frame_monitor_block_top_offset * wordSize);
never@307 962 __ movptr(rax, monitor_block_top);
never@307 963 __ cmpptr(rax, rsp);
duke@0 964 __ jcc(Assembler::equal, L);
duke@0 965 __ stop("broken stack frame setup in interpreter");
duke@0 966 __ bind(L);
duke@0 967 }
duke@0 968 #endif
duke@0 969
duke@0 970 // jvmti/dtrace support
duke@0 971 __ notify_method_entry();
duke@0 972
duke@0 973 // work registers
duke@0 974 const Register method = rbx;
duke@0 975 const Register thread = rdi;
duke@0 976 const Register t = rcx;
duke@0 977
duke@0 978 // allocate space for parameters
duke@0 979 __ get_method(method);
duke@0 980 __ verify_oop(method);
jrose@660 981 __ load_unsigned_short(t, Address(method, methodOopDesc::size_of_parameters_offset()));
twisti@1517 982 __ shlptr(t, Interpreter::logStackElementSize);
never@307 983 __ addptr(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror
never@307 984 __ subptr(rsp, t);
never@307 985 __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
duke@0 986
duke@0 987 // get signature handler
duke@0 988 { Label L;
never@307 989 __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
never@307 990 __ testptr(t, t);
duke@0 991 __ jcc(Assembler::notZero, L);
duke@0 992 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
duke@0 993 __ get_method(method);
never@307 994 __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
duke@0 995 __ bind(L);
duke@0 996 }
duke@0 997
duke@0 998 // call signature handler
duke@0 999 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rdi, "adjust this code");
duke@0 1000 assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code");
duke@0 1001 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t , "adjust this code");
duke@0 1002 // The generated handlers do not touch RBX (the method oop).
duke@0 1003 // However, large signatures cannot be cached and are generated
duke@0 1004 // each time here. The slow-path generator will blow RBX
duke@0 1005 // sometime, so we must reload it after the call.
duke@0 1006 __ call(t);
duke@0 1007 __ get_method(method); // slow path call blows RBX on DevStudio 5.0
duke@0 1008
duke@0 1009 // result handler is in rax,
duke@0 1010 // set result handler
never@307 1011 __ movptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize), rax);
duke@0 1012
duke@0 1013 // pass mirror handle if static call
duke@0 1014 { Label L;
duke@0 1015 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
duke@0 1016 __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
duke@0 1017 __ testl(t, JVM_ACC_STATIC);
duke@0 1018 __ jcc(Assembler::zero, L);
duke@0 1019 // get mirror
never@307 1020 __ movptr(t, Address(method, methodOopDesc:: constants_offset()));
never@307 1021 __ movptr(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes()));
never@307 1022 __ movptr(t, Address(t, mirror_offset));
duke@0 1023 // copy mirror into activation frame
never@307 1024 __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize), t);
duke@0 1025 // pass handle to mirror
never@307 1026 __ lea(t, Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize));
never@307 1027 __ movptr(Address(rsp, wordSize), t);
duke@0 1028 __ bind(L);
duke@0 1029 }
duke@0 1030
duke@0 1031 // get native function entry point
duke@0 1032 { Label L;
never@307 1033 __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
duke@0 1034 ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
never@307 1035 __ cmpptr(rax, unsatisfied.addr());
duke@0 1036 __ jcc(Assembler::notEqual, L);
duke@0 1037 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
duke@0 1038 __ get_method(method);
duke@0 1039 __ verify_oop(method);
never@307 1040 __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
duke@0 1041 __ bind(L);
duke@0 1042 }
duke@0 1043
duke@0 1044 // pass JNIEnv
duke@0 1045 __ get_thread(thread);
never@307 1046 __ lea(t, Address(thread, JavaThread::jni_environment_offset()));
never@307 1047 __ movptr(Address(rsp, 0), t);
duke@0 1048
duke@0 1049 // set_last_Java_frame_before_call
duke@0 1050 // It is enough that the pc()
duke@0 1051 // points into the right code segment. It does not have to be the correct return pc.
duke@0 1052 __ set_last_Java_frame(thread, noreg, rbp, __ pc());
duke@0 1053
duke@0 1054 // change thread state
duke@0 1055 #ifdef ASSERT
duke@0 1056 { Label L;
duke@0 1057 __ movl(t, Address(thread, JavaThread::thread_state_offset()));
duke@0 1058 __ cmpl(t, _thread_in_Java);
duke@0 1059 __ jcc(Assembler::equal, L);
duke@0 1060 __ stop("Wrong thread state in native stub");
duke@0 1061 __ bind(L);
duke@0 1062 }
duke@0 1063 #endif
duke@0 1064
duke@0 1065 // Change state to native
duke@0 1066 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);
duke@0 1067 __ call(rax);
duke@0 1068
duke@0 1069 // result potentially in rdx:rax or ST0
duke@0 1070
duke@0 1071 // Either restore the MXCSR register after returning from the JNI Call
duke@0 1072 // or verify that it wasn't changed.
duke@0 1073 if (VM_Version::supports_sse()) {
duke@0 1074 if (RestoreMXCSROnJNICalls) {
duke@0 1075 __ ldmxcsr(ExternalAddress(StubRoutines::addr_mxcsr_std()));
duke@0 1076 }
duke@0 1077 else if (CheckJNICalls ) {
never@307 1078 __ call(RuntimeAddress(StubRoutines::x86::verify_mxcsr_entry()));
duke@0 1079 }
duke@0 1080 }
duke@0 1081
duke@0 1082 // Either restore the x87 floating pointer control word after returning
duke@0 1083 // from the JNI call or verify that it wasn't changed.
duke@0 1084 if (CheckJNICalls) {
never@307 1085 __ call(RuntimeAddress(StubRoutines::x86::verify_fpu_cntrl_wrd_entry()));
duke@0 1086 }
duke@0 1087
duke@0 1088 // save potential result in ST(0) & rdx:rax
duke@0 1089 // (if result handler is the T_FLOAT or T_DOUBLE handler, result must be in ST0 -
duke@0 1090 // the check is necessary to avoid potential Intel FPU overflow problems by saving/restoring 'empty' FPU registers)
duke@0 1091 // It is safe to do this push because state is _thread_in_native and return address will be found
duke@0 1092 // via _last_native_pc and not via _last_jave_sp
duke@0 1093
duke@0 1094 // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
duke@0 1095 // If the order changes or anything else is added to the stack the code in
duke@0 1096 // interpreter_frame_result will have to be changed.
duke@0 1097
duke@0 1098 { Label L;
duke@0 1099 Label push_double;
duke@0 1100 ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
duke@0 1101 ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
duke@0 1102 __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
duke@0 1103 float_handler.addr());
duke@0 1104 __ jcc(Assembler::equal, push_double);
duke@0 1105 __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
duke@0 1106 double_handler.addr());
duke@0 1107 __ jcc(Assembler::notEqual, L);
duke@0 1108 __ bind(push_double);
duke@0 1109 __ push(dtos);
duke@0 1110 __ bind(L);
duke@0 1111 }
duke@0 1112 __ push(ltos);
duke@0 1113
duke@0 1114 // change thread state
duke@0 1115 __ get_thread(thread);
duke@0 1116 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
duke@0 1117 if(os::is_MP()) {
duke@0 1118 if (UseMembar) {
never@307 1119 // Force this write out before the read below
never@307 1120 __ membar(Assembler::Membar_mask_bits(
never@307 1121 Assembler::LoadLoad | Assembler::LoadStore |
never@307 1122 Assembler::StoreLoad | Assembler::StoreStore));
duke@0 1123 } else {
duke@0 1124 // Write serialization page so VM thread can do a pseudo remote membar.
duke@0 1125 // We use the current thread pointer to calculate a thread specific
duke@0 1126 // offset to write to within the page. This minimizes bus traffic
duke@0 1127 // due to cache line collision.
duke@0 1128 __ serialize_memory(thread, rcx);
duke@0 1129 }
duke@0 1130 }
duke@0 1131
duke@0 1132 if (AlwaysRestoreFPU) {
duke@0 1133 // Make sure the control word is correct.
duke@0 1134 __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
duke@0 1135 }
duke@0 1136
duke@0 1137 // check for safepoint operation in progress and/or pending suspend requests
duke@0 1138 { Label Continue;
duke@0 1139
duke@0 1140 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
duke@0 1141 SafepointSynchronize::_not_synchronized);
duke@0 1142
duke@0 1143 Label L;
duke@0 1144 __ jcc(Assembler::notEqual, L);
duke@0 1145 __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
duke@0 1146 __ jcc(Assembler::equal, Continue);
duke@0 1147 __ bind(L);
duke@0 1148
duke@0 1149 // Don't use call_VM as it will see a possible pending exception and forward it
duke@0 1150 // and never return here preventing us from clearing _last_native_pc down below.
duke@0 1151 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
duke@0 1152 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
duke@0 1153 // by hand.
duke@0 1154 //
never@307 1155 __ push(thread);
duke@0 1156 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
duke@0 1157 JavaThread::check_special_condition_for_native_trans)));
duke@0 1158 __ increment(rsp, wordSize);
duke@0 1159 __ get_thread(thread);
duke@0 1160
duke@0 1161 __ bind(Continue);
duke@0 1162 }
duke@0 1163
duke@0 1164 // change thread state
duke@0 1165 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
duke@0 1166
duke@0 1167 __ reset_last_Java_frame(thread, true, true);
duke@0 1168
duke@0 1169 // reset handle block
never@307 1170 __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
xlu@520 1171 __ movptr(Address(t, JNIHandleBlock::top_offset_in_bytes()), NULL_WORD);
duke@0 1172
duke@0 1173 // If result was an oop then unbox and save it in the frame
duke@0 1174 { Label L;
duke@0 1175 Label no_oop, store_result;
duke@0 1176 ExternalAddress handler(AbstractInterpreter::result_handler(T_OBJECT));
duke@0 1177 __ cmpptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize),
duke@0 1178 handler.addr());
duke@0 1179 __ jcc(Assembler::notEqual, no_oop);
never@307 1180 __ cmpptr(Address(rsp, 0), (int32_t)NULL_WORD);
duke@0 1181 __ pop(ltos);
never@307 1182 __ testptr(rax, rax);
duke@0 1183 __ jcc(Assembler::zero, store_result);
duke@0 1184 // unbox
never@307 1185 __ movptr(rax, Address(rax, 0));
duke@0 1186 __ bind(store_result);
never@307 1187 __ movptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset)*wordSize), rax);
duke@0 1188 // keep stack depth as expected by pushing oop which will eventually be discarded
duke@0 1189 __ push(ltos);
duke@0 1190 __ bind(no_oop);
duke@0 1191 }
duke@0 1192
duke@0 1193 {
duke@0 1194 Label no_reguard;
duke@0 1195 __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
duke@0 1196 __ jcc(Assembler::notEqual, no_reguard);
duke@0 1197
never@307 1198 __ pusha();
duke@0 1199 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
never@307 1200 __ popa();
duke@0 1201
duke@0 1202 __ bind(no_reguard);
duke@0 1203 }
duke@0 1204
duke@0 1205 // restore rsi to have legal interpreter frame,
duke@0 1206 // i.e., bci == 0 <=> rsi == code_base()
duke@0 1207 // Can't call_VM until bcp is within reasonable.
duke@0 1208 __ get_method(method); // method is junk from thread_in_native to now.
duke@0 1209 __ verify_oop(method);
never@307 1210 __ movptr(rsi, Address(method,methodOopDesc::const_offset())); // get constMethodOop
never@307 1211 __ lea(rsi, Address(rsi,constMethodOopDesc::codes_offset())); // get codebase
duke@0 1212
duke@0 1213 // handle exceptions (exception handling will handle unlocking!)
duke@0 1214 { Label L;
never@307 1215 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
duke@0 1216 __ jcc(Assembler::zero, L);
duke@0 1217 // Note: At some point we may want to unify this with the code used in call_VM_base();
duke@0 1218 // i.e., we should use the StubRoutines::forward_exception code. For now this
duke@0 1219 // doesn't work here because the rsp is not correctly set at this point.
duke@0 1220 __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
duke@0 1221 __ should_not_reach_here();
duke@0 1222 __ bind(L);
duke@0 1223 }
duke@0 1224
duke@0 1225 // do unlocking if necessary
duke@0 1226 { Label L;
duke@0 1227 __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
duke@0 1228 __ testl(t, JVM_ACC_SYNCHRONIZED);
duke@0 1229 __ jcc(Assembler::zero, L);
duke@0 1230 // the code below should be shared with interpreter macro assembler implementation
duke@0 1231 { Label unlock;
duke@0 1232 // BasicObjectLock will be first in list, since this is a synchronized method. However, need
duke@0 1233 // to check that the object has not been unlocked by an explicit monitorexit bytecode.
duke@0 1234 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
duke@0 1235
never@307 1236 __ lea(rdx, monitor); // address of first monitor
duke@0 1237
never@307 1238 __ movptr(t, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
never@307 1239 __ testptr(t, t);
duke@0 1240 __ jcc(Assembler::notZero, unlock);
duke@0 1241
duke@0 1242 // Entry already unlocked, need to throw exception
duke@0 1243 __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
duke@0 1244 __ should_not_reach_here();
duke@0 1245
duke@0 1246 __ bind(unlock);
duke@0 1247 __ unlock_object(rdx);
duke@0 1248 }
duke@0 1249 __ bind(L);
duke@0 1250 }
duke@0 1251
duke@0 1252 // jvmti/dtrace support
duke@0 1253 // Note: This must happen _after_ handling/throwing any exceptions since
duke@0 1254 // the exception handler code notifies the runtime of method exits
duke@0 1255 // too. If this happens before, method entry/exit notifications are
duke@0 1256 // not properly paired (was bug - gri 11/22/99).
duke@0 1257 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
duke@0 1258
duke@0 1259 // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result
duke@0 1260 __ pop(ltos);
never@307 1261 __ movptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize));
duke@0 1262 __ call(t);
duke@0 1263
duke@0 1264 // remove activation
never@307 1265 __ movptr(t, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
duke@0 1266 __ leave(); // remove frame anchor
never@307 1267 __ pop(rdi); // get return address
never@307 1268 __ mov(rsp, t); // set sp to sender sp
duke@0 1269 __ jmp(rdi);
duke@0 1270
duke@0 1271 if (inc_counter) {
duke@0 1272 // Handle overflow of counter and compile method
duke@0 1273 __ bind(invocation_counter_overflow);
duke@0 1274 generate_counter_overflow(&continue_after_compile);
duke@0 1275 }
duke@0 1276
duke@0 1277 return entry_point;
duke@0 1278 }
duke@0 1279
duke@0 1280 //
duke@0 1281 // Generic interpreted method entry to (asm) interpreter
duke@0 1282 //
duke@0 1283 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
duke@0 1284 // determine code generation flags
duke@0 1285 bool inc_counter = UseCompiler || CountCompiledCalls;
duke@0 1286
duke@0 1287 // rbx,: methodOop
duke@0 1288 // rsi: sender sp
duke@0 1289 address entry_point = __ pc();
duke@0 1290
duke@0 1291
duke@0 1292 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
duke@0 1293 const Address size_of_locals (rbx, methodOopDesc::size_of_locals_offset());
duke@0 1294 const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
duke@0 1295 const Address access_flags (rbx, methodOopDesc::access_flags_offset());
duke@0 1296
duke@0 1297 // get parameter size (always needed)
jrose@660 1298 __ load_unsigned_short(rcx, size_of_parameters);
duke@0 1299
duke@0 1300 // rbx,: methodOop
duke@0 1301 // rcx: size of parameters
duke@0 1302
duke@0 1303 // rsi: sender_sp (could differ from sp+wordSize if we were called via c2i )
duke@0 1304
jrose@660 1305 __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
duke@0 1306 __ subl(rdx, rcx); // rdx = no. of additional locals
duke@0 1307
duke@0 1308 // see if we've got enough room on the stack for locals plus overhead.
duke@0 1309 generate_stack_overflow_check();
duke@0 1310
duke@0 1311 // get return address
never@307 1312 __ pop(rax);
duke@0 1313
duke@0 1314 // compute beginning of parameters (rdi)
never@307 1315 __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
duke@0 1316
duke@0 1317 // rdx - # of additional locals
duke@0 1318 // allocate space for locals
duke@0 1319 // explicitly initialize locals
duke@0 1320 {
duke@0 1321 Label exit, loop;
duke@0 1322 __ testl(rdx, rdx);
duke@0 1323 __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
duke@0 1324 __ bind(loop);
never@307 1325 __ push((int32_t)NULL_WORD); // initialize local variables
duke@0 1326 __ decrement(rdx); // until everything initialized
duke@0 1327 __ jcc(Assembler::greater, loop);
duke@0 1328 __ bind(exit);
duke@0 1329 }
duke@0 1330
duke@0 1331 if (inc_counter) __ movl(rcx, invocation_counter); // (pre-)fetch invocation count
duke@0 1332 // initialize fixed part of activation frame
duke@0 1333 generate_fixed_frame(false);
duke@0 1334
duke@0 1335 // make sure method is not native & not abstract
duke@0 1336 #ifdef ASSERT
duke@0 1337 __ movl(rax, access_flags);
duke@0 1338 {
duke@0 1339 Label L;
duke@0 1340 __ testl(rax, JVM_ACC_NATIVE);
duke@0 1341 __ jcc(Assembler::zero, L);
duke@0 1342 __ stop("tried to execute native method as non-native");
duke@0 1343 __ bind(L);
duke@0 1344 }
duke@0 1345 { Label L;
duke@0 1346 __ testl(rax, JVM_ACC_ABSTRACT);
duke@0 1347 __ jcc(Assembler::zero, L);
duke@0 1348 __ stop("tried to execute abstract method in interpreter");
duke@0 1349 __ bind(L);
duke@0 1350 }
duke@0 1351 #endif
duke@0 1352
duke@0 1353 // Since at this point in the method invocation the exception handler
duke@0 1354 // would try to exit the monitor of synchronized methods which hasn't
duke@0 1355 // been entered yet, we set the thread local variable
duke@0 1356 // _do_not_unlock_if_synchronized to true. The remove_activation will
duke@0 1357 // check this flag.
duke@0 1358
duke@0 1359 __ get_thread(rax);
duke@0 1360 const Address do_not_unlock_if_synchronized(rax,
duke@0 1361 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
duke@0 1362 __ movbool(do_not_unlock_if_synchronized, true);
duke@0 1363
duke@0 1364 // increment invocation count & check for overflow
duke@0 1365 Label invocation_counter_overflow;
duke@0 1366 Label profile_method;
duke@0 1367 Label profile_method_continue;
duke@0 1368 if (inc_counter) {
duke@0 1369 generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue);
duke@0 1370 if (ProfileInterpreter) {
duke@0 1371 __ bind(profile_method_continue);
duke@0 1372 }
duke@0 1373 }
duke@0 1374 Label continue_after_compile;
duke@0 1375 __ bind(continue_after_compile);
duke@0 1376
duke@0 1377 bang_stack_shadow_pages(false);
duke@0 1378
duke@0 1379 // reset the _do_not_unlock_if_synchronized flag
duke@0 1380 __ get_thread(rax);
duke@0 1381 __ movbool(do_not_unlock_if_synchronized, false);
duke@0 1382
duke@0 1383 // check for synchronized methods
duke@0 1384 // Must happen AFTER invocation_counter check and stack overflow check,
duke@0 1385 // so method is not locked if overflows.
duke@0 1386 //
duke@0 1387 if (synchronized) {
duke@0 1388 // Allocate monitor and lock method
duke@0 1389 lock_method();
duke@0 1390 } else {
duke@0 1391 // no synchronization necessary
duke@0 1392 #ifdef ASSERT
duke@0 1393 { Label L;
duke@0 1394 __ movl(rax, access_flags);
duke@0 1395 __ testl(rax, JVM_ACC_SYNCHRONIZED);
duke@0 1396 __ jcc(Assembler::zero, L);
duke@0 1397 __ stop("method needs synchronization");
duke@0 1398 __ bind(L);
duke@0 1399 }
duke@0 1400 #endif
duke@0 1401 }
duke@0 1402
duke@0 1403 // start execution
duke@0 1404 #ifdef ASSERT
duke@0 1405 { Label L;
duke@0 1406 const Address monitor_block_top (rbp,
duke@0 1407 frame::interpreter_frame_monitor_block_top_offset * wordSize);
never@307 1408 __ movptr(rax, monitor_block_top);
never@307 1409 __ cmpptr(rax, rsp);
duke@0 1410 __ jcc(Assembler::equal, L);
duke@0 1411 __ stop("broken stack frame setup in interpreter");
duke@0 1412 __ bind(L);
duke@0 1413 }
duke@0 1414 #endif
duke@0 1415
duke@0 1416 // jvmti support
duke@0 1417 __ notify_method_entry();
duke@0 1418
duke@0 1419 __ dispatch_next(vtos);
duke@0 1420
duke@0 1421 // invocation counter overflow
duke@0 1422 if (inc_counter) {
duke@0 1423 if (ProfileInterpreter) {
duke@0 1424 // We have decided to profile this method in the interpreter
duke@0 1425 __ bind(profile_method);
iveresov@2131 1426 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
iveresov@2131 1427 __ set_method_data_pointer_for_bcp();
iveresov@2154 1428 __ get_method(rbx);
duke@0 1429 __ jmp(profile_method_continue);
duke@0 1430 }
duke@0 1431 // Handle overflow of counter and compile method
duke@0 1432 __ bind(invocation_counter_overflow);
duke@0 1433 generate_counter_overflow(&continue_after_compile);
duke@0 1434 }
duke@0 1435
duke@0 1436 return entry_point;
duke@0 1437 }
duke@0 1438
duke@0 1439 //------------------------------------------------------------------------------------------------------------------------
duke@0 1440 // Entry points
duke@0 1441 //
duke@0 1442 // Here we generate the various kind of entries into the interpreter.
duke@0 1443 // The two main entry type are generic bytecode methods and native call method.
duke@0 1444 // These both come in synchronized and non-synchronized versions but the
duke@0 1445 // frame layout they create is very similar. The other method entry
duke@0 1446 // types are really just special purpose entries that are really entry
duke@0 1447 // and interpretation all in one. These are for trivial methods like
duke@0 1448 // accessor, empty, or special math methods.
duke@0 1449 //
duke@0 1450 // When control flow reaches any of the entry types for the interpreter
duke@0 1451 // the following holds ->
duke@0 1452 //
duke@0 1453 // Arguments:
duke@0 1454 //
duke@0 1455 // rbx,: methodOop
duke@0 1456 // rcx: receiver
duke@0 1457 //
duke@0 1458 //
duke@0 1459 // Stack layout immediately at entry
duke@0 1460 //
duke@0 1461 // [ return address ] <--- rsp
duke@0 1462 // [ parameter n ]
duke@0 1463 // ...
duke@0 1464 // [ parameter 1 ]
duke@0 1465 // [ expression stack ] (caller's java expression stack)
duke@0 1466
duke@0 1467 // Assuming that we don't go to one of the trivial specialized
duke@0 1468 // entries the stack will look like below when we are ready to execute
duke@0 1469 // the first bytecode (or call the native routine). The register usage
duke@0 1470 // will be as the template based interpreter expects (see interpreter_x86.hpp).
duke@0 1471 //
duke@0 1472 // local variables follow incoming parameters immediately; i.e.
duke@0 1473 // the return address is moved to the end of the locals).
duke@0 1474 //
duke@0 1475 // [ monitor entry ] <--- rsp
duke@0 1476 // ...
duke@0 1477 // [ monitor entry ]
duke@0 1478 // [ expr. stack bottom ]
duke@0 1479 // [ saved rsi ]
duke@0 1480 // [ current rdi ]
duke@0 1481 // [ methodOop ]
duke@0 1482 // [ saved rbp, ] <--- rbp,
duke@0 1483 // [ return address ]
duke@0 1484 // [ local variable m ]
duke@0 1485 // ...
duke@0 1486 // [ local variable 1 ]
duke@0 1487 // [ parameter n ]
duke@0 1488 // ...
duke@0 1489 // [ parameter 1 ] <--- rdi
duke@0 1490
duke@0 1491 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
duke@0 1492 // determine code generation flags
duke@0 1493 bool synchronized = false;
duke@0 1494 address entry_point = NULL;
duke@0 1495
duke@0 1496 switch (kind) {
duke@0 1497 case Interpreter::zerolocals : break;
duke@0 1498 case Interpreter::zerolocals_synchronized: synchronized = true; break;
duke@0 1499 case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
duke@0 1500 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
duke@0 1501 case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
duke@0 1502 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
duke@0 1503 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
jrose@748 1504 case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
duke@0 1505
duke@0 1506 case Interpreter::java_lang_math_sin : // fall thru
duke@0 1507 case Interpreter::java_lang_math_cos : // fall thru
duke@0 1508 case Interpreter::java_lang_math_tan : // fall thru
duke@0 1509 case Interpreter::java_lang_math_abs : // fall thru
duke@0 1510 case Interpreter::java_lang_math_log : // fall thru
duke@0 1511 case Interpreter::java_lang_math_log10 : // fall thru
duke@0 1512 case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
johnc@2488 1513 case Interpreter::java_lang_ref_reference_get
johnc@2488 1514 : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
duke@0 1515 default : ShouldNotReachHere(); break;
duke@0 1516 }
duke@0 1517
duke@0 1518 if (entry_point) return entry_point;
duke@0 1519
duke@0 1520 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
duke@0 1521
duke@0 1522 }
duke@0 1523
never@1252 1524 // These should never be compiled since the interpreter will prefer
never@1252 1525 // the compiled version to the intrinsic version.
never@1252 1526 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
never@1252 1527 switch (method_kind(m)) {
never@1252 1528 case Interpreter::java_lang_math_sin : // fall thru
never@1252 1529 case Interpreter::java_lang_math_cos : // fall thru
never@1252 1530 case Interpreter::java_lang_math_tan : // fall thru
never@1252 1531 case Interpreter::java_lang_math_abs : // fall thru
never@1252 1532 case Interpreter::java_lang_math_log : // fall thru
never@1252 1533 case Interpreter::java_lang_math_log10 : // fall thru
never@1252 1534 case Interpreter::java_lang_math_sqrt :
never@1252 1535 return false;
never@1252 1536 default:
never@1252 1537 return true;
never@1252 1538 }
never@1252 1539 }
never@1252 1540
duke@0 1541 // How much stack a method activation needs in words.
duke@0 1542 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
duke@0 1543
duke@0 1544 const int stub_code = 4; // see generate_call_stub
duke@0 1545 // Save space for one monitor to get into the interpreted method in case
duke@0 1546 // the method is synchronized
duke@0 1547 int monitor_size = method->is_synchronized() ?
duke@0 1548 1*frame::interpreter_frame_monitor_size() : 0;
duke@0 1549
duke@0 1550 // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
duke@0 1551 // be sure to change this if you add/subtract anything to/from the overhead area
duke@0 1552 const int overhead_size = -frame::interpreter_frame_initial_sp_offset;
duke@0 1553
jrose@748 1554 const int extra_stack = methodOopDesc::extra_stack_entries();
jrose@748 1555 const int method_stack = (method->max_locals() + method->max_stack() + extra_stack) *
twisti@1517 1556 Interpreter::stackElementWords;
duke@0 1557 return overhead_size + method_stack + stub_code;
duke@0 1558 }
duke@0 1559
duke@0 1560 // asm based interpreter deoptimization helpers
duke@0 1561
duke@0 1562 int AbstractInterpreter::layout_activation(methodOop method,
duke@0 1563 int tempcount,
duke@0 1564 int popframe_extra_args,
duke@0 1565 int moncount,
never@2613 1566 int caller_actual_parameters,
duke@0 1567 int callee_param_count,
duke@0 1568 int callee_locals,
duke@0 1569 frame* caller,
duke@0 1570 frame* interpreter_frame,
duke@0 1571 bool is_top_frame) {
duke@0 1572 // Note: This calculation must exactly parallel the frame setup
duke@0 1573 // in AbstractInterpreterGenerator::generate_method_entry.
duke@0 1574 // If interpreter_frame!=NULL, set up the method, locals, and monitors.
duke@0 1575 // The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
duke@0 1576 // as determined by a previous call to this method.
duke@0 1577 // It is also guaranteed to be walkable even though it is in a skeletal state
duke@0 1578 // NOTE: return size is in words not bytes
duke@0 1579
duke@0 1580 // fixed size of an interpreter frame:
twisti@1517 1581 int max_locals = method->max_locals() * Interpreter::stackElementWords;
duke@0 1582 int extra_locals = (method->max_locals() - method->size_of_parameters()) *
twisti@1517 1583 Interpreter::stackElementWords;
duke@0 1584
duke@0 1585 int overhead = frame::sender_sp_offset - frame::interpreter_frame_initial_sp_offset;
duke@0 1586
duke@0 1587 // Our locals were accounted for by the caller (or last_frame_adjust on the transistion)
duke@0 1588 // Since the callee parameters already account for the callee's params we only need to account for
duke@0 1589 // the extra locals.
duke@0 1590
duke@0 1591
duke@0 1592 int size = overhead +
twisti@1517 1593 ((callee_locals - callee_param_count)*Interpreter::stackElementWords) +
duke@0 1594 (moncount*frame::interpreter_frame_monitor_size()) +
twisti@1517 1595 tempcount*Interpreter::stackElementWords + popframe_extra_args;
duke@0 1596
duke@0 1597 if (interpreter_frame != NULL) {
duke@0 1598 #ifdef ASSERT
twisti@2398 1599 if (!EnableInvokeDynamic)
twisti@1212 1600 // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
twisti@1212 1601 // Probably, since deoptimization doesn't work yet.
twisti@1212 1602 assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
duke@0 1603 assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable(2)");
duke@0 1604 #endif
duke@0 1605
duke@0 1606 interpreter_frame->interpreter_frame_set_method(method);
duke@0 1607 // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
duke@0 1608 // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
duke@0 1609 // and sender_sp is fp+8
duke@0 1610 intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
duke@0 1611
duke@0 1612 interpreter_frame->interpreter_frame_set_locals(locals);
duke@0 1613 BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
duke@0 1614 BasicObjectLock* monbot = montop - moncount;
duke@0 1615 interpreter_frame->interpreter_frame_set_monitor_end(monbot);
duke@0 1616
duke@0 1617 // Set last_sp
duke@0 1618 intptr_t* rsp = (intptr_t*) monbot -
twisti@1517 1619 tempcount*Interpreter::stackElementWords -
duke@0 1620 popframe_extra_args;
duke@0 1621 interpreter_frame->interpreter_frame_set_last_sp(rsp);
duke@0 1622
duke@0 1623 // All frames but the initial (oldest) interpreter frame we fill in have a
duke@0 1624 // value for sender_sp that allows walking the stack but isn't
duke@0 1625 // truly correct. Correct the value here.
duke@0 1626
duke@0 1627 if (extra_locals != 0 &&
duke@0 1628 interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
duke@0 1629 interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
duke@0 1630 }
duke@0 1631 *interpreter_frame->interpreter_frame_cache_addr() =
duke@0 1632 method->constants()->cache();
duke@0 1633 }
duke@0 1634 return size;
duke@0 1635 }
duke@0 1636
duke@0 1637
duke@0 1638 //------------------------------------------------------------------------------------------------------------------------
duke@0 1639 // Exceptions
duke@0 1640
duke@0 1641 void TemplateInterpreterGenerator::generate_throw_exception() {
duke@0 1642 // Entry point in previous activation (i.e., if the caller was interpreted)
duke@0 1643 Interpreter::_rethrow_exception_entry = __ pc();
twisti@1382 1644 const Register thread = rcx;
duke@0 1645
duke@0 1646 // Restore sp to interpreter_frame_last_sp even though we are going
duke@0 1647 // to empty the expression stack for the exception processing.
xlu@520 1648 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 1649 // rax,: exception
duke@0 1650 // rdx: return address/pc that threw exception
duke@0 1651 __ restore_bcp(); // rsi points to call/send
duke@0 1652 __ restore_locals();
duke@0 1653
duke@0 1654 // Entry point for exceptions thrown within interpreter code
duke@0 1655 Interpreter::_throw_exception_entry = __ pc();
duke@0 1656 // expression stack is undefined here
duke@0 1657 // rax,: exception
duke@0 1658 // rsi: exception bcp
duke@0 1659 __ verify_oop(rax);
duke@0 1660
duke@0 1661 // expression stack must be empty before entering the VM in case of an exception
duke@0 1662 __ empty_expression_stack();
duke@0 1663 __ empty_FPU_stack();
duke@0 1664 // find exception handler address and preserve exception oop
duke@0 1665 __ call_VM(rdx, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), rax);
duke@0 1666 // rax,: exception handler entry point
duke@0 1667 // rdx: preserved exception oop
duke@0 1668 // rsi: bcp for exception handler
duke@0 1669 __ push_ptr(rdx); // push exception which is now the only value on the stack
duke@0 1670 __ jmp(rax); // jump to exception handler (may be _remove_activation_entry!)
duke@0 1671
duke@0 1672 // If the exception is not handled in the current frame the frame is removed and
duke@0 1673 // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
duke@0 1674 //
duke@0 1675 // Note: At this point the bci is still the bxi for the instruction which caused
duke@0 1676 // the exception and the expression stack is empty. Thus, for any VM calls
duke@0 1677 // at this point, GC will find a legal oop map (with empty expression stack).
duke@0 1678
duke@0 1679 // In current activation
duke@0 1680 // tos: exception
duke@0 1681 // rsi: exception bcp
duke@0 1682
duke@0 1683 //
duke@0 1684 // JVMTI PopFrame support
duke@0 1685 //
duke@0 1686
duke@0 1687 Interpreter::_remove_activation_preserving_args_entry = __ pc();
duke@0 1688 __ empty_expression_stack();
duke@0 1689 __ empty_FPU_stack();
duke@0 1690 // Set the popframe_processing bit in pending_popframe_condition indicating that we are
duke@0 1691 // currently handling popframe, so that call_VMs that may happen later do not trigger new
duke@0 1692 // popframe handling cycles.
twisti@1382 1693 __ get_thread(thread);
twisti@1382 1694 __ movl(rdx, Address(thread, JavaThread::popframe_condition_offset()));
duke@0 1695 __ orl(rdx, JavaThread::popframe_processing_bit);
twisti@1382 1696 __ movl(Address(thread, JavaThread::popframe_condition_offset()), rdx);
duke@0 1697
duke@0 1698 {
duke@0 1699 // Check to see whether we are returning to a deoptimized frame.
duke@0 1700 // (The PopFrame call ensures that the caller of the popped frame is
duke@0 1701 // either interpreted or compiled and deoptimizes it if compiled.)
duke@0 1702 // In this case, we can't call dispatch_next() after the frame is
duke@0 1703 // popped, but instead must save the incoming arguments and restore
duke@0 1704 // them after deoptimization has occurred.
duke@0 1705 //
duke@0 1706 // Note that we don't compare the return PC against the
duke@0 1707 // deoptimization blob's unpack entry because of the presence of
duke@0 1708 // adapter frames in C2.
duke@0 1709 Label caller_not_deoptimized;
never@307 1710 __ movptr(rdx, Address(rbp, frame::return_addr_offset * wordSize));
duke@0 1711 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), rdx);
duke@0 1712 __ testl(rax, rax);
duke@0 1713 __ jcc(Assembler::notZero, caller_not_deoptimized);
duke@0 1714
duke@0 1715 // Compute size of arguments for saving when returning to deoptimized caller
duke@0 1716 __ get_method(rax);
duke@0 1717 __ verify_oop(rax);
jrose@660 1718 __ load_unsigned_short(rax, Address(rax, in_bytes(methodOopDesc::size_of_parameters_offset())));
twisti@1517 1719 __ shlptr(rax, Interpreter::logStackElementSize);
duke@0 1720 __ restore_locals();
never@307 1721 __ subptr(rdi, rax);
never@307 1722 __ addptr(rdi, wordSize);
duke@0 1723 // Save these arguments
twisti@1382 1724 __ get_thread(thread);
twisti@1382 1725 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), thread, rax, rdi);
duke@0 1726
duke@0 1727 __ remove_activation(vtos, rdx,
duke@0 1728 /* throw_monitor_exception */ false,
duke@0 1729 /* install_monitor_exception */ false,
duke@0 1730 /* notify_jvmdi */ false);
duke@0 1731
duke@0 1732 // Inform deoptimization that it is responsible for restoring these arguments
twisti@1382 1733 __ get_thread(thread);
twisti@1382 1734 __ movl(Address(thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_force_deopt_reexecution_bit);
duke@0 1735
duke@0 1736 // Continue in deoptimization handler
duke@0 1737 __ jmp(rdx);
duke@0 1738
duke@0 1739 __ bind(caller_not_deoptimized);
duke@0 1740 }
duke@0 1741
duke@0 1742 __ remove_activation(vtos, rdx,
duke@0 1743 /* throw_monitor_exception */ false,
duke@0 1744 /* install_monitor_exception */ false,
duke@0 1745 /* notify_jvmdi */ false);
duke@0 1746
duke@0 1747 // Finish with popframe handling
duke@0 1748 // A previous I2C followed by a deoptimization might have moved the
duke@0 1749 // outgoing arguments further up the stack. PopFrame expects the
duke@0 1750 // mutations to those outgoing arguments to be preserved and other
duke@0 1751 // constraints basically require this frame to look exactly as
duke@0 1752 // though it had previously invoked an interpreted activation with
duke@0 1753 // no space between the top of the expression stack (current
duke@0 1754 // last_sp) and the top of stack. Rather than force deopt to
duke@0 1755 // maintain this kind of invariant all the time we call a small
duke@0 1756 // fixup routine to move the mutated arguments onto the top of our
duke@0 1757 // expression stack if necessary.
never@307 1758 __ mov(rax, rsp);
never@307 1759 __ movptr(rbx, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
twisti@1382 1760 __ get_thread(thread);
duke@0 1761 // PC must point into interpreter here
twisti@1382 1762 __ set_last_Java_frame(thread, noreg, rbp, __ pc());
twisti@1382 1763 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, rax, rbx);
twisti@1382 1764 __ get_thread(thread);
twisti@1382 1765 __ reset_last_Java_frame(thread, true, true);
duke@0 1766 // Restore the last_sp and null it out
never@307 1767 __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
xlu@520 1768 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 1769
duke@0 1770 __ restore_bcp();
duke@0 1771 __ restore_locals();
duke@0 1772 // The method data pointer was incremented already during
duke@0 1773 // call profiling. We have to restore the mdp for the current bcp.
duke@0 1774 if (ProfileInterpreter) {
duke@0 1775 __ set_method_data_pointer_for_bcp();
duke@0 1776 }
duke@0 1777
duke@0 1778 // Clear the popframe condition flag
twisti@1382 1779 __ get_thread(thread);
twisti@1382 1780 __ movl(Address(thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_inactive);
duke@0 1781
duke@0 1782 __ dispatch_next(vtos);
duke@0 1783 // end of PopFrame support
duke@0 1784
duke@0 1785 Interpreter::_remove_activation_entry = __ pc();
duke@0 1786
duke@0 1787 // preserve exception over this code sequence
duke@0 1788 __ pop_ptr(rax);
twisti@1382 1789 __ get_thread(thread);
twisti@1382 1790 __ movptr(Address(thread, JavaThread::vm_result_offset()), rax);
duke@0 1791 // remove the activation (without doing throws on illegalMonitorExceptions)
duke@0 1792 __ remove_activation(vtos, rdx, false, true, false);
duke@0 1793 // restore exception
twisti@1382 1794 __ get_thread(thread);
twisti@1382 1795 __ movptr(rax, Address(thread, JavaThread::vm_result_offset()));
twisti@1382 1796 __ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
duke@0 1797 __ verify_oop(rax);
duke@0 1798
duke@0 1799 // Inbetween activations - previous activation type unknown yet
duke@0 1800 // compute continuation point - the continuation point expects
duke@0 1801 // the following registers set up:
duke@0 1802 //
twisti@1382 1803 // rax: exception
duke@0 1804 // rdx: return address/pc that threw exception
duke@0 1805 // rsp: expression stack of caller
twisti@1382 1806 // rbp: rbp, of caller
never@307 1807 __ push(rax); // save exception
never@307 1808 __ push(rdx); // save return address
twisti@1382 1809 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, rdx);
never@307 1810 __ mov(rbx, rax); // save exception handler
never@307 1811 __ pop(rdx); // restore return address
never@307 1812 __ pop(rax); // restore exception
duke@0 1813 // Note that an "issuing PC" is actually the next PC after the call
duke@0 1814 __ jmp(rbx); // jump to exception handler of caller
duke@0 1815 }
duke@0 1816
duke@0 1817
duke@0 1818 //
duke@0 1819 // JVMTI ForceEarlyReturn support
duke@0 1820 //
duke@0 1821 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
duke@0 1822 address entry = __ pc();
twisti@1382 1823 const Register thread = rcx;
duke@0 1824
duke@0 1825 __ restore_bcp();
duke@0 1826 __ restore_locals();
duke@0 1827 __ empty_expression_stack();
duke@0 1828 __ empty_FPU_stack();
duke@0 1829 __ load_earlyret_value(state);
duke@0 1830
twisti@1382 1831 __ get_thread(thread);
twisti@1382 1832 __ movptr(rcx, Address(thread, JavaThread::jvmti_thread_state_offset()));
duke@0 1833 const Address cond_addr(rcx, JvmtiThreadState::earlyret_state_offset());
duke@0 1834
duke@0 1835 // Clear the earlyret state
duke@0 1836 __ movl(cond_addr, JvmtiThreadState::earlyret_inactive);
duke@0 1837
duke@0 1838 __ remove_activation(state, rsi,
duke@0 1839 false, /* throw_monitor_exception */
duke@0 1840 false, /* install_monitor_exception */
duke@0 1841 true); /* notify_jvmdi */
duke@0 1842 __ jmp(rsi);
duke@0 1843 return entry;
duke@0 1844 } // end of ForceEarlyReturn support
duke@0 1845
duke@0 1846
duke@0 1847 //------------------------------------------------------------------------------------------------------------------------
duke@0 1848 // Helper for vtos entry point generation
duke@0 1849
duke@0 1850 void TemplateInterpreterGenerator::set_vtos_entry_points (Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
duke@0 1851 assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
duke@0 1852 Label L;
duke@0 1853 fep = __ pc(); __ push(ftos); __ jmp(L);
duke@0 1854 dep = __ pc(); __ push(dtos); __ jmp(L);
duke@0 1855 lep = __ pc(); __ push(ltos); __ jmp(L);
duke@0 1856 aep = __ pc(); __ push(atos); __ jmp(L);
duke@0 1857 bep = cep = sep = // fall through
duke@0 1858 iep = __ pc(); __ push(itos); // fall through
duke@0 1859 vep = __ pc(); __ bind(L); // fall through
duke@0 1860 generate_and_dispatch(t);
duke@0 1861 }
duke@0 1862
duke@0 1863 //------------------------------------------------------------------------------------------------------------------------
duke@0 1864 // Generation of individual instructions
duke@0 1865
duke@0 1866 // helpers for generate_and_dispatch
duke@0 1867
duke@0 1868
duke@0 1869
duke@0 1870 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
duke@0 1871 : TemplateInterpreterGenerator(code) {
duke@0 1872 generate_all(); // down here so it can be "virtual"
duke@0 1873 }
duke@0 1874
duke@0 1875 //------------------------------------------------------------------------------------------------------------------------
duke@0 1876
duke@0 1877 // Non-product code
duke@0 1878 #ifndef PRODUCT
duke@0 1879 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
duke@0 1880 address entry = __ pc();
duke@0 1881
duke@0 1882 // prepare expression stack
never@307 1883 __ pop(rcx); // pop return address so expression stack is 'pure'
duke@0 1884 __ push(state); // save tosca
duke@0 1885
duke@0 1886 // pass tosca registers as arguments & call tracer
duke@0 1887 __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), rcx, rax, rdx);
never@307 1888 __ mov(rcx, rax); // make sure return address is not destroyed by pop(state)
duke@0 1889 __ pop(state); // restore tosca
duke@0 1890
duke@0 1891 // return
duke@0 1892 __ jmp(rcx);
duke@0 1893
duke@0 1894 return entry;
duke@0 1895 }
duke@0 1896
duke@0 1897
duke@0 1898 void TemplateInterpreterGenerator::count_bytecode() {
never@307 1899 __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value));
duke@0 1900 }
duke@0 1901
duke@0 1902
duke@0 1903 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
never@307 1904 __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()]));
duke@0 1905 }
duke@0 1906
duke@0 1907
duke@0 1908 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
duke@0 1909 __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx);
duke@0 1910 __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes);
duke@0 1911 __ orl(rbx, ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
duke@0 1912 ExternalAddress table((address) BytecodePairHistogram::_counters);
duke@0 1913 Address index(noreg, rbx, Address::times_4);
never@307 1914 __ incrementl(ArrayAddress(table, index));
duke@0 1915 }
duke@0 1916
duke@0 1917
duke@0 1918 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
duke@0 1919 // Call a little run-time stub to avoid blow-up for each bytecode.
duke@0 1920 // The run-time runtime saves the right registers, depending on
duke@0 1921 // the tosca in-state for the given template.
duke@0 1922 assert(Interpreter::trace_code(t->tos_in()) != NULL,
duke@0 1923 "entry must have been generated");
duke@0 1924 __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
duke@0 1925 }
duke@0 1926
duke@0 1927
duke@0 1928 void TemplateInterpreterGenerator::stop_interpreter_at() {
duke@0 1929 Label L;
duke@0 1930 __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value),
duke@0 1931 StopInterpreterAt);
duke@0 1932 __ jcc(Assembler::notEqual, L);
duke@0 1933 __ int3();
duke@0 1934 __ bind(L);
duke@0 1935 }
duke@0 1936 #endif // !PRODUCT
duke@0 1937 #endif // CC_INTERP