src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff src/hotspot/cpu/arm

src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp

Print this page




  48 #include "runtime/vframeArray.hpp"
  49 #include "utilities/align.hpp"
  50 #include "utilities/debug.hpp"
  51 #include "utilities/macros.hpp"
  52 
  53 // Size of interpreter code.  Increase if too small.  Interpreter will
  54 // fail with a guarantee ("not enough space for interpreter generation");
  55 // if too small.
  56 // Run with +PrintInterpreter to get the VM to print out the size.
  57 // Max size with JVMTI
  58 int TemplateInterpreter::InterpreterCodeSize = 180 * 1024;
  59 
  60 #define __ _masm->
  61 
  62 //------------------------------------------------------------------------------------------------------------------------
  63 
  64 address TemplateInterpreterGenerator::generate_slow_signature_handler() {
  65   address entry = __ pc();
  66 
  67   // callee-save register for saving LR, shared with generate_native_entry
  68   const Register Rsaved_ret_addr = AARCH64_ONLY(R21) NOT_AARCH64(Rtmp_save0);
  69 
  70   __ mov(Rsaved_ret_addr, LR);
  71 
  72   __ mov(R1, Rmethod);
  73   __ mov(R2, Rlocals);
  74   __ mov(R3, SP);
  75 
  76 #ifdef AARCH64
  77   // expand expr. stack and extended SP to avoid cutting SP in call_VM
  78   __ mov(Rstack_top, SP);
  79   __ str(Rstack_top, Address(FP, frame::interpreter_frame_extended_sp_offset * wordSize));
  80   __ check_stack_top();
  81 
  82   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), R1, R2, R3, false);
  83 
  84   __ ldp(ZR,      c_rarg1, Address(SP, 2*wordSize, post_indexed));
  85   __ ldp(c_rarg2, c_rarg3, Address(SP, 2*wordSize, post_indexed));
  86   __ ldp(c_rarg4, c_rarg5, Address(SP, 2*wordSize, post_indexed));
  87   __ ldp(c_rarg6, c_rarg7, Address(SP, 2*wordSize, post_indexed));
  88 
  89   __ ldp_d(V0, V1, Address(SP, 2*wordSize, post_indexed));
  90   __ ldp_d(V2, V3, Address(SP, 2*wordSize, post_indexed));
  91   __ ldp_d(V4, V5, Address(SP, 2*wordSize, post_indexed));
  92   __ ldp_d(V6, V7, Address(SP, 2*wordSize, post_indexed));
  93 #else
  94 
  95   // Safer to save R9 (when scratched) since callers may have been
  96   // written assuming R9 survives. This is suboptimal but
  97   // probably not important for this slow case call site.
  98   // Note for R9 saving: slow_signature_handler may copy register
  99   // arguments above the current SP (passed as R3). It is safe for
 100   // call_VM to use push and pop to protect additional values on the
 101   // stack if needed.
 102   __ call_VM(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), true /* save R9 if needed*/);
 103   __ add(SP, SP, wordSize);     // Skip R0
 104   __ pop(RegisterSet(R1, R3));  // Load arguments passed in registers
 105 #ifdef __ABI_HARD__
 106   // Few alternatives to an always-load-FP-registers approach:
 107   // - parse method signature to detect FP arguments
 108   // - keep a counter/flag on a stack indicationg number of FP arguments in the method.
 109   // The later has been originally implemented and tested but a conditional path could
 110   // eliminate any gain imposed by avoiding 8 double word loads.
 111   __ fldmiad(SP, FloatRegisterSet(D0, 8), writeback);
 112 #endif // __ABI_HARD__
 113 #endif // AARCH64
 114 
 115   __ ret(Rsaved_ret_addr);
 116 
 117   return entry;
 118 }
 119 
 120 
 121 //
 122 // Various method entries (that c++ and asm interpreter agree upon)
 123 //------------------------------------------------------------------------------------------------------------------------
 124 //
 125 //
 126 
 127 // Abstract method entry
 128 // Attempt to execute abstract method. Throw exception
 129 address TemplateInterpreterGenerator::generate_abstract_entry(void) {
 130   address entry_point = __ pc();
 131 
 132 #ifdef AARCH64
 133   __ restore_sp_after_call(Rtemp);
 134   __ restore_stack_top();
 135 #endif
 136 
 137   __ empty_expression_stack();
 138 
 139   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
 140 
 141   DEBUG_ONLY(STOP("generate_abstract_entry");) // Should not reach here
 142   return entry_point;
 143 }
 144 
 145 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
 146   if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
 147 
 148   // TODO: ARM
 149   return NULL;
 150 
 151   address entry_point = __ pc();
 152   STOP("generate_math_entry");
 153   return entry_point;
 154 }
 155 


 257   }
 258 
 259   // throw exception
 260   __ b(Interpreter::throw_exception_entry());
 261 
 262   __ nop(); // to avoid filling CPU pipeline with invalid instructions
 263   __ nop();
 264   __ bind_literal(Lname);
 265   if (!pass_oop && (message != NULL)) {
 266     __ bind_literal(Lmessage);
 267   }
 268 
 269   return entry;
 270 }
 271 
 272 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
 273   address entry = __ pc();
 274 
 275   __ interp_verify_oop(R0_tos, state, __FILE__, __LINE__);
 276 
 277 #ifdef AARCH64
 278   __ restore_sp_after_call(Rtemp);  // Restore SP to extended SP
 279   __ restore_stack_top();
 280 #else
 281   // Restore stack bottom in case i2c adjusted stack
 282   __ ldr(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
 283   // and NULL it as marker that SP is now tos until next java call
 284   __ mov(Rtemp, (int)NULL_WORD);
 285   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
 286 #endif // AARCH64
 287 
 288   __ restore_method();
 289   __ restore_bcp();
 290   __ restore_dispatch();
 291   __ restore_locals();
 292 
 293   const Register Rcache = R2_tmp;
 294   const Register Rindex = R3_tmp;
 295   __ get_cache_and_index_at_bcp(Rcache, Rindex, 1, index_size);
 296 
 297   __ add(Rtemp, Rcache, AsmOperand(Rindex, lsl, LogBytesPerWord));
 298   __ ldrb(Rtemp, Address(Rtemp, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
 299   __ check_stack_top();
 300   __ add(Rstack_top, Rstack_top, AsmOperand(Rtemp, lsl, Interpreter::logStackElementSize));
 301 
 302 #ifndef AARCH64
 303   __ convert_retval_to_tos(state);
 304 #endif // !AARCH64
 305 
 306  __ check_and_handle_popframe();
 307  __ check_and_handle_earlyret();
 308 
 309   __ dispatch_next(state, step);
 310 
 311   return entry;
 312 }
 313 
 314 
 315 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) {
 316   address entry = __ pc();
 317 
 318   __ interp_verify_oop(R0_tos, state, __FILE__, __LINE__);
 319 
 320 #ifdef AARCH64
 321   __ restore_sp_after_call(Rtemp);  // Restore SP to extended SP
 322   __ restore_stack_top();
 323 #else
 324   // The stack is not extended by deopt but we must NULL last_sp as this
 325   // entry is like a "return".
 326   __ mov(Rtemp, 0);
 327   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
 328 #endif // AARCH64
 329 
 330   __ restore_method();
 331   __ restore_bcp();
 332   __ restore_dispatch();
 333   __ restore_locals();
 334 
 335   // handle exceptions
 336   { Label L;
 337     __ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset()));
 338     __ cbz(Rtemp, L);
 339     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
 340     __ should_not_reach_here();
 341     __ bind(L);
 342   }
 343 
 344   if (continuation == NULL) {
 345     __ dispatch_next(state, step);
 346   } else {
 347     __ jump_to_entry(continuation);
 348   }
 349 
 350   return entry;
 351 }
 352 
 353 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
 354 #ifdef AARCH64
 355   address entry = __ pc();
 356   switch (type) {
 357     case T_BOOLEAN:
 358       __ tst(R0, 0xff);
 359       __ cset(R0, ne);
 360       break;
 361     case T_CHAR   : __ zero_extend(R0, R0, 16);  break;
 362     case T_BYTE   : __ sign_extend(R0, R0,  8);  break;
 363     case T_SHORT  : __ sign_extend(R0, R0, 16);  break;
 364     case T_INT    : // fall through
 365     case T_LONG   : // fall through
 366     case T_VOID   : // fall through
 367     case T_FLOAT  : // fall through
 368     case T_DOUBLE : /* nothing to do */          break;
 369     case T_OBJECT :
 370       // retrieve result from frame
 371       __ ldr(R0, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize));
 372       // and verify it
 373       __ verify_oop(R0);
 374       break;
 375     default       : ShouldNotReachHere();
 376   }
 377   __ ret();
 378   return entry;
 379 #else
 380   // Result handlers are not used on 32-bit ARM
 381   // since the returned value is already in appropriate format.
 382   __ should_not_reach_here();  // to avoid empty code block
 383 
 384   // The result handler non-zero indicates an object is returned and this is
 385   // used in the native entry code.
 386   return type == T_OBJECT ? (address)(-1) : NULL;
 387 #endif // AARCH64
 388 }
 389 
 390 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
 391   address entry = __ pc();
 392   __ push(state);
 393   __ call_VM(noreg, runtime_entry);
 394 
 395   // load current bytecode
 396   __ ldrb(R3_bytecode, Address(Rbcp));
 397   __ dispatch_only_normal(vtos);
 398   return entry;
 399 }
 400 
 401 
 402 // Helpers for commoning out cases in the various type of method entries.
 403 //
 404 
 405 // increment invocation count & check for overflow
 406 //
 407 // Note: checking for negative value instead of overflow


 449 
 450     const Register Ricnt = R0_tmp;  // invocation counter
 451     const Register Rbcnt = R1_tmp;  // backedge counter
 452 
 453     __ get_method_counters(Rmethod, Rcounters, done);
 454 
 455     if (ProfileInterpreter) {
 456       const Register Riic = R1_tmp;
 457       __ ldr_s32(Riic, Address(Rcounters, MethodCounters::interpreter_invocation_counter_offset()));
 458       __ add(Riic, Riic, 1);
 459       __ str_32(Riic, Address(Rcounters, MethodCounters::interpreter_invocation_counter_offset()));
 460     }
 461 
 462     // Update standard invocation counters
 463 
 464     __ ldr_u32(Ricnt, invocation_counter);
 465     __ ldr_u32(Rbcnt, backedge_counter);
 466 
 467     __ add(Ricnt, Ricnt, InvocationCounter::count_increment);
 468 
 469 #ifdef AARCH64
 470     __ andr(Rbcnt, Rbcnt, (unsigned int)InvocationCounter::count_mask_value); // mask out the status bits
 471 #else
 472     __ bic(Rbcnt, Rbcnt, ~InvocationCounter::count_mask_value); // mask out the status bits
 473 #endif // AARCH64
 474 
 475     __ str_32(Ricnt, invocation_counter);            // save invocation count
 476     __ add(Ricnt, Ricnt, Rbcnt);                     // add both counters
 477 
 478     // profile_method is non-null only for interpreted method so
 479     // profile_method != NULL == !native_call
 480     // BytecodeInterpreter only calls for native so code is elided.
 481 
 482     if (ProfileInterpreter && profile_method != NULL) {
 483       assert(profile_method_continue != NULL, "should be non-null");
 484 
 485       // Test to see if we should create a method data oop
 486       // Reuse R1_tmp as we don't need backedge counters anymore.
 487       Address profile_limit(Rcounters, in_bytes(MethodCounters::interpreter_profile_limit_offset()));
 488       __ ldr_s32(R1_tmp, profile_limit);
 489       __ cmp_32(Ricnt, R1_tmp);
 490       __ b(*profile_method_continue, lt);
 491 
 492       // if no method data exists, go to profile_method
 493       __ test_method_data_pointer(R1_tmp, *profile_method);


 505   // InterpreterRuntime::frequency_counter_overflow takes one argument
 506   // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
 507   // The call returns the address of the verified entry point for the method or NULL
 508   // if the compilation did not complete (either went background or bailed out).
 509   __ mov(R1, (int)false);
 510   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), R1);
 511 
 512   // jump to the interpreted entry.
 513   __ b(do_continue);
 514 }
 515 
 516 void TemplateInterpreterGenerator::generate_stack_overflow_check(void) {
 517   // Check if we've got enough room on the stack for
 518   //  - overhead;
 519   //  - locals;
 520   //  - expression stack.
 521   //
 522   // Registers on entry:
 523   //
 524   // R3 = number of additional locals
 525   // R11 = max expression stack slots (AArch64 only)
 526   // Rthread
 527   // Rmethod
 528   // Registers used: R0, R1, R2, Rtemp.
 529 
 530   const Register Radditional_locals = R3;
 531   const Register RmaxStack = AARCH64_ONLY(R11) NOT_AARCH64(R2);
 532 
 533   // monitor entry size
 534   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
 535 
 536   // total overhead size: entry_size + (saved registers, thru expr stack bottom).
 537   // be sure to change this if you add/subtract anything to/from the overhead area
 538   const int overhead_size = (frame::sender_sp_offset - frame::interpreter_frame_initial_sp_offset)*wordSize + entry_size;
 539 
 540   // Pages reserved for VM runtime calls and subsequent Java calls.
 541   const int reserved_pages = JavaThread::stack_shadow_zone_size();
 542 
 543   // Thread::stack_size() includes guard pages, and they should not be touched.
 544   const int guard_pages = JavaThread::stack_guard_zone_size();
 545 
 546   __ ldr(R0, Address(Rthread, Thread::stack_base_offset()));
 547   __ ldr(R1, Address(Rthread, Thread::stack_size_offset()));
 548 #ifndef AARCH64
 549   __ ldr(Rtemp, Address(Rmethod, Method::const_offset()));
 550   __ ldrh(RmaxStack, Address(Rtemp, ConstMethod::max_stack_offset()));
 551 #endif // !AARCH64
 552   __ sub_slow(Rtemp, SP, overhead_size + reserved_pages + guard_pages + Method::extra_stack_words());
 553 
 554   // reserve space for additional locals
 555   __ sub(Rtemp, Rtemp, AsmOperand(Radditional_locals, lsl, Interpreter::logStackElementSize));
 556 
 557   // stack size
 558   __ sub(R0, R0, R1);
 559 
 560   // reserve space for expression stack
 561   __ sub(Rtemp, Rtemp, AsmOperand(RmaxStack, lsl, Interpreter::logStackElementSize));
 562 
 563   __ cmp(Rtemp, R0);
 564 
 565 #ifdef AARCH64
 566   Label L;
 567   __ b(L, hi);
 568   __ mov(SP, Rsender_sp);  // restore SP
 569   __ b(StubRoutines::throw_StackOverflowError_entry());
 570   __ bind(L);
 571 #else
 572   __ mov(SP, Rsender_sp, ls);  // restore SP
 573   __ b(StubRoutines::throw_StackOverflowError_entry(), ls);
 574 #endif // AARCH64
 575 }
 576 
 577 
 578 // Allocate monitor and lock method (asm interpreter)
 579 //
 580 void TemplateInterpreterGenerator::lock_method() {
 581   // synchronize method
 582 
 583   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
 584   assert ((entry_size % StackAlignmentInBytes) == 0, "should keep stack alignment");
 585 
 586   #ifdef ASSERT
 587     { Label L;
 588       __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
 589       __ tbnz(Rtemp, JVM_ACC_SYNCHRONIZED_BIT, L);
 590       __ stop("method doesn't need synchronization");
 591       __ bind(L);
 592     }
 593   #endif // ASSERT
 594 
 595   // get synchronization object
 596   { Label done;
 597     __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
 598 #ifdef AARCH64
 599     __ ldr(R0, Address(Rlocals, Interpreter::local_offset_in_bytes(0))); // get receiver (assume this is frequent case)
 600     __ tbz(Rtemp, JVM_ACC_STATIC_BIT, done);
 601 #else
 602     __ tst(Rtemp, JVM_ACC_STATIC);
 603     __ ldr(R0, Address(Rlocals, Interpreter::local_offset_in_bytes(0)), eq); // get receiver (assume this is frequent case)
 604     __ b(done, eq);
 605 #endif // AARCH64
 606     __ load_mirror(R0, Rmethod, Rtemp);
 607     __ bind(done);
 608   }
 609 
 610   // add space for monitor & lock
 611 
 612 #ifdef AARCH64
 613   __ check_extended_sp(Rtemp);
 614   __ sub(SP, SP, entry_size);                  // adjust extended SP
 615   __ mov(Rtemp, SP);
 616   __ str(Rtemp, Address(FP, frame::interpreter_frame_extended_sp_offset * wordSize));
 617 #endif // AARCH64
 618 
 619   __ sub(Rstack_top, Rstack_top, entry_size);
 620   __ check_stack_top_on_expansion();
 621                                               // add space for a monitor entry
 622   __ str(Rstack_top, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize));
 623                                               // set new monitor block top
 624   __ str(R0, Address(Rstack_top, BasicObjectLock::obj_offset_in_bytes()));
 625                                               // store object
 626   __ mov(R1, Rstack_top);                     // monitor entry address
 627   __ lock_object(R1);
 628 }
 629 
 630 #ifdef AARCH64
 631 
 632 //
 633 // Generate a fixed interpreter frame. This is identical setup for interpreted methods
 634 // and for native methods hence the shared code.
 635 //
 636 // On entry:
 637 //   R10 = ConstMethod
 638 //   R11 = max expr. stack (in slots), if !native_call
 639 //
 640 // On exit:
 641 //   Rbcp, Rstack_top are initialized, SP is extended
 642 //
 643 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
 644   // Incoming registers
 645   const Register RconstMethod = R10;
 646   const Register RmaxStack = R11;
 647   // Temporary registers
 648   const Register RextendedSP = R0;
 649   const Register Rcache = R1;
 650   const Register Rmdp = ProfileInterpreter ? R2 : ZR;
 651 
 652   // Generates the following stack layout (stack grows up in this picture):
 653   //
 654   // [ expr. stack bottom ]
 655   // [ saved Rbcp         ]
 656   // [ current Rlocals    ]
 657   // [ cache              ]
 658   // [ mdx                ]
 659   // [ mirror             ]
 660   // [ Method*            ]
 661   // [ extended SP        ]
 662   // [ expr. stack top    ]
 663   // [ sender_sp          ]
 664   // [ saved FP           ] <--- FP
 665   // [ saved LR           ]
 666 
 667   // initialize fixed part of activation frame
 668   __ stp(FP, LR, Address(SP, -2*wordSize, pre_indexed));
 669   __ mov(FP, SP);                                     // establish new FP
 670 
 671   // setup Rbcp
 672   if (native_call) {
 673     __ mov(Rbcp, ZR);                                 // bcp = 0 for native calls
 674   } else {
 675     __ add(Rbcp, RconstMethod, in_bytes(ConstMethod::codes_offset())); // get codebase
 676   }
 677 
 678   // Rstack_top & RextendedSP
 679   __ sub(Rstack_top, SP, 10*wordSize);
 680   if (native_call) {
 681     __ sub(RextendedSP, Rstack_top, align_up(wordSize, StackAlignmentInBytes));    // reserve 1 slot for exception handling
 682   } else {
 683     __ sub(RextendedSP, Rstack_top, AsmOperand(RmaxStack, lsl, Interpreter::logStackElementSize));
 684     __ align_reg(RextendedSP, RextendedSP, StackAlignmentInBytes);
 685   }
 686   __ mov(SP, RextendedSP);
 687   __ check_stack_top();
 688 
 689   // Load Rmdp
 690   if (ProfileInterpreter) {
 691     __ ldr(Rtemp, Address(Rmethod, Method::method_data_offset()));
 692     __ tst(Rtemp, Rtemp);
 693     __ add(Rtemp, Rtemp, in_bytes(MethodData::data_offset()));
 694     __ csel(Rmdp, ZR, Rtemp, eq);
 695   }
 696 
 697   // Load Rcache
 698   __ ldr(Rtemp, Address(RconstMethod, ConstMethod::constants_offset()));
 699   __ ldr(Rcache, Address(Rtemp, ConstantPool::cache_offset_in_bytes()));
 700   // Get mirror and store it in the frame as GC root for this Method*
 701   __ load_mirror(Rtemp, Rmethod, Rtemp);
 702 
 703   // Build fixed frame
 704   __ stp(Rstack_top, Rbcp, Address(FP, -10*wordSize));
 705   __ stp(Rlocals, Rcache,  Address(FP,  -8*wordSize));
 706   __ stp(Rmdp, Rtemp,          Address(FP,  -6*wordSize));
 707   __ stp(Rmethod, RextendedSP, Address(FP,  -4*wordSize));
 708   __ stp(ZR, Rsender_sp,   Address(FP,  -2*wordSize));
 709   assert(frame::interpreter_frame_initial_sp_offset == -10, "interpreter frame broken");
 710   assert(frame::interpreter_frame_stack_top_offset  == -2, "stack top broken");
 711 }
 712 
 713 #else // AARCH64
 714 
 715 //
 716 // Generate a fixed interpreter frame. This is identical setup for interpreted methods
 717 // and for native methods hence the shared code.
 718 
 719 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
 720   // Generates the following stack layout:
 721   //
 722   // [ expr. stack bottom ]
 723   // [ saved Rbcp         ]
 724   // [ current Rlocals    ]
 725   // [ cache              ]
 726   // [ mdx                ]
 727   // [ Method*            ]
 728   // [ last_sp            ]
 729   // [ sender_sp          ]
 730   // [ saved FP           ] <--- FP
 731   // [ saved LR           ]
 732 
 733   // initialize fixed part of activation frame


 755 
 756   if (ProfileInterpreter) {
 757     __ ldr(Rtemp, Address(Rmethod, Method::method_data_offset()));
 758     __ tst(Rtemp, Rtemp);
 759     __ add(Rtemp, Rtemp, in_bytes(MethodData::data_offset()), ne);
 760     __ push(Rtemp);                                    // set the mdp (method data pointer)
 761   } else {
 762     __ push(R0);
 763   }
 764 
 765   __ ldr(Rtemp, Address(Rmethod, Method::const_offset()));
 766   __ ldr(Rtemp, Address(Rtemp, ConstMethod::constants_offset()));
 767   __ ldr(Rtemp, Address(Rtemp, ConstantPool::cache_offset_in_bytes()));
 768   __ push(Rtemp);                                      // set constant pool cache
 769   __ push(Rlocals);                                    // set locals pointer
 770   __ push(Rbcp);                                       // set bcp
 771   __ push(R0);                                         // reserve word for pointer to expression stack bottom
 772   __ str(SP, Address(SP, 0));                          // set expression stack bottom
 773 }
 774 
 775 #endif // AARCH64
 776 
 777 // End of helpers
 778 
 779 //------------------------------------------------------------------------------------------------------------------------
 780 // Entry points
 781 //
 782 // Here we generate the various kind of entries into the interpreter.
 783 // The two main entry type are generic bytecode methods and native call method.
 784 // These both come in synchronized and non-synchronized versions but the
 785 // frame layout they create is very similar. The other method entry
 786 // types are really just special purpose entries that are really entry
 787 // and interpretation all in one. These are for trivial methods like
 788 // accessor, empty, or special math methods.
 789 //
 790 // When control flow reaches any of the entry types for the interpreter
 791 // the following holds ->
 792 //
 793 // Arguments:
 794 //
 795 // Rmethod: Method*
 796 // Rthread: thread
 797 // Rsender_sp:  sender sp
 798 // Rparams (SP on 32-bit ARM): pointer to method parameters
 799 //
 800 // LR: return address
 801 //
 802 // Stack layout immediately at entry
 803 //
 804 // [ optional padding(*)] <--- SP (AArch64)
 805 // [ parameter n        ] <--- Rparams (SP on 32-bit ARM)
 806 //   ...
 807 // [ parameter 1        ]
 808 // [ expression stack   ] (caller's java expression stack)
 809 
 810 // Assuming that we don't go to one of the trivial specialized
 811 // entries the stack will look like below when we are ready to execute
 812 // the first bytecode (or call the native routine). The register usage
 813 // will be as the template based interpreter expects.
 814 //
 815 // local variables follow incoming parameters immediately; i.e.
 816 // the return address is saved at the end of the locals.
 817 //
 818 // [ reserved stack (*) ] <--- SP (AArch64)
 819 // [ expr. stack        ] <--- Rstack_top (SP on 32-bit ARM)
 820 // [ monitor entry      ]
 821 //   ...
 822 // [ monitor entry      ]
 823 // [ expr. stack bottom ]
 824 // [ saved Rbcp         ]
 825 // [ current Rlocals    ]
 826 // [ cache              ]
 827 // [ mdx                ]
 828 // [ mirror             ]
 829 // [ Method*            ]
 830 //
 831 // 32-bit ARM:
 832 // [ last_sp            ]
 833 //
 834 // AArch64:
 835 // [ extended SP (*)    ]
 836 // [ stack top (*)      ]
 837 //
 838 // [ sender_sp          ]
 839 // [ saved FP           ] <--- FP
 840 // [ saved LR           ]
 841 // [ optional padding(*)]
 842 // [ local variable m   ]
 843 //   ...
 844 // [ local variable 1   ]
 845 // [ parameter n        ]
 846 //   ...
 847 // [ parameter 1        ] <--- Rlocals
 848 //
 849 // (*) - AArch64 only
 850 //
 851 
 852 address TemplateInterpreterGenerator::generate_Reference_get_entry(void) {
 853   // Code: _aload_0, _getfield, _areturn
 854   // parameter size = 1
 855   //
 856   // The code that gets generated by this routine is split into 2 parts:
 857   //    1. The "intrinsified" code performing an ON_WEAK_OOP_REF load,
 858   //    2. The slow path - which is an expansion of the regular method entry.
 859   //
 860   // Notes:-
 861   // * An intrinsic is always executed, where an ON_WEAK_OOP_REF load is performed.
 862   // * We may jump to the slow path iff the receiver is null. If the
 863   //   Reference object is null then we no longer perform an ON_WEAK_OOP_REF load
 864   //   Thus we can use the regular method entry code to generate the NPE.
 865   //
 866   // Rmethod: Method*
 867   // Rthread: thread
 868   // Rsender_sp: sender sp, must be preserved for slow path, set SP to it on fast path
 869   // Rparams: parameters
 870 


 907 //
 908 // Interpreter stub for calling a native method. (asm interpreter)
 909 // This sets up a somewhat different looking stack for calling the native method
 910 // than the typical interpreter frame setup.
 911 //
 912 
 913 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
 914   // determine code generation flags
 915   bool inc_counter  = UseCompiler || CountCompiledCalls || LogTouchedMethods;
 916 
 917   // Incoming registers:
 918   //
 919   // Rmethod: Method*
 920   // Rthread: thread
 921   // Rsender_sp: sender sp
 922   // Rparams: parameters
 923 
 924   address entry_point = __ pc();
 925 
 926   // Register allocation
 927   const Register Rsize_of_params = AARCH64_ONLY(R20) NOT_AARCH64(R6);
 928   const Register Rsig_handler    = AARCH64_ONLY(R21) NOT_AARCH64(Rtmp_save0 /* R4 */);
 929   const Register Rnative_code    = AARCH64_ONLY(R22) NOT_AARCH64(Rtmp_save1 /* R5 */);
 930   const Register Rresult_handler = AARCH64_ONLY(Rsig_handler) NOT_AARCH64(R6);
 931 
 932 #ifdef AARCH64
 933   const Register RconstMethod = R10; // also used in generate_fixed_frame (should match)
 934   const Register Rsaved_result = Rnative_code;
 935   const FloatRegister Dsaved_result = V8;
 936 #else
 937   const Register Rsaved_result_lo = Rtmp_save0;  // R4
 938   const Register Rsaved_result_hi = Rtmp_save1;  // R5
 939   FloatRegister saved_result_fp;
 940 #endif // AARCH64
 941 
 942 
 943 #ifdef AARCH64
 944   __ ldr(RconstMethod, Address(Rmethod, Method::const_offset()));
 945   __ ldrh(Rsize_of_params,  Address(RconstMethod, ConstMethod::size_of_parameters_offset()));
 946 #else
 947   __ ldr(Rsize_of_params, Address(Rmethod, Method::const_offset()));
 948   __ ldrh(Rsize_of_params,  Address(Rsize_of_params, ConstMethod::size_of_parameters_offset()));
 949 #endif // AARCH64
 950 
 951   // native calls don't need the stack size check since they have no expression stack
 952   // and the arguments are already on the stack and we only add a handful of words
 953   // to the stack
 954 
 955   // compute beginning of parameters (Rlocals)
 956   __ sub(Rlocals, Rparams, wordSize);
 957   __ add(Rlocals, Rlocals, AsmOperand(Rsize_of_params, lsl, Interpreter::logStackElementSize));
 958 
 959 #ifdef AARCH64
 960   int extra_stack_reserve = 2*wordSize; // extra space for oop_temp
 961   if(__ can_post_interpreter_events()) {
 962     // extra space for saved results
 963     extra_stack_reserve += 2*wordSize;
 964   }
 965   // reserve extra stack space and nullify oop_temp slot
 966   __ stp(ZR, ZR, Address(SP, -extra_stack_reserve, pre_indexed));
 967 #else
 968   // reserve stack space for oop_temp
 969   __ mov(R0, 0);
 970   __ push(R0);
 971 #endif // AARCH64
 972 
 973   generate_fixed_frame(true); // Note: R9 is now saved in the frame
 974 
 975   // make sure method is native & not abstract
 976 #ifdef ASSERT
 977   __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
 978   {
 979     Label L;
 980     __ tbnz(Rtemp, JVM_ACC_NATIVE_BIT, L);
 981     __ stop("tried to execute non-native method as native");
 982     __ bind(L);
 983   }
 984   { Label L;
 985     __ tbz(Rtemp, JVM_ACC_ABSTRACT_BIT, L);
 986     __ stop("tried to execute abstract method in interpreter");
 987     __ bind(L);
 988   }
 989 #endif
 990 
 991   // increment invocation count & check for overflow


1047     __ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset()));
1048     __ cbnz(Rsig_handler, L);
1049     __ mov(R1, Rmethod);
1050     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1, true);
1051     __ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset()));
1052     __ bind(L);
1053   }
1054 
1055   {
1056     Label L;
1057     __ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset()));
1058     __ cbnz(Rnative_code, L);
1059     __ mov(R1, Rmethod);
1060     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1);
1061     __ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset()));
1062     __ bind(L);
1063   }
1064 
1065   // Allocate stack space for arguments
1066 
1067 #ifdef AARCH64
1068   __ sub(Rtemp, SP, Rsize_of_params, ex_uxtw, LogBytesPerWord);
1069   __ align_reg(SP, Rtemp, StackAlignmentInBytes);
1070 
1071   // Allocate more stack space to accomodate all arguments passed on GP and FP registers:
1072   // 8 * wordSize for GPRs
1073   // 8 * wordSize for FPRs
1074   int reg_arguments = align_up(8*wordSize + 8*wordSize, StackAlignmentInBytes);
1075 #else
1076 
1077   // C functions need aligned stack
1078   __ bic(SP, SP, StackAlignmentInBytes - 1);
1079   // Multiply by BytesPerLong instead of BytesPerWord, because calling convention
1080   // may require empty slots due to long alignment, e.g. func(int, jlong, int, jlong)
1081   __ sub(SP, SP, AsmOperand(Rsize_of_params, lsl, LogBytesPerLong));
1082 
1083 #ifdef __ABI_HARD__
1084   // Allocate more stack space to accomodate all GP as well as FP registers:
1085   // 4 * wordSize
1086   // 8 * BytesPerLong
1087   int reg_arguments = align_up((4*wordSize) + (8*BytesPerLong), StackAlignmentInBytes);
1088 #else
1089   // Reserve at least 4 words on the stack for loading
1090   // of parameters passed on registers (R0-R3).
1091   // See generate_slow_signature_handler().
1092   // It is also used for JNIEnv & class additional parameters.
1093   int reg_arguments = 4 * wordSize;
1094 #endif // __ABI_HARD__
1095 #endif // AARCH64
1096 
1097   __ sub(SP, SP, reg_arguments);
1098 
1099 
1100   // Note: signature handler blows R4 (32-bit ARM) or R21 (AArch64) besides all scratch registers.
1101   // See AbstractInterpreterGenerator::generate_slow_signature_handler().
1102   __ call(Rsig_handler);
1103 #if R9_IS_SCRATCHED
1104   __ restore_method();
1105 #endif
1106   __ mov(Rresult_handler, R0);
1107 
1108   // Pass JNIEnv and mirror for static methods
1109   {
1110     Label L;
1111     __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
1112     __ add(R0, Rthread, in_bytes(JavaThread::jni_environment_offset()));
1113     __ tbz(Rtemp, JVM_ACC_STATIC_BIT, L);
1114     __ load_mirror(Rtemp, Rmethod, Rtemp);
1115     __ add(R1, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
1116     __ str(Rtemp, Address(R1, 0));
1117     __ bind(L);
1118   }
1119 
1120   __ set_last_Java_frame(SP, FP, true, Rtemp);
1121 
1122   // Changing state to _thread_in_native must be the last thing to do
1123   // before the jump to native code. At this moment stack must be
1124   // safepoint-safe and completely prepared for stack walking.
1125 #ifdef ASSERT
1126   {
1127     Label L;
1128     __ ldr_u32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
1129     __ cmp_32(Rtemp, _thread_in_Java);
1130     __ b(L, eq);
1131     __ stop("invalid thread state");
1132     __ bind(L);
1133   }
1134 #endif
1135 
1136 #ifdef AARCH64
1137   __ mov(Rtemp, _thread_in_native);
1138   __ add(Rtemp2, Rthread, in_bytes(JavaThread::thread_state_offset()));
1139   // STLR is used to force all preceding writes to be observed prior to thread state change
1140   __ stlr_w(Rtemp, Rtemp2);
1141 #else
1142   // Force all preceding writes to be observed prior to thread state change
1143   __ membar(MacroAssembler::StoreStore, Rtemp);
1144 
1145   __ mov(Rtemp, _thread_in_native);
1146   __ str(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
1147 #endif // AARCH64
1148 
1149   __ call(Rnative_code);
1150 #if R9_IS_SCRATCHED
1151   __ restore_method();
1152 #endif
1153 
1154   // Set FPSCR/FPCR to a known state
1155   if (AlwaysRestoreFPU) {
1156     __ restore_default_fp_mode();
1157   }
1158 
1159   // Do safepoint check
1160   __ mov(Rtemp, _thread_in_native_trans);
1161   __ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
1162 
1163     // Force this write out before the read below
1164   __ membar(MacroAssembler::StoreLoad, Rtemp);
1165 
1166   __ ldr_global_s32(Rtemp, SafepointSynchronize::address_of_state());
1167 
1168   // Protect the return value in the interleaved code: save it to callee-save registers.
1169 #ifdef AARCH64
1170   __ mov(Rsaved_result, R0);
1171   __ fmov_d(Dsaved_result, D0);
1172 #else
1173   __ mov(Rsaved_result_lo, R0);
1174   __ mov(Rsaved_result_hi, R1);
1175 #ifdef __ABI_HARD__
1176   // preserve native FP result in a callee-saved register
1177   saved_result_fp = D8;
1178   __ fcpyd(saved_result_fp, D0);
1179 #else
1180   saved_result_fp = fnoreg;
1181 #endif // __ABI_HARD__
1182 #endif // AARCH64
1183 
1184   {
1185     __ ldr_u32(R3, Address(Rthread, JavaThread::suspend_flags_offset()));
1186     __ cmp(Rtemp, SafepointSynchronize::_not_synchronized);
1187     __ cond_cmp(R3, 0, eq);
1188 
1189 #ifdef AARCH64
1190     Label L;
1191     __ b(L, eq);
1192     __ mov(R0, Rthread);
1193     __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans), relocInfo::none);
1194     __ bind(L);
1195 #else
1196   __ mov(R0, Rthread, ne);
1197   __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans), relocInfo::none, ne);
1198 #if R9_IS_SCRATCHED
1199   __ restore_method();
1200 #endif
1201 #endif // AARCH64
1202   }
1203 
1204   // Perform Native->Java thread transition
1205   __ mov(Rtemp, _thread_in_Java);
1206   __ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
1207 
1208   // Zero handles and last_java_sp
1209   __ reset_last_Java_frame(Rtemp);
1210   __ ldr(R3, Address(Rthread, JavaThread::active_handles_offset()));
1211   __ str_32(__ zero_register(Rtemp), Address(R3, JNIHandleBlock::top_offset_in_bytes()));
1212   if (CheckJNICalls) {
1213     __ str(__ zero_register(Rtemp), Address(Rthread, JavaThread::pending_jni_exception_check_fn_offset()));
1214   }
1215 
1216   // Unbox oop result, e.g. JNIHandles::resolve result if it's an oop.
1217   {
1218     Label Lnot_oop;
1219 #ifdef AARCH64
1220     __ mov_slow(Rtemp, AbstractInterpreter::result_handler(T_OBJECT));
1221     __ cmp(Rresult_handler, Rtemp);
1222     __ b(Lnot_oop, ne);
1223 #else // !AARCH64
1224     // For ARM32, Rresult_handler is -1 for oop result, 0 otherwise.
1225     __ cbz(Rresult_handler, Lnot_oop);
1226 #endif // !AARCH64
1227     Register value = AARCH64_ONLY(Rsaved_result) NOT_AARCH64(Rsaved_result_lo);
1228     __ resolve_jobject(value,   // value
1229                        Rtemp,   // tmp1
1230                        R1_tmp); // tmp2
1231     // Store resolved result in frame for GC visibility.
1232     __ str(value, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize));
1233     __ bind(Lnot_oop);
1234   }
1235 
1236 #ifdef AARCH64
1237   // Restore SP (drop native parameters area), to keep SP in sync with extended_sp in frame
1238   __ restore_sp_after_call(Rtemp);
1239   __ check_stack_top();
1240 #endif // AARCH64
1241 
1242   // reguard stack if StackOverflow exception happened while in native.
1243   {
1244     __ ldr_u32(Rtemp, Address(Rthread, JavaThread::stack_guard_state_offset()));
1245     __ cmp_32(Rtemp, JavaThread::stack_guard_yellow_reserved_disabled);
1246 #ifdef AARCH64
1247     Label L;
1248     __ b(L, ne);
1249     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::none);
1250     __ bind(L);
1251 #else
1252   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::none, eq);
1253 #if R9_IS_SCRATCHED
1254   __ restore_method();
1255 #endif
1256 #endif // AARCH64
1257   }
1258 
1259   // check pending exceptions
1260   {
1261     __ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset()));
1262 #ifdef AARCH64
1263     Label L;
1264     __ cbz(Rtemp, L);
1265     __ mov_pc_to(Rexception_pc);
1266     __ b(StubRoutines::forward_exception_entry());
1267     __ bind(L);
1268 #else
1269     __ cmp(Rtemp, 0);
1270     __ mov(Rexception_pc, PC, ne);
1271     __ b(StubRoutines::forward_exception_entry(), ne);
1272 #endif // AARCH64
1273   }
1274 
1275   if (synchronized) {
1276     // address of first monitor
1277     __ sub(R1, FP, - (frame::interpreter_frame_monitor_block_bottom_offset - frame::interpreter_frame_monitor_size()) * wordSize);
1278     __ unlock_object(R1);
1279   }
1280 
1281   // jvmti/dtrace support
1282   // Note: This must happen _after_ handling/throwing any exceptions since
1283   //       the exception handler code notifies the runtime of method exits
1284   //       too. If this happens before, method entry/exit notifications are
1285   //       not properly paired (was bug - gri 11/22/99).
1286 #ifdef AARCH64
1287   __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI, true, Rsaved_result, noreg, Dsaved_result);
1288 #else
1289   __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI, true, Rsaved_result_lo, Rsaved_result_hi, saved_result_fp);
1290 #endif // AARCH64
1291 
1292   // Restore the result. Oop result is restored from the stack.
1293 #ifdef AARCH64
1294   __ mov(R0, Rsaved_result);
1295   __ fmov_d(D0, Dsaved_result);
1296 
1297   __ blr(Rresult_handler);
1298 #else
1299   __ cmp(Rresult_handler, 0);
1300   __ ldr(R0, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize), ne);
1301   __ mov(R0, Rsaved_result_lo, eq);
1302   __ mov(R1, Rsaved_result_hi);
1303 
1304 #ifdef __ABI_HARD__
1305   // reload native FP result
1306   __ fcpyd(D0, D8);
1307 #endif // __ABI_HARD__
1308 
1309 #ifdef ASSERT
1310   if (VerifyOops) {
1311     Label L;
1312     __ cmp(Rresult_handler, 0);
1313     __ b(L, eq);
1314     __ verify_oop(R0);
1315     __ bind(L);
1316   }
1317 #endif // ASSERT
1318 #endif // AARCH64
1319 
1320   // Restore FP/LR, sender_sp and return
1321 #ifdef AARCH64
1322   __ ldr(Rtemp, Address(FP, frame::interpreter_frame_sender_sp_offset * wordSize));
1323   __ ldp(FP, LR, Address(FP));
1324   __ mov(SP, Rtemp);
1325 #else
1326   __ mov(Rtemp, FP);
1327   __ ldmia(FP, RegisterSet(FP) | RegisterSet(LR));
1328   __ ldr(SP, Address(Rtemp, frame::interpreter_frame_sender_sp_offset * wordSize));
1329 #endif // AARCH64
1330 
1331   __ ret();
1332 
1333   if (inc_counter) {
1334     // Handle overflow of counter and compile method
1335     __ bind(invocation_counter_overflow);
1336     generate_counter_overflow(continue_after_compile);
1337   }
1338 
1339   return entry_point;
1340 }
1341 
1342 //
1343 // Generic interpreted method entry to (asm) interpreter
1344 //
1345 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) {
1346   // determine code generation flags
1347   bool inc_counter  = UseCompiler || CountCompiledCalls || LogTouchedMethods;
1348 
1349   // Rmethod: Method*
1350   // Rthread: thread
1351   // Rsender_sp: sender sp (could differ from SP if we were called via c2i)
1352   // Rparams: pointer to the last parameter in the stack
1353 
1354   address entry_point = __ pc();
1355 
1356   const Register RconstMethod = AARCH64_ONLY(R10) NOT_AARCH64(R3);
1357 
1358 #ifdef AARCH64
1359   const Register RmaxStack = R11;
1360   const Register RlocalsBase = R12;
1361 #endif // AARCH64
1362 
1363   __ ldr(RconstMethod, Address(Rmethod, Method::const_offset()));
1364 
1365   __ ldrh(R2, Address(RconstMethod, ConstMethod::size_of_parameters_offset()));
1366   __ ldrh(R3, Address(RconstMethod, ConstMethod::size_of_locals_offset()));
1367 
1368   // setup Rlocals
1369   __ sub(Rlocals, Rparams, wordSize);
1370   __ add(Rlocals, Rlocals, AsmOperand(R2, lsl, Interpreter::logStackElementSize));
1371 
1372   __ sub(R3, R3, R2); // number of additional locals
1373 
1374 #ifdef AARCH64
1375   // setup RmaxStack
1376   __ ldrh(RmaxStack, Address(RconstMethod, ConstMethod::max_stack_offset()));
1377   // We have to add extra reserved slots to max_stack. There are 3 users of the extra slots,
1378   // none of which are at the same time, so we just need to make sure there is enough room
1379   // for the biggest user:
1380   //   -reserved slot for exception handler
1381   //   -reserved slots for JSR292. Method::extra_stack_entries() is the size.
1382   //   -3 reserved slots so get_method_counters() can save some registers before call_VM().
1383   __ add(RmaxStack, RmaxStack, MAX2(3, Method::extra_stack_entries()));
1384 #endif // AARCH64
1385 
1386   // see if we've got enough room on the stack for locals plus overhead.
1387   generate_stack_overflow_check();
1388 
1389 #ifdef AARCH64
1390 
1391   // allocate space for locals
1392   {
1393     __ sub(RlocalsBase, Rparams, AsmOperand(R3, lsl, Interpreter::logStackElementSize));
1394     __ align_reg(SP, RlocalsBase, StackAlignmentInBytes);
1395   }
1396 
1397   // explicitly initialize locals
1398   {
1399     Label zero_loop, done;
1400     __ cbz(R3, done);
1401 
1402     __ tbz(R3, 0, zero_loop);
1403     __ subs(R3, R3, 1);
1404     __ str(ZR, Address(RlocalsBase, wordSize, post_indexed));
1405     __ b(done, eq);
1406 
1407     __ bind(zero_loop);
1408     __ subs(R3, R3, 2);
1409     __ stp(ZR, ZR, Address(RlocalsBase, 2*wordSize, post_indexed));
1410     __ b(zero_loop, ne);
1411 
1412     __ bind(done);
1413   }
1414 
1415 #else
1416   // allocate space for locals
1417   // explicitly initialize locals
1418 
1419   // Loop is unrolled 4 times
1420   Label loop;
1421   __ mov(R0, 0);
1422   __ bind(loop);
1423 
1424   // #1
1425   __ subs(R3, R3, 1);
1426   __ push(R0, ge);
1427 
1428   // #2
1429   __ subs(R3, R3, 1, ge);
1430   __ push(R0, ge);
1431 
1432   // #3
1433   __ subs(R3, R3, 1, ge);
1434   __ push(R0, ge);
1435 
1436   // #4
1437   __ subs(R3, R3, 1, ge);
1438   __ push(R0, ge);
1439 
1440   __ b(loop, gt);
1441 #endif // AARCH64
1442 
1443   // initialize fixed part of activation frame
1444   generate_fixed_frame(false);
1445 
1446   __ restore_dispatch();
1447 
1448   // make sure method is not native & not abstract
1449 #ifdef ASSERT
1450   __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
1451   {
1452     Label L;
1453     __ tbz(Rtemp, JVM_ACC_NATIVE_BIT, L);
1454     __ stop("tried to execute native method as non-native");
1455     __ bind(L);
1456   }
1457   { Label L;
1458     __ tbz(Rtemp, JVM_ACC_ABSTRACT_BIT, L);
1459     __ stop("tried to execute abstract method in interpreter");
1460     __ bind(L);
1461   }


1536 
1537       __ b(profile_method_continue);
1538     }
1539 
1540     // Handle overflow of counter and compile method
1541     __ bind(invocation_counter_overflow);
1542     generate_counter_overflow(continue_after_compile);
1543   }
1544 
1545   return entry_point;
1546 }
1547 
1548 //------------------------------------------------------------------------------------------------------------------------
1549 // Exceptions
1550 
1551 void TemplateInterpreterGenerator::generate_throw_exception() {
1552   // Entry point in previous activation (i.e., if the caller was interpreted)
1553   Interpreter::_rethrow_exception_entry = __ pc();
1554   // Rexception_obj: exception
1555 
1556 #ifndef AARCH64
1557   // Clear interpreter_frame_last_sp.
1558   __ mov(Rtemp, 0);
1559   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
1560 #endif // !AARCH64
1561 
1562 #if R9_IS_SCRATCHED
1563   __ restore_method();
1564 #endif
1565   __ restore_bcp();
1566   __ restore_dispatch();
1567   __ restore_locals();
1568 
1569 #ifdef AARCH64
1570   __ restore_sp_after_call(Rtemp);
1571 #endif // AARCH64
1572 
1573   // Entry point for exceptions thrown within interpreter code
1574   Interpreter::_throw_exception_entry = __ pc();
1575 
1576   // expression stack is undefined here
1577   // Rexception_obj: exception
1578   // Rbcp: exception bcp
1579   __ verify_oop(Rexception_obj);
1580 
1581   // expression stack must be empty before entering the VM in case of an exception
1582   __ empty_expression_stack();
1583   // find exception handler address and preserve exception oop
1584   __ mov(R1, Rexception_obj);
1585   __ call_VM(Rexception_obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), R1);
1586   // R0: exception handler entry point
1587   // Rexception_obj: preserved exception oop
1588   // Rbcp: bcp for exception handler
1589   __ push_ptr(Rexception_obj);                    // push exception which is now the only value on the stack
1590   __ jump(R0);                                    // jump to exception handler (may be _remove_activation_entry!)
1591 
1592   // If the exception is not handled in the current frame the frame is removed and
1593   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
1594   //
1595   // Note: At this point the bci is still the bxi for the instruction which caused
1596   //       the exception and the expression stack is empty. Thus, for any VM calls
1597   //       at this point, GC will find a legal oop map (with empty expression stack).
1598 
1599   // In current activation
1600   // tos: exception
1601   // Rbcp: exception bcp
1602 
1603   //
1604   // JVMTI PopFrame support
1605   //
1606    Interpreter::_remove_activation_preserving_args_entry = __ pc();
1607 
1608 #ifdef AARCH64
1609   __ restore_sp_after_call(Rtemp); // restore SP to extended SP
1610 #endif // AARCH64
1611 
1612   __ empty_expression_stack();
1613 
1614   // Set the popframe_processing bit in _popframe_condition indicating that we are
1615   // currently handling popframe, so that call_VMs that may happen later do not trigger new
1616   // popframe handling cycles.
1617 
1618   __ ldr_s32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset()));
1619   __ orr(Rtemp, Rtemp, (unsigned)JavaThread::popframe_processing_bit);
1620   __ str_32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset()));
1621 
1622   {
1623     // Check to see whether we are returning to a deoptimized frame.
1624     // (The PopFrame call ensures that the caller of the popped frame is
1625     // either interpreted or compiled and deoptimizes it if compiled.)
1626     // In this case, we can't call dispatch_next() after the frame is
1627     // popped, but instead must save the incoming arguments and restore
1628     // them after deoptimization has occurred.
1629     //
1630     // Note that we don't compare the return PC against the
1631     // deoptimization blob's unpack entry because of the presence of
1632     // adapter frames in C2.
1633     Label caller_not_deoptimized;
1634     __ ldr(R0, Address(FP, frame::return_addr_offset * wordSize));
1635     __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), R0);
1636     __ cbnz_32(R0, caller_not_deoptimized);
1637 #ifdef AARCH64
1638     __ NOT_TESTED();
1639 #endif
1640 
1641     // Compute size of arguments for saving when returning to deoptimized caller
1642     __ restore_method();
1643     __ ldr(R0, Address(Rmethod, Method::const_offset()));
1644     __ ldrh(R0, Address(R0, ConstMethod::size_of_parameters_offset()));
1645 
1646     __ logical_shift_left(R1, R0, Interpreter::logStackElementSize);
1647     // Save these arguments
1648     __ restore_locals();
1649     __ sub(R2, Rlocals, R1);
1650     __ add(R2, R2, wordSize);
1651     __ mov(R0, Rthread);
1652     __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), R0, R1, R2);
1653 
1654     __ remove_activation(vtos, LR,
1655                          /* throw_monitor_exception */ false,
1656                          /* install_monitor_exception */ false,
1657                          /* notify_jvmdi */ false);
1658 
1659     // Inform deoptimization that it is responsible for restoring these arguments
1660     __ mov(Rtemp, JavaThread::popframe_force_deopt_reexecution_bit);
1661     __ str_32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset()));
1662 
1663     // Continue in deoptimization handler
1664     __ ret();
1665 
1666     __ bind(caller_not_deoptimized);
1667   }
1668 
1669   __ remove_activation(vtos, R4,
1670                        /* throw_monitor_exception */ false,
1671                        /* install_monitor_exception */ false,
1672                        /* notify_jvmdi */ false);
1673 
1674 #ifndef AARCH64
1675   // Finish with popframe handling
1676   // A previous I2C followed by a deoptimization might have moved the
1677   // outgoing arguments further up the stack. PopFrame expects the
1678   // mutations to those outgoing arguments to be preserved and other
1679   // constraints basically require this frame to look exactly as
1680   // though it had previously invoked an interpreted activation with
1681   // no space between the top of the expression stack (current
1682   // last_sp) and the top of stack. Rather than force deopt to
1683   // maintain this kind of invariant all the time we call a small
1684   // fixup routine to move the mutated arguments onto the top of our
1685   // expression stack if necessary.
1686   __ mov(R1, SP);
1687   __ ldr(R2, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
1688   // PC must point into interpreter here
1689   __ set_last_Java_frame(SP, FP, true, Rtemp);
1690   __ mov(R0, Rthread);
1691   __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), R0, R1, R2);
1692   __ reset_last_Java_frame(Rtemp);
1693 #endif // !AARCH64
1694 
1695 #ifdef AARCH64
1696   __ restore_sp_after_call(Rtemp);
1697   __ restore_stack_top();
1698 #else
1699   // Restore the last_sp and null it out
1700   __ ldr(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
1701   __ mov(Rtemp, (int)NULL_WORD);
1702   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
1703 #endif // AARCH64
1704 
1705   __ restore_bcp();
1706   __ restore_dispatch();
1707   __ restore_locals();
1708   __ restore_method();
1709 
1710   // The method data pointer was incremented already during
1711   // call profiling. We have to restore the mdp for the current bcp.
1712   if (ProfileInterpreter) {
1713     __ set_method_data_pointer_for_bcp();
1714   }
1715 
1716   // Clear the popframe condition flag
1717   assert(JavaThread::popframe_inactive == 0, "adjust this code");
1718   __ str_32(__ zero_register(Rtemp), Address(Rthread, JavaThread::popframe_condition_offset()));
1719 
1720 #if INCLUDE_JVMTI
1721   {
1722     Label L_done;
1723 


1760   //
1761   // Rexception_obj: exception
1762   // Rexception_pc: return address/pc that threw exception
1763   // SP: expression stack of caller
1764   // FP: frame pointer of caller
1765   __ mov(c_rarg0, Rthread);
1766   __ mov(c_rarg1, Rexception_pc);
1767   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), c_rarg0, c_rarg1);
1768   // Note that an "issuing PC" is actually the next PC after the call
1769 
1770   __ jump(R0);                             // jump to exception handler of caller
1771 }
1772 
1773 
1774 //
1775 // JVMTI ForceEarlyReturn support
1776 //
1777 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
1778   address entry = __ pc();
1779 
1780 #ifdef AARCH64
1781   __ restore_sp_after_call(Rtemp); // restore SP to extended SP
1782 #endif // AARCH64
1783 
1784   __ restore_bcp();
1785   __ restore_dispatch();
1786   __ restore_locals();
1787 
1788   __ empty_expression_stack();
1789 
1790   __ load_earlyret_value(state);
1791 
1792   // Clear the earlyret state
1793   __ ldr(Rtemp, Address(Rthread, JavaThread::jvmti_thread_state_offset()));
1794 
1795   assert(JvmtiThreadState::earlyret_inactive == 0, "adjust this code");
1796   __ str_32(__ zero_register(R2), Address(Rtemp, JvmtiThreadState::earlyret_state_offset()));
1797 
1798   __ remove_activation(state, LR,
1799                        false, /* throw_monitor_exception */
1800                        false, /* install_monitor_exception */
1801                        true); /* notify_jvmdi */
1802 
1803 #ifndef AARCH64
1804   // According to interpreter calling conventions, result is returned in R0/R1,
1805   // so ftos (S0) and dtos (D0) are moved to R0/R1.
1806   // This conversion should be done after remove_activation, as it uses
1807   // push(state) & pop(state) to preserve return value.
1808   __ convert_tos_to_retval(state);
1809 #endif // !AARCH64
1810   __ ret();
1811 
1812   return entry;
1813 } // end of ForceEarlyReturn support
1814 
1815 
1816 //------------------------------------------------------------------------------------------------------------------------
1817 // Helper for vtos entry point generation
1818 
1819 void TemplateInterpreterGenerator::set_vtos_entry_points (Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
1820   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
1821   Label L;
1822 
1823 #ifdef __SOFTFP__
1824   dep = __ pc();                // fall through
1825 #else
1826   fep = __ pc(); __ push(ftos); __ b(L);
1827   dep = __ pc(); __ push(dtos); __ b(L);
1828 #endif // __SOFTFP__
1829 
1830   lep = __ pc(); __ push(ltos); __ b(L);
1831 
1832   if (AARCH64_ONLY(true) NOT_AARCH64(VerifyOops)) {  // can't share atos entry with itos on AArch64 or if VerifyOops
1833     aep = __ pc(); __ push(atos); __ b(L);
1834   } else {
1835     aep = __ pc();              // fall through
1836   }
1837 
1838 #ifdef __SOFTFP__
1839   fep = __ pc();                // fall through
1840 #endif // __SOFTFP__
1841 
1842   bep = cep = sep =             // fall through
1843   iep = __ pc(); __ push(itos); // fall through
1844   vep = __ pc(); __ bind(L);    // fall through
1845   generate_and_dispatch(t);
1846 }
1847 
1848 //------------------------------------------------------------------------------------------------------------------------
1849 
1850 // Non-product code
1851 #ifndef PRODUCT
1852 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
1853   address entry = __ pc();
1854 
1855   // prepare expression stack
1856   __ push(state);       // save tosca
1857 
1858   // pass tosca registers as arguments
1859   __ mov(R2, R0_tos);
1860 #ifdef AARCH64
1861   __ mov(R3, ZR);
1862 #else
1863   __ mov(R3, R1_tos_hi);
1864 #endif // AARCH64
1865   __ mov(R1, LR);       // save return address
1866 
1867   // call tracer
1868   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), R1, R2, R3);
1869 
1870   __ mov(LR, R0);       // restore return address
1871   __ pop(state);        // restore tosca
1872 
1873   // return
1874   __ ret();
1875 
1876   return entry;
1877 }
1878 
1879 
1880 void TemplateInterpreterGenerator::count_bytecode() {
1881   __ inc_global_counter((address) &BytecodeCounter::_counter_value, 0, Rtemp, R2_tmp, true);
1882 }
1883 
1884 




  48 #include "runtime/vframeArray.hpp"
  49 #include "utilities/align.hpp"
  50 #include "utilities/debug.hpp"
  51 #include "utilities/macros.hpp"
  52 
  53 // Size of interpreter code.  Increase if too small.  Interpreter will
  54 // fail with a guarantee ("not enough space for interpreter generation");
  55 // if too small.
  56 // Run with +PrintInterpreter to get the VM to print out the size.
  57 // Max size with JVMTI
  58 int TemplateInterpreter::InterpreterCodeSize = 180 * 1024;
  59 
  60 #define __ _masm->
  61 
  62 //------------------------------------------------------------------------------------------------------------------------
  63 
  64 address TemplateInterpreterGenerator::generate_slow_signature_handler() {
  65   address entry = __ pc();
  66 
  67   // callee-save register for saving LR, shared with generate_native_entry
  68   const Register Rsaved_ret_addr = Rtmp_save0;
  69 
  70   __ mov(Rsaved_ret_addr, LR);
  71 
  72   __ mov(R1, Rmethod);
  73   __ mov(R2, Rlocals);
  74   __ mov(R3, SP);
  75 


















  76 
  77   // Safer to save R9 (when scratched) since callers may have been
  78   // written assuming R9 survives. This is suboptimal but
  79   // probably not important for this slow case call site.
  80   // Note for R9 saving: slow_signature_handler may copy register
  81   // arguments above the current SP (passed as R3). It is safe for
  82   // call_VM to use push and pop to protect additional values on the
  83   // stack if needed.
  84   __ call_VM(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), true /* save R9 if needed*/);
  85   __ add(SP, SP, wordSize);     // Skip R0
  86   __ pop(RegisterSet(R1, R3));  // Load arguments passed in registers
  87 #ifdef __ABI_HARD__
  88   // Few alternatives to an always-load-FP-registers approach:
  89   // - parse method signature to detect FP arguments
  90   // - keep a counter/flag on a stack indicationg number of FP arguments in the method.
  91   // The later has been originally implemented and tested but a conditional path could
  92   // eliminate any gain imposed by avoiding 8 double word loads.
  93   __ fldmiad(SP, FloatRegisterSet(D0, 8), writeback);
  94 #endif // __ABI_HARD__

  95 
  96   __ ret(Rsaved_ret_addr);
  97 
  98   return entry;
  99 }
 100 
 101 
 102 //
 103 // Various method entries (that c++ and asm interpreter agree upon)
 104 //------------------------------------------------------------------------------------------------------------------------
 105 //
 106 //
 107 
 108 // Abstract method entry
 109 // Attempt to execute abstract method. Throw exception
 110 address TemplateInterpreterGenerator::generate_abstract_entry(void) {
 111   address entry_point = __ pc();
 112 




 113 
 114   __ empty_expression_stack();
 115 
 116   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
 117 
 118   DEBUG_ONLY(STOP("generate_abstract_entry");) // Should not reach here
 119   return entry_point;
 120 }
 121 
 122 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
 123   if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
 124 
 125   // TODO: ARM
 126   return NULL;
 127 
 128   address entry_point = __ pc();
 129   STOP("generate_math_entry");
 130   return entry_point;
 131 }
 132 


 234   }
 235 
 236   // throw exception
 237   __ b(Interpreter::throw_exception_entry());
 238 
 239   __ nop(); // to avoid filling CPU pipeline with invalid instructions
 240   __ nop();
 241   __ bind_literal(Lname);
 242   if (!pass_oop && (message != NULL)) {
 243     __ bind_literal(Lmessage);
 244   }
 245 
 246   return entry;
 247 }
 248 
 249 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
 250   address entry = __ pc();
 251 
 252   __ interp_verify_oop(R0_tos, state, __FILE__, __LINE__);
 253 




 254   // Restore stack bottom in case i2c adjusted stack
 255   __ ldr(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
 256   // and NULL it as marker that SP is now tos until next java call
 257   __ mov(Rtemp, (int)NULL_WORD);
 258   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));

 259 
 260   __ restore_method();
 261   __ restore_bcp();
 262   __ restore_dispatch();
 263   __ restore_locals();
 264 
 265   const Register Rcache = R2_tmp;
 266   const Register Rindex = R3_tmp;
 267   __ get_cache_and_index_at_bcp(Rcache, Rindex, 1, index_size);
 268 
 269   __ add(Rtemp, Rcache, AsmOperand(Rindex, lsl, LogBytesPerWord));
 270   __ ldrb(Rtemp, Address(Rtemp, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
 271   __ check_stack_top();
 272   __ add(Rstack_top, Rstack_top, AsmOperand(Rtemp, lsl, Interpreter::logStackElementSize));
 273 

 274   __ convert_retval_to_tos(state);

 275 
 276  __ check_and_handle_popframe();
 277  __ check_and_handle_earlyret();
 278 
 279   __ dispatch_next(state, step);
 280 
 281   return entry;
 282 }
 283 
 284 
 285 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) {
 286   address entry = __ pc();
 287 
 288   __ interp_verify_oop(R0_tos, state, __FILE__, __LINE__);
 289 




 290   // The stack is not extended by deopt but we must NULL last_sp as this
 291   // entry is like a "return".
 292   __ mov(Rtemp, 0);
 293   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));

 294 
 295   __ restore_method();
 296   __ restore_bcp();
 297   __ restore_dispatch();
 298   __ restore_locals();
 299 
 300   // handle exceptions
 301   { Label L;
 302     __ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset()));
 303     __ cbz(Rtemp, L);
 304     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
 305     __ should_not_reach_here();
 306     __ bind(L);
 307   }
 308 
 309   if (continuation == NULL) {
 310     __ dispatch_next(state, step);
 311   } else {
 312     __ jump_to_entry(continuation);
 313   }
 314 
 315   return entry;
 316 }
 317 
 318 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {


























 319   // Result handlers are not used on 32-bit ARM
 320   // since the returned value is already in appropriate format.
 321   __ should_not_reach_here();  // to avoid empty code block
 322 
 323   // The result handler non-zero indicates an object is returned and this is
 324   // used in the native entry code.
 325   return type == T_OBJECT ? (address)(-1) : NULL;

 326 }
 327 
 328 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
 329   address entry = __ pc();
 330   __ push(state);
 331   __ call_VM(noreg, runtime_entry);
 332 
 333   // load current bytecode
 334   __ ldrb(R3_bytecode, Address(Rbcp));
 335   __ dispatch_only_normal(vtos);
 336   return entry;
 337 }
 338 
 339 
 340 // Helpers for commoning out cases in the various type of method entries.
 341 //
 342 
 343 // increment invocation count & check for overflow
 344 //
 345 // Note: checking for negative value instead of overflow


 387 
 388     const Register Ricnt = R0_tmp;  // invocation counter
 389     const Register Rbcnt = R1_tmp;  // backedge counter
 390 
 391     __ get_method_counters(Rmethod, Rcounters, done);
 392 
 393     if (ProfileInterpreter) {
 394       const Register Riic = R1_tmp;
 395       __ ldr_s32(Riic, Address(Rcounters, MethodCounters::interpreter_invocation_counter_offset()));
 396       __ add(Riic, Riic, 1);
 397       __ str_32(Riic, Address(Rcounters, MethodCounters::interpreter_invocation_counter_offset()));
 398     }
 399 
 400     // Update standard invocation counters
 401 
 402     __ ldr_u32(Ricnt, invocation_counter);
 403     __ ldr_u32(Rbcnt, backedge_counter);
 404 
 405     __ add(Ricnt, Ricnt, InvocationCounter::count_increment);
 406 



 407     __ bic(Rbcnt, Rbcnt, ~InvocationCounter::count_mask_value); // mask out the status bits

 408 
 409     __ str_32(Ricnt, invocation_counter);            // save invocation count
 410     __ add(Ricnt, Ricnt, Rbcnt);                     // add both counters
 411 
 412     // profile_method is non-null only for interpreted method so
 413     // profile_method != NULL == !native_call
 414     // BytecodeInterpreter only calls for native so code is elided.
 415 
 416     if (ProfileInterpreter && profile_method != NULL) {
 417       assert(profile_method_continue != NULL, "should be non-null");
 418 
 419       // Test to see if we should create a method data oop
 420       // Reuse R1_tmp as we don't need backedge counters anymore.
 421       Address profile_limit(Rcounters, in_bytes(MethodCounters::interpreter_profile_limit_offset()));
 422       __ ldr_s32(R1_tmp, profile_limit);
 423       __ cmp_32(Ricnt, R1_tmp);
 424       __ b(*profile_method_continue, lt);
 425 
 426       // if no method data exists, go to profile_method
 427       __ test_method_data_pointer(R1_tmp, *profile_method);


 439   // InterpreterRuntime::frequency_counter_overflow takes one argument
 440   // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
 441   // The call returns the address of the verified entry point for the method or NULL
 442   // if the compilation did not complete (either went background or bailed out).
 443   __ mov(R1, (int)false);
 444   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), R1);
 445 
 446   // jump to the interpreted entry.
 447   __ b(do_continue);
 448 }
 449 
 450 void TemplateInterpreterGenerator::generate_stack_overflow_check(void) {
 451   // Check if we've got enough room on the stack for
 452   //  - overhead;
 453   //  - locals;
 454   //  - expression stack.
 455   //
 456   // Registers on entry:
 457   //
 458   // R3 = number of additional locals

 459   // Rthread
 460   // Rmethod
 461   // Registers used: R0, R1, R2, Rtemp.
 462 
 463   const Register Radditional_locals = R3;
 464   const Register RmaxStack = R2;
 465 
 466   // monitor entry size
 467   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
 468 
 469   // total overhead size: entry_size + (saved registers, thru expr stack bottom).
 470   // be sure to change this if you add/subtract anything to/from the overhead area
 471   const int overhead_size = (frame::sender_sp_offset - frame::interpreter_frame_initial_sp_offset)*wordSize + entry_size;
 472 
 473   // Pages reserved for VM runtime calls and subsequent Java calls.
 474   const int reserved_pages = JavaThread::stack_shadow_zone_size();
 475 
 476   // Thread::stack_size() includes guard pages, and they should not be touched.
 477   const int guard_pages = JavaThread::stack_guard_zone_size();
 478 
 479   __ ldr(R0, Address(Rthread, Thread::stack_base_offset()));
 480   __ ldr(R1, Address(Rthread, Thread::stack_size_offset()));

 481   __ ldr(Rtemp, Address(Rmethod, Method::const_offset()));
 482   __ ldrh(RmaxStack, Address(Rtemp, ConstMethod::max_stack_offset()));

 483   __ sub_slow(Rtemp, SP, overhead_size + reserved_pages + guard_pages + Method::extra_stack_words());
 484 
 485   // reserve space for additional locals
 486   __ sub(Rtemp, Rtemp, AsmOperand(Radditional_locals, lsl, Interpreter::logStackElementSize));
 487 
 488   // stack size
 489   __ sub(R0, R0, R1);
 490 
 491   // reserve space for expression stack
 492   __ sub(Rtemp, Rtemp, AsmOperand(RmaxStack, lsl, Interpreter::logStackElementSize));
 493 
 494   __ cmp(Rtemp, R0);
 495 







 496   __ mov(SP, Rsender_sp, ls);  // restore SP
 497   __ b(StubRoutines::throw_StackOverflowError_entry(), ls);

 498 }
 499 
 500 
 501 // Allocate monitor and lock method (asm interpreter)
 502 //
 503 void TemplateInterpreterGenerator::lock_method() {
 504   // synchronize method
 505 
 506   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
 507   assert ((entry_size % StackAlignmentInBytes) == 0, "should keep stack alignment");
 508 
 509   #ifdef ASSERT
 510     { Label L;
 511       __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
 512       __ tbnz(Rtemp, JVM_ACC_SYNCHRONIZED_BIT, L);
 513       __ stop("method doesn't need synchronization");
 514       __ bind(L);
 515     }
 516   #endif // ASSERT
 517 
 518   // get synchronization object
 519   { Label done;
 520     __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));




 521     __ tst(Rtemp, JVM_ACC_STATIC);
 522     __ ldr(R0, Address(Rlocals, Interpreter::local_offset_in_bytes(0)), eq); // get receiver (assume this is frequent case)
 523     __ b(done, eq);

 524     __ load_mirror(R0, Rmethod, Rtemp);
 525     __ bind(done);
 526   }
 527 
 528   // add space for monitor & lock
 529 






 530 
 531   __ sub(Rstack_top, Rstack_top, entry_size);
 532   __ check_stack_top_on_expansion();
 533                                               // add space for a monitor entry
 534   __ str(Rstack_top, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize));
 535                                               // set new monitor block top
 536   __ str(R0, Address(Rstack_top, BasicObjectLock::obj_offset_in_bytes()));
 537                                               // store object
 538   __ mov(R1, Rstack_top);                     // monitor entry address
 539   __ lock_object(R1);
 540 }
 541 




















































































 542 
 543 //
 544 // Generate a fixed interpreter frame. This is identical setup for interpreted methods
 545 // and for native methods hence the shared code.
 546 
 547 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
 548   // Generates the following stack layout:
 549   //
 550   // [ expr. stack bottom ]
 551   // [ saved Rbcp         ]
 552   // [ current Rlocals    ]
 553   // [ cache              ]
 554   // [ mdx                ]
 555   // [ Method*            ]
 556   // [ last_sp            ]
 557   // [ sender_sp          ]
 558   // [ saved FP           ] <--- FP
 559   // [ saved LR           ]
 560 
 561   // initialize fixed part of activation frame


 583 
 584   if (ProfileInterpreter) {
 585     __ ldr(Rtemp, Address(Rmethod, Method::method_data_offset()));
 586     __ tst(Rtemp, Rtemp);
 587     __ add(Rtemp, Rtemp, in_bytes(MethodData::data_offset()), ne);
 588     __ push(Rtemp);                                    // set the mdp (method data pointer)
 589   } else {
 590     __ push(R0);
 591   }
 592 
 593   __ ldr(Rtemp, Address(Rmethod, Method::const_offset()));
 594   __ ldr(Rtemp, Address(Rtemp, ConstMethod::constants_offset()));
 595   __ ldr(Rtemp, Address(Rtemp, ConstantPool::cache_offset_in_bytes()));
 596   __ push(Rtemp);                                      // set constant pool cache
 597   __ push(Rlocals);                                    // set locals pointer
 598   __ push(Rbcp);                                       // set bcp
 599   __ push(R0);                                         // reserve word for pointer to expression stack bottom
 600   __ str(SP, Address(SP, 0));                          // set expression stack bottom
 601 }
 602 

 603 
 604 // End of helpers
 605 
 606 //------------------------------------------------------------------------------------------------------------------------
 607 // Entry points
 608 //
 609 // Here we generate the various kind of entries into the interpreter.
 610 // The two main entry type are generic bytecode methods and native call method.
 611 // These both come in synchronized and non-synchronized versions but the
 612 // frame layout they create is very similar. The other method entry
 613 // types are really just special purpose entries that are really entry
 614 // and interpretation all in one. These are for trivial methods like
 615 // accessor, empty, or special math methods.
 616 //
 617 // When control flow reaches any of the entry types for the interpreter
 618 // the following holds ->
 619 //
 620 // Arguments:
 621 //
 622 // Rmethod: Method*
 623 // Rthread: thread
 624 // Rsender_sp:  sender sp
 625 // Rparams (SP on 32-bit ARM): pointer to method parameters
 626 //
 627 // LR: return address
 628 //
 629 // Stack layout immediately at entry
 630 //

 631 // [ parameter n        ] <--- Rparams (SP on 32-bit ARM)
 632 //   ...
 633 // [ parameter 1        ]
 634 // [ expression stack   ] (caller's java expression stack)
 635 
 636 // Assuming that we don't go to one of the trivial specialized
 637 // entries the stack will look like below when we are ready to execute
 638 // the first bytecode (or call the native routine). The register usage
 639 // will be as the template based interpreter expects.
 640 //
 641 // local variables follow incoming parameters immediately; i.e.
 642 // the return address is saved at the end of the locals.
 643 //

 644 // [ expr. stack        ] <--- Rstack_top (SP on 32-bit ARM)
 645 // [ monitor entry      ]
 646 //   ...
 647 // [ monitor entry      ]
 648 // [ expr. stack bottom ]
 649 // [ saved Rbcp         ]
 650 // [ current Rlocals    ]
 651 // [ cache              ]
 652 // [ mdx                ]
 653 // [ mirror             ]
 654 // [ Method*            ]
 655 //
 656 // 32-bit ARM:
 657 // [ last_sp            ]
 658 //




 659 // [ sender_sp          ]
 660 // [ saved FP           ] <--- FP
 661 // [ saved LR           ]
 662 // [ optional padding(*)]
 663 // [ local variable m   ]
 664 //   ...
 665 // [ local variable 1   ]
 666 // [ parameter n        ]
 667 //   ...
 668 // [ parameter 1        ] <--- Rlocals
 669 //


 670 
 671 address TemplateInterpreterGenerator::generate_Reference_get_entry(void) {
 672   // Code: _aload_0, _getfield, _areturn
 673   // parameter size = 1
 674   //
 675   // The code that gets generated by this routine is split into 2 parts:
 676   //    1. The "intrinsified" code performing an ON_WEAK_OOP_REF load,
 677   //    2. The slow path - which is an expansion of the regular method entry.
 678   //
 679   // Notes:-
 680   // * An intrinsic is always executed, where an ON_WEAK_OOP_REF load is performed.
 681   // * We may jump to the slow path iff the receiver is null. If the
 682   //   Reference object is null then we no longer perform an ON_WEAK_OOP_REF load
 683   //   Thus we can use the regular method entry code to generate the NPE.
 684   //
 685   // Rmethod: Method*
 686   // Rthread: thread
 687   // Rsender_sp: sender sp, must be preserved for slow path, set SP to it on fast path
 688   // Rparams: parameters
 689 


 726 //
 727 // Interpreter stub for calling a native method. (asm interpreter)
 728 // This sets up a somewhat different looking stack for calling the native method
 729 // than the typical interpreter frame setup.
 730 //
 731 
 732 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
 733   // determine code generation flags
 734   bool inc_counter  = UseCompiler || CountCompiledCalls || LogTouchedMethods;
 735 
 736   // Incoming registers:
 737   //
 738   // Rmethod: Method*
 739   // Rthread: thread
 740   // Rsender_sp: sender sp
 741   // Rparams: parameters
 742 
 743   address entry_point = __ pc();
 744 
 745   // Register allocation
 746   const Register Rsize_of_params = R6;
 747   const Register Rsig_handler    = Rtmp_save0;
 748   const Register Rnative_code    = Rtmp_save1;
 749   const Register Rresult_handler = R6;
 750 





 751   const Register Rsaved_result_lo = Rtmp_save0;  // R4
 752   const Register Rsaved_result_hi = Rtmp_save1;  // R5
 753   FloatRegister saved_result_fp;

 754 
 755 




 756   __ ldr(Rsize_of_params, Address(Rmethod, Method::const_offset()));
 757   __ ldrh(Rsize_of_params,  Address(Rsize_of_params, ConstMethod::size_of_parameters_offset()));

 758 
 759   // native calls don't need the stack size check since they have no expression stack
 760   // and the arguments are already on the stack and we only add a handful of words
 761   // to the stack
 762 
 763   // compute beginning of parameters (Rlocals)
 764   __ sub(Rlocals, Rparams, wordSize);
 765   __ add(Rlocals, Rlocals, AsmOperand(Rsize_of_params, lsl, Interpreter::logStackElementSize));
 766 









 767   // reserve stack space for oop_temp
 768   __ mov(R0, 0);
 769   __ push(R0);

 770 
 771   generate_fixed_frame(true); // Note: R9 is now saved in the frame
 772 
 773   // make sure method is native & not abstract
 774 #ifdef ASSERT
 775   __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
 776   {
 777     Label L;
 778     __ tbnz(Rtemp, JVM_ACC_NATIVE_BIT, L);
 779     __ stop("tried to execute non-native method as native");
 780     __ bind(L);
 781   }
 782   { Label L;
 783     __ tbz(Rtemp, JVM_ACC_ABSTRACT_BIT, L);
 784     __ stop("tried to execute abstract method in interpreter");
 785     __ bind(L);
 786   }
 787 #endif
 788 
 789   // increment invocation count & check for overflow


 845     __ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset()));
 846     __ cbnz(Rsig_handler, L);
 847     __ mov(R1, Rmethod);
 848     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1, true);
 849     __ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset()));
 850     __ bind(L);
 851   }
 852 
 853   {
 854     Label L;
 855     __ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset()));
 856     __ cbnz(Rnative_code, L);
 857     __ mov(R1, Rmethod);
 858     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1);
 859     __ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset()));
 860     __ bind(L);
 861   }
 862 
 863   // Allocate stack space for arguments
 864 









 865 
 866   // C functions need aligned stack
 867   __ bic(SP, SP, StackAlignmentInBytes - 1);
 868   // Multiply by BytesPerLong instead of BytesPerWord, because calling convention
 869   // may require empty slots due to long alignment, e.g. func(int, jlong, int, jlong)
 870   __ sub(SP, SP, AsmOperand(Rsize_of_params, lsl, LogBytesPerLong));
 871 
 872 #ifdef __ABI_HARD__
 873   // Allocate more stack space to accomodate all GP as well as FP registers:
 874   // 4 * wordSize
 875   // 8 * BytesPerLong
 876   int reg_arguments = align_up((4*wordSize) + (8*BytesPerLong), StackAlignmentInBytes);
 877 #else
 878   // Reserve at least 4 words on the stack for loading
 879   // of parameters passed on registers (R0-R3).
 880   // See generate_slow_signature_handler().
 881   // It is also used for JNIEnv & class additional parameters.
 882   int reg_arguments = 4 * wordSize;
 883 #endif // __ABI_HARD__

 884 
 885   __ sub(SP, SP, reg_arguments);
 886 
 887 
 888   // Note: signature handler blows R4 besides all scratch registers.
 889   // See AbstractInterpreterGenerator::generate_slow_signature_handler().
 890   __ call(Rsig_handler);
 891 #if R9_IS_SCRATCHED
 892   __ restore_method();
 893 #endif
 894   __ mov(Rresult_handler, R0);
 895 
 896   // Pass JNIEnv and mirror for static methods
 897   {
 898     Label L;
 899     __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
 900     __ add(R0, Rthread, in_bytes(JavaThread::jni_environment_offset()));
 901     __ tbz(Rtemp, JVM_ACC_STATIC_BIT, L);
 902     __ load_mirror(Rtemp, Rmethod, Rtemp);
 903     __ add(R1, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
 904     __ str(Rtemp, Address(R1, 0));
 905     __ bind(L);
 906   }
 907 
 908   __ set_last_Java_frame(SP, FP, true, Rtemp);
 909 
 910   // Changing state to _thread_in_native must be the last thing to do
 911   // before the jump to native code. At this moment stack must be
 912   // safepoint-safe and completely prepared for stack walking.
 913 #ifdef ASSERT
 914   {
 915     Label L;
 916     __ ldr_u32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
 917     __ cmp_32(Rtemp, _thread_in_Java);
 918     __ b(L, eq);
 919     __ stop("invalid thread state");
 920     __ bind(L);
 921   }
 922 #endif
 923 






 924   // Force all preceding writes to be observed prior to thread state change
 925   __ membar(MacroAssembler::StoreStore, Rtemp);
 926 
 927   __ mov(Rtemp, _thread_in_native);
 928   __ str(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));

 929 
 930   __ call(Rnative_code);
 931 #if R9_IS_SCRATCHED
 932   __ restore_method();
 933 #endif
 934 
 935   // Set FPSCR/FPCR to a known state
 936   if (AlwaysRestoreFPU) {
 937     __ restore_default_fp_mode();
 938   }
 939 
 940   // Do safepoint check
 941   __ mov(Rtemp, _thread_in_native_trans);
 942   __ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
 943 
 944     // Force this write out before the read below
 945   __ membar(MacroAssembler::StoreLoad, Rtemp);
 946 
 947   __ ldr_global_s32(Rtemp, SafepointSynchronize::address_of_state());
 948 
 949   // Protect the return value in the interleaved code: save it to callee-save registers.




 950   __ mov(Rsaved_result_lo, R0);
 951   __ mov(Rsaved_result_hi, R1);
 952 #ifdef __ABI_HARD__
 953   // preserve native FP result in a callee-saved register
 954   saved_result_fp = D8;
 955   __ fcpyd(saved_result_fp, D0);
 956 #else
 957   saved_result_fp = fnoreg;
 958 #endif // __ABI_HARD__

 959 
 960   {
 961     __ ldr_u32(R3, Address(Rthread, JavaThread::suspend_flags_offset()));
 962     __ cmp(Rtemp, SafepointSynchronize::_not_synchronized);
 963     __ cond_cmp(R3, 0, eq);
 964 







 965   __ mov(R0, Rthread, ne);
 966   __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans), relocInfo::none, ne);
 967 #if R9_IS_SCRATCHED
 968   __ restore_method();
 969 #endif

 970   }
 971 
 972   // Perform Native->Java thread transition
 973   __ mov(Rtemp, _thread_in_Java);
 974   __ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
 975 
 976   // Zero handles and last_java_sp
 977   __ reset_last_Java_frame(Rtemp);
 978   __ ldr(R3, Address(Rthread, JavaThread::active_handles_offset()));
 979   __ str_32(__ zero_register(Rtemp), Address(R3, JNIHandleBlock::top_offset_in_bytes()));
 980   if (CheckJNICalls) {
 981     __ str(__ zero_register(Rtemp), Address(Rthread, JavaThread::pending_jni_exception_check_fn_offset()));
 982   }
 983 
 984   // Unbox oop result, e.g. JNIHandles::resolve result if it's an oop.
 985   {
 986     Label Lnot_oop;





 987     // For ARM32, Rresult_handler is -1 for oop result, 0 otherwise.
 988     __ cbz(Rresult_handler, Lnot_oop);
 989     Register value = Rsaved_result_lo;

 990     __ resolve_jobject(value,   // value
 991                        Rtemp,   // tmp1
 992                        R1_tmp); // tmp2
 993     // Store resolved result in frame for GC visibility.
 994     __ str(value, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize));
 995     __ bind(Lnot_oop);
 996   }
 997 





 998 
 999   // reguard stack if StackOverflow exception happened while in native.
1000   {
1001     __ ldr_u32(Rtemp, Address(Rthread, JavaThread::stack_guard_state_offset()));
1002     __ cmp_32(Rtemp, JavaThread::stack_guard_yellow_reserved_disabled);






1003   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::none, eq);
1004 #if R9_IS_SCRATCHED
1005   __ restore_method();
1006 #endif

1007   }
1008 
1009   // check pending exceptions
1010   {
1011     __ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset()));







1012     __ cmp(Rtemp, 0);
1013     __ mov(Rexception_pc, PC, ne);
1014     __ b(StubRoutines::forward_exception_entry(), ne);

1015   }
1016 
1017   if (synchronized) {
1018     // address of first monitor
1019     __ sub(R1, FP, - (frame::interpreter_frame_monitor_block_bottom_offset - frame::interpreter_frame_monitor_size()) * wordSize);
1020     __ unlock_object(R1);
1021   }
1022 
1023   // jvmti/dtrace support
1024   // Note: This must happen _after_ handling/throwing any exceptions since
1025   //       the exception handler code notifies the runtime of method exits
1026   //       too. If this happens before, method entry/exit notifications are
1027   //       not properly paired (was bug - gri 11/22/99).



1028   __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI, true, Rsaved_result_lo, Rsaved_result_hi, saved_result_fp);

1029 
1030   // Restore the result. Oop result is restored from the stack.






1031   __ cmp(Rresult_handler, 0);
1032   __ ldr(R0, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize), ne);
1033   __ mov(R0, Rsaved_result_lo, eq);
1034   __ mov(R1, Rsaved_result_hi);
1035 
1036 #ifdef __ABI_HARD__
1037   // reload native FP result
1038   __ fcpyd(D0, D8);
1039 #endif // __ABI_HARD__
1040 
1041 #ifdef ASSERT
1042   if (VerifyOops) {
1043     Label L;
1044     __ cmp(Rresult_handler, 0);
1045     __ b(L, eq);
1046     __ verify_oop(R0);
1047     __ bind(L);
1048   }
1049 #endif // ASSERT

1050 
1051   // Restore FP/LR, sender_sp and return





1052   __ mov(Rtemp, FP);
1053   __ ldmia(FP, RegisterSet(FP) | RegisterSet(LR));
1054   __ ldr(SP, Address(Rtemp, frame::interpreter_frame_sender_sp_offset * wordSize));

1055 
1056   __ ret();
1057 
1058   if (inc_counter) {
1059     // Handle overflow of counter and compile method
1060     __ bind(invocation_counter_overflow);
1061     generate_counter_overflow(continue_after_compile);
1062   }
1063 
1064   return entry_point;
1065 }
1066 
1067 //
1068 // Generic interpreted method entry to (asm) interpreter
1069 //
1070 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) {
1071   // determine code generation flags
1072   bool inc_counter  = UseCompiler || CountCompiledCalls || LogTouchedMethods;
1073 
1074   // Rmethod: Method*
1075   // Rthread: thread
1076   // Rsender_sp: sender sp (could differ from SP if we were called via c2i)
1077   // Rparams: pointer to the last parameter in the stack
1078 
1079   address entry_point = __ pc();
1080 
1081   const Register RconstMethod = R3;
1082 




1083 
1084   __ ldr(RconstMethod, Address(Rmethod, Method::const_offset()));
1085 
1086   __ ldrh(R2, Address(RconstMethod, ConstMethod::size_of_parameters_offset()));
1087   __ ldrh(R3, Address(RconstMethod, ConstMethod::size_of_locals_offset()));
1088 
1089   // setup Rlocals
1090   __ sub(Rlocals, Rparams, wordSize);
1091   __ add(Rlocals, Rlocals, AsmOperand(R2, lsl, Interpreter::logStackElementSize));
1092 
1093   __ sub(R3, R3, R2); // number of additional locals
1094 











1095 
1096   // see if we've got enough room on the stack for locals plus overhead.
1097   generate_stack_overflow_check();
1098 



























1099   // allocate space for locals
1100   // explicitly initialize locals
1101 
1102   // Loop is unrolled 4 times
1103   Label loop;
1104   __ mov(R0, 0);
1105   __ bind(loop);
1106 
1107   // #1
1108   __ subs(R3, R3, 1);
1109   __ push(R0, ge);
1110 
1111   // #2
1112   __ subs(R3, R3, 1, ge);
1113   __ push(R0, ge);
1114 
1115   // #3
1116   __ subs(R3, R3, 1, ge);
1117   __ push(R0, ge);
1118 
1119   // #4
1120   __ subs(R3, R3, 1, ge);
1121   __ push(R0, ge);
1122 
1123   __ b(loop, gt);

1124 
1125   // initialize fixed part of activation frame
1126   generate_fixed_frame(false);
1127 
1128   __ restore_dispatch();
1129 
1130   // make sure method is not native & not abstract
1131 #ifdef ASSERT
1132   __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
1133   {
1134     Label L;
1135     __ tbz(Rtemp, JVM_ACC_NATIVE_BIT, L);
1136     __ stop("tried to execute native method as non-native");
1137     __ bind(L);
1138   }
1139   { Label L;
1140     __ tbz(Rtemp, JVM_ACC_ABSTRACT_BIT, L);
1141     __ stop("tried to execute abstract method in interpreter");
1142     __ bind(L);
1143   }


1218 
1219       __ b(profile_method_continue);
1220     }
1221 
1222     // Handle overflow of counter and compile method
1223     __ bind(invocation_counter_overflow);
1224     generate_counter_overflow(continue_after_compile);
1225   }
1226 
1227   return entry_point;
1228 }
1229 
1230 //------------------------------------------------------------------------------------------------------------------------
1231 // Exceptions
1232 
1233 void TemplateInterpreterGenerator::generate_throw_exception() {
1234   // Entry point in previous activation (i.e., if the caller was interpreted)
1235   Interpreter::_rethrow_exception_entry = __ pc();
1236   // Rexception_obj: exception
1237 

1238   // Clear interpreter_frame_last_sp.
1239   __ mov(Rtemp, 0);
1240   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));

1241 
1242 #if R9_IS_SCRATCHED
1243   __ restore_method();
1244 #endif
1245   __ restore_bcp();
1246   __ restore_dispatch();
1247   __ restore_locals();
1248 



1249 
1250   // Entry point for exceptions thrown within interpreter code
1251   Interpreter::_throw_exception_entry = __ pc();
1252 
1253   // expression stack is undefined here
1254   // Rexception_obj: exception
1255   // Rbcp: exception bcp
1256   __ verify_oop(Rexception_obj);
1257 
1258   // expression stack must be empty before entering the VM in case of an exception
1259   __ empty_expression_stack();
1260   // find exception handler address and preserve exception oop
1261   __ mov(R1, Rexception_obj);
1262   __ call_VM(Rexception_obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), R1);
1263   // R0: exception handler entry point
1264   // Rexception_obj: preserved exception oop
1265   // Rbcp: bcp for exception handler
1266   __ push_ptr(Rexception_obj);                    // push exception which is now the only value on the stack
1267   __ jump(R0);                                    // jump to exception handler (may be _remove_activation_entry!)
1268 
1269   // If the exception is not handled in the current frame the frame is removed and
1270   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
1271   //
1272   // Note: At this point the bci is still the bxi for the instruction which caused
1273   //       the exception and the expression stack is empty. Thus, for any VM calls
1274   //       at this point, GC will find a legal oop map (with empty expression stack).
1275 
1276   // In current activation
1277   // tos: exception
1278   // Rbcp: exception bcp
1279 
1280   //
1281   // JVMTI PopFrame support
1282   //
1283    Interpreter::_remove_activation_preserving_args_entry = __ pc();
1284 



1285 
1286   __ empty_expression_stack();
1287 
1288   // Set the popframe_processing bit in _popframe_condition indicating that we are
1289   // currently handling popframe, so that call_VMs that may happen later do not trigger new
1290   // popframe handling cycles.
1291 
1292   __ ldr_s32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset()));
1293   __ orr(Rtemp, Rtemp, (unsigned)JavaThread::popframe_processing_bit);
1294   __ str_32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset()));
1295 
1296   {
1297     // Check to see whether we are returning to a deoptimized frame.
1298     // (The PopFrame call ensures that the caller of the popped frame is
1299     // either interpreted or compiled and deoptimizes it if compiled.)
1300     // In this case, we can't call dispatch_next() after the frame is
1301     // popped, but instead must save the incoming arguments and restore
1302     // them after deoptimization has occurred.
1303     //
1304     // Note that we don't compare the return PC against the
1305     // deoptimization blob's unpack entry because of the presence of
1306     // adapter frames in C2.
1307     Label caller_not_deoptimized;
1308     __ ldr(R0, Address(FP, frame::return_addr_offset * wordSize));
1309     __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), R0);
1310     __ cbnz_32(R0, caller_not_deoptimized);



1311 
1312     // Compute size of arguments for saving when returning to deoptimized caller
1313     __ restore_method();
1314     __ ldr(R0, Address(Rmethod, Method::const_offset()));
1315     __ ldrh(R0, Address(R0, ConstMethod::size_of_parameters_offset()));
1316 
1317     __ logical_shift_left(R1, R0, Interpreter::logStackElementSize);
1318     // Save these arguments
1319     __ restore_locals();
1320     __ sub(R2, Rlocals, R1);
1321     __ add(R2, R2, wordSize);
1322     __ mov(R0, Rthread);
1323     __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), R0, R1, R2);
1324 
1325     __ remove_activation(vtos, LR,
1326                          /* throw_monitor_exception */ false,
1327                          /* install_monitor_exception */ false,
1328                          /* notify_jvmdi */ false);
1329 
1330     // Inform deoptimization that it is responsible for restoring these arguments
1331     __ mov(Rtemp, JavaThread::popframe_force_deopt_reexecution_bit);
1332     __ str_32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset()));
1333 
1334     // Continue in deoptimization handler
1335     __ ret();
1336 
1337     __ bind(caller_not_deoptimized);
1338   }
1339 
1340   __ remove_activation(vtos, R4,
1341                        /* throw_monitor_exception */ false,
1342                        /* install_monitor_exception */ false,
1343                        /* notify_jvmdi */ false);
1344 

1345   // Finish with popframe handling
1346   // A previous I2C followed by a deoptimization might have moved the
1347   // outgoing arguments further up the stack. PopFrame expects the
1348   // mutations to those outgoing arguments to be preserved and other
1349   // constraints basically require this frame to look exactly as
1350   // though it had previously invoked an interpreted activation with
1351   // no space between the top of the expression stack (current
1352   // last_sp) and the top of stack. Rather than force deopt to
1353   // maintain this kind of invariant all the time we call a small
1354   // fixup routine to move the mutated arguments onto the top of our
1355   // expression stack if necessary.
1356   __ mov(R1, SP);
1357   __ ldr(R2, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
1358   // PC must point into interpreter here
1359   __ set_last_Java_frame(SP, FP, true, Rtemp);
1360   __ mov(R0, Rthread);
1361   __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), R0, R1, R2);
1362   __ reset_last_Java_frame(Rtemp);

1363 




1364   // Restore the last_sp and null it out
1365   __ ldr(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
1366   __ mov(Rtemp, (int)NULL_WORD);
1367   __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));

1368 
1369   __ restore_bcp();
1370   __ restore_dispatch();
1371   __ restore_locals();
1372   __ restore_method();
1373 
1374   // The method data pointer was incremented already during
1375   // call profiling. We have to restore the mdp for the current bcp.
1376   if (ProfileInterpreter) {
1377     __ set_method_data_pointer_for_bcp();
1378   }
1379 
1380   // Clear the popframe condition flag
1381   assert(JavaThread::popframe_inactive == 0, "adjust this code");
1382   __ str_32(__ zero_register(Rtemp), Address(Rthread, JavaThread::popframe_condition_offset()));
1383 
1384 #if INCLUDE_JVMTI
1385   {
1386     Label L_done;
1387 


1424   //
1425   // Rexception_obj: exception
1426   // Rexception_pc: return address/pc that threw exception
1427   // SP: expression stack of caller
1428   // FP: frame pointer of caller
1429   __ mov(c_rarg0, Rthread);
1430   __ mov(c_rarg1, Rexception_pc);
1431   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), c_rarg0, c_rarg1);
1432   // Note that an "issuing PC" is actually the next PC after the call
1433 
1434   __ jump(R0);                             // jump to exception handler of caller
1435 }
1436 
1437 
1438 //
1439 // JVMTI ForceEarlyReturn support
1440 //
1441 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
1442   address entry = __ pc();
1443 



1444 
1445   __ restore_bcp();
1446   __ restore_dispatch();
1447   __ restore_locals();
1448 
1449   __ empty_expression_stack();
1450 
1451   __ load_earlyret_value(state);
1452 
1453   // Clear the earlyret state
1454   __ ldr(Rtemp, Address(Rthread, JavaThread::jvmti_thread_state_offset()));
1455 
1456   assert(JvmtiThreadState::earlyret_inactive == 0, "adjust this code");
1457   __ str_32(__ zero_register(R2), Address(Rtemp, JvmtiThreadState::earlyret_state_offset()));
1458 
1459   __ remove_activation(state, LR,
1460                        false, /* throw_monitor_exception */
1461                        false, /* install_monitor_exception */
1462                        true); /* notify_jvmdi */
1463 

1464   // According to interpreter calling conventions, result is returned in R0/R1,
1465   // so ftos (S0) and dtos (D0) are moved to R0/R1.
1466   // This conversion should be done after remove_activation, as it uses
1467   // push(state) & pop(state) to preserve return value.
1468   __ convert_tos_to_retval(state);

1469   __ ret();
1470 
1471   return entry;
1472 } // end of ForceEarlyReturn support
1473 
1474 
1475 //------------------------------------------------------------------------------------------------------------------------
1476 // Helper for vtos entry point generation
1477 
1478 void TemplateInterpreterGenerator::set_vtos_entry_points (Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
1479   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
1480   Label L;
1481 
1482 #ifdef __SOFTFP__
1483   dep = __ pc();                // fall through
1484 #else
1485   fep = __ pc(); __ push(ftos); __ b(L);
1486   dep = __ pc(); __ push(dtos); __ b(L);
1487 #endif // __SOFTFP__
1488 
1489   lep = __ pc(); __ push(ltos); __ b(L);
1490 
1491   if (VerifyOops) {  // can't share atos entry if VerifyOops
1492     aep = __ pc(); __ push(atos); __ b(L);
1493   } else {
1494     aep = __ pc();              // fall through
1495   }
1496 
1497 #ifdef __SOFTFP__
1498   fep = __ pc();                // fall through
1499 #endif // __SOFTFP__
1500 
1501   bep = cep = sep =             // fall through
1502   iep = __ pc(); __ push(itos); // fall through
1503   vep = __ pc(); __ bind(L);    // fall through
1504   generate_and_dispatch(t);
1505 }
1506 
1507 //------------------------------------------------------------------------------------------------------------------------
1508 
1509 // Non-product code
1510 #ifndef PRODUCT
1511 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
1512   address entry = __ pc();
1513 
1514   // prepare expression stack
1515   __ push(state);       // save tosca
1516 
1517   // pass tosca registers as arguments
1518   __ mov(R2, R0_tos);



1519   __ mov(R3, R1_tos_hi);

1520   __ mov(R1, LR);       // save return address
1521 
1522   // call tracer
1523   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), R1, R2, R3);
1524 
1525   __ mov(LR, R0);       // restore return address
1526   __ pop(state);        // restore tosca
1527 
1528   // return
1529   __ ret();
1530 
1531   return entry;
1532 }
1533 
1534 
1535 void TemplateInterpreterGenerator::count_bytecode() {
1536   __ inc_global_counter((address) &BytecodeCounter::_counter_value, 0, Rtemp, R2_tmp, true);
1537 }
1538 
1539 


src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File