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