src/cpu/x86/vm/templateInterpreter_x86_64.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
permissions
-rw-r--r--

Initial load

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

mercurial