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