src/cpu/x86/vm/templateInterpreter_x86_32.cpp

Tue, 21 Apr 2009 23:21:04 -0700

author
jrose
date
Tue, 21 Apr 2009 23:21:04 -0700
changeset 1161
be93aad57795
parent 1145
e5b0439ef4ae
child 1474
987e948ebbc8
permissions
-rw-r--r--

6655646: dynamic languages need dynamically linked call sites
Summary: invokedynamic instruction (JSR 292 RI)
Reviewed-by: twisti, never

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

mercurial