< prev index next >

src/hotspot/cpu/x86/stubGenerator_x86_64.cpp

Print this page

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 

  25 #include "asm/macroAssembler.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "classfile/vmIntrinsics.hpp"
  28 #include "compiler/oopMap.hpp"
  29 #include "gc/shared/barrierSet.hpp"
  30 #include "gc/shared/barrierSetAssembler.hpp"
  31 #include "gc/shared/barrierSetNMethod.hpp"
  32 #include "gc/shared/gc_globals.hpp"
  33 #include "memory/universe.hpp"
  34 #include "prims/jvmtiExport.hpp"
  35 #include "prims/upcallLinker.hpp"
  36 #include "runtime/arguments.hpp"
  37 #include "runtime/continuationEntry.hpp"
  38 #include "runtime/javaThread.hpp"
  39 #include "runtime/sharedRuntime.hpp"
  40 #include "runtime/stubRoutines.hpp"


  41 #include "stubGenerator_x86_64.hpp"
  42 #ifdef COMPILER2
  43 #include "opto/runtime.hpp"
  44 #include "opto/c2_globals.hpp"
  45 #endif
  46 #if INCLUDE_JVMCI
  47 #include "jvmci/jvmci_globals.hpp"
  48 #endif
  49 
  50 // For a more detailed description of the stub routine structure
  51 // see the comment in stubRoutines.hpp
  52 
  53 #define __ _masm->
  54 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8)
  55 
  56 #ifdef PRODUCT
  57 #define BLOCK_COMMENT(str) /* nothing */
  58 #else
  59 #define BLOCK_COMMENT(str) __ block_comment(str)
  60 #endif // PRODUCT

 284   __ BIND(loop);
 285   __ movptr(rax, Address(c_rarg2, 0));// get parameter
 286   __ addptr(c_rarg2, wordSize);       // advance to next parameter
 287   __ decrementl(c_rarg1);             // decrement counter
 288   __ push(rax);                       // pass parameter
 289   __ jcc(Assembler::notZero, loop);
 290 
 291   // call Java function
 292   __ BIND(parameters_done);
 293   __ movptr(rbx, method);             // get Method*
 294   __ movptr(c_rarg1, entry_point);    // get entry_point
 295   __ mov(r13, rsp);                   // set sender sp
 296   BLOCK_COMMENT("call Java function");
 297   __ call(c_rarg1);
 298 
 299   BLOCK_COMMENT("call_stub_return_address:");
 300   return_address = __ pc();
 301 
 302   // store result depending on type (everything that is not
 303   // T_OBJECT, T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT)
 304   __ movptr(c_rarg0, result);
 305   Label is_long, is_float, is_double, exit;
 306   __ movl(c_rarg1, result_type);
 307   __ cmpl(c_rarg1, T_OBJECT);


 308   __ jcc(Assembler::equal, is_long);
 309   __ cmpl(c_rarg1, T_LONG);
 310   __ jcc(Assembler::equal, is_long);
 311   __ cmpl(c_rarg1, T_FLOAT);
 312   __ jcc(Assembler::equal, is_float);
 313   __ cmpl(c_rarg1, T_DOUBLE);
 314   __ jcc(Assembler::equal, is_double);
 315 #ifdef ASSERT
 316   // make sure the type is INT
 317   {
 318     Label L;
 319     __ cmpl(c_rarg1, T_INT);
 320     __ jcc(Assembler::equal, L);
 321     __ stop("StubRoutines::call_stub: unexpected result type");
 322     __ bind(L);
 323   }
 324 #endif
 325 
 326   // handle T_INT case
 327   __ movl(Address(c_rarg0, 0), rax);
 328 
 329   __ BIND(exit);
 330 
 331   // pop parameters
 332   __ lea(rsp, rsp_after_call);
 333 
 334 #ifdef ASSERT
 335   // verify that threads correspond
 336   {
 337    Label L1, L2, L3;
 338     __ cmpptr(r15_thread, thread);
 339     __ jcc(Assembler::equal, L1);
 340     __ stop("StubRoutines::call_stub: r15_thread is corrupted");
 341     __ bind(L1);
 342     __ get_thread_slow(rbx);
 343     __ cmpptr(r15_thread, thread);
 344     __ jcc(Assembler::equal, L2);
 345     __ stop("StubRoutines::call_stub: r15_thread is modified by call");
 346     __ bind(L2);
 347     __ cmpptr(r15_thread, rbx);

 365   __ movptr(r13, r13_save);
 366   __ movptr(r12, r12_save);
 367   __ movptr(rbx, rbx_save);
 368 
 369 #ifdef _WIN64
 370   __ movptr(rdi, rdi_save);
 371   __ movptr(rsi, rsi_save);
 372 #else
 373   __ ldmxcsr(mxcsr_save);
 374 #endif
 375 
 376   // restore rsp
 377   __ addptr(rsp, -rsp_after_call_off * wordSize);
 378 
 379   // return
 380   __ vzeroupper();
 381   __ pop(rbp);
 382   __ ret(0);
 383 
 384   // handle return types different from T_INT













 385   __ BIND(is_long);
 386   __ movq(Address(c_rarg0, 0), rax);
 387   __ jmp(exit);
 388 
 389   __ BIND(is_float);
 390   __ movflt(Address(c_rarg0, 0), xmm0);
 391   __ jmp(exit);
 392 
 393   __ BIND(is_double);
 394   __ movdbl(Address(c_rarg0, 0), xmm0);
 395   __ jmp(exit);
 396 
 397   return start;
 398 }
 399 
 400 // Return point for a Java call if there's an exception thrown in
 401 // Java code.  The exception is caught and transformed into a
 402 // pending exception stored in JavaThread that can be tested from
 403 // within the VM.
 404 //
 405 // Note: Usually the parameters are removed by the callee. In case
 406 // of an exception crossing an activation frame boundary, that is
 407 // not the case if the callee is compiled code => need to setup the
 408 // rsp.
 409 //
 410 // rax: exception oop
 411 
 412 address StubGenerator::generate_catch_exception() {
 413   StubId stub_id = StubId::stubgen_catch_exception_id;
 414   StubCodeMark mark(this, stub_id);

3732 *  Output:
3733 *        rax   - float16  jshort
3734 */
3735 address StubGenerator::generate_floatToFloat16() {
3736   StubId stub_id = StubId::stubgen_f2hf_id;
3737   StubCodeMark mark(this, stub_id);
3738 
3739   address start = __ pc();
3740 
3741   BLOCK_COMMENT("Entry:");
3742   // No need for RuntimeStub frame since it is called only during JIT compilation
3743 
3744   // Convert and put result into rax
3745   __ flt_to_flt16(rax, xmm0, xmm1);
3746 
3747   __ ret(0);
3748 
3749   return start;
3750 }
3751 





























































3752 address StubGenerator::generate_cont_thaw(StubId stub_id) {
3753   if (!Continuations::enabled()) return nullptr;
3754 
3755   bool return_barrier;
3756   bool return_barrier_exception;
3757   Continuation::thaw_kind kind;
3758 
3759   switch (stub_id) {
3760   case StubId::stubgen_cont_thaw_id:
3761     return_barrier = false;
3762     return_barrier_exception = false;
3763     kind = Continuation::thaw_top;
3764     break;
3765   case StubId::stubgen_cont_returnBarrier_id:
3766     return_barrier = true;
3767     return_barrier_exception = false;
3768     kind = Continuation::thaw_return_barrier;
3769     break;
3770   case StubId::stubgen_cont_returnBarrierExc_id:
3771     return_barrier = true;

3783   if (!return_barrier) {
3784     // Pop return address. If we don't do this, we get a drift,
3785     // where the bottom-most frozen frame continuously grows.
3786     __ pop(c_rarg3);
3787   } else {
3788     __ movptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset()));
3789   }
3790 
3791 #ifdef ASSERT
3792   {
3793     Label L_good_sp;
3794     __ cmpptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset()));
3795     __ jcc(Assembler::equal, L_good_sp);
3796     __ stop("Incorrect rsp at thaw entry");
3797     __ BIND(L_good_sp);
3798   }
3799 #endif // ASSERT
3800 
3801   if (return_barrier) {
3802     // Preserve possible return value from a method returning to the return barrier.
3803     __ push_ppx(rax);
3804     __ push_d(xmm0);
3805   }
3806 
3807   __ movptr(c_rarg0, r15_thread);
3808   __ movptr(c_rarg1, (return_barrier ? 1 : 0));
3809   __ call_VM_leaf(CAST_FROM_FN_PTR(address, Continuation::prepare_thaw), 2);
3810   __ movptr(rbx, rax);
3811 
3812   if (return_barrier) {
3813     // Restore return value from a method returning to the return barrier.
3814     // No safepoint in the call to thaw, so even an oop return value should be OK.
3815     __ pop_d(xmm0);
3816     __ pop_ppx(rax);
3817   }
3818 
3819 #ifdef ASSERT
3820   {
3821     Label L_good_sp;
3822     __ cmpptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset()));
3823     __ jcc(Assembler::equal, L_good_sp);
3824     __ stop("Incorrect rsp after prepare thaw");
3825     __ BIND(L_good_sp);
3826   }
3827 #endif // ASSERT
3828 
3829   // rbx contains the size of the frames to thaw, 0 if overflow or no more frames
3830   Label L_thaw_success;
3831   __ testptr(rbx, rbx);
3832   __ jccb(Assembler::notZero, L_thaw_success);
3833   __ jump(RuntimeAddress(SharedRuntime::throw_StackOverflowError_entry()));
3834   __ bind(L_thaw_success);
3835 
3836   // Make room for the thawed frames and align the stack.
3837   __ subptr(rsp, rbx);
3838   __ andptr(rsp, -StackAlignmentInBytes);
3839 
3840   if (return_barrier) {
3841     // Preserve possible return value from a method returning to the return barrier. (Again.)
3842     __ push_ppx(rax);
3843     __ push_d(xmm0);
3844   }
3845 
3846   // If we want, we can templatize thaw by kind, and have three different entries.
3847   __ movptr(c_rarg0, r15_thread);
3848   __ movptr(c_rarg1, kind);
3849   __ call_VM_leaf(Continuation::thaw_entry(), 2);
3850   __ movptr(rbx, rax);
3851 
3852   if (return_barrier) {
3853     // Restore return value from a method returning to the return barrier. (Again.)
3854     // No safepoint in the call to thaw, so even an oop return value should be OK.
3855     __ pop_d(xmm0);
3856     __ pop_ppx(rax);
3857   } else {
3858     // Return 0 (success) from doYield.
3859     __ xorptr(rax, rax);
3860   }
3861 
3862   // After thawing, rbx is the SP of the yielding frame.
3863   // Move there, and then to saved RBP slot.
3864   __ movptr(rsp, rbx);
3865   __ subptr(rsp, 2*wordSize);
3866 
3867   if (return_barrier_exception) {
3868     __ movptr(c_rarg0, r15_thread);
3869     __ movptr(c_rarg1, Address(rsp, wordSize)); // return address
3870 
3871     // rax still holds the original exception oop, save it before the call
3872     __ push_ppx(rax);
3873 
3874     __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), 2);
3875     __ movptr(rbx, rax);
3876 

4043 
4044 void StubGenerator::generate_initial_stubs() {
4045   // Generates all stubs and initializes the entry points
4046 
4047   // This platform-specific settings are needed by generate_call_stub()
4048   create_control_words();
4049 
4050   // Initialize table for unsafe copy memeory check.
4051   if (UnsafeMemoryAccess::_table == nullptr) {
4052     UnsafeMemoryAccess::create_table(16 + 4); // 16 for copyMemory; 4 for setMemory
4053   }
4054 
4055   // entry points that exist in all platforms Note: This is code
4056   // that could be shared among different platforms - however the
4057   // benefit seems to be smaller than the disadvantage of having a
4058   // much more complicated generator structure. See also comment in
4059   // stubRoutines.hpp.
4060 
4061   StubRoutines::_forward_exception_entry = generate_forward_exception();
4062 










4063   StubRoutines::_call_stub_entry =
4064     generate_call_stub(StubRoutines::_call_stub_return_address);
4065 
4066   // is referenced by megamorphic call
4067   StubRoutines::_catch_exception_entry = generate_catch_exception();
4068 
4069   // platform dependent
4070   StubRoutines::x86::_verify_mxcsr_entry    = generate_verify_mxcsr();
4071 
4072   StubRoutines::x86::_f2i_fixup             = generate_f2i_fixup();
4073   StubRoutines::x86::_f2l_fixup             = generate_f2l_fixup();
4074   StubRoutines::x86::_d2i_fixup             = generate_d2i_fixup();
4075   StubRoutines::x86::_d2l_fixup             = generate_d2l_fixup();
4076 
4077   StubRoutines::x86::_float_sign_mask       = generate_fp_mask(StubId::stubgen_float_sign_mask_id,  0x7FFFFFFF7FFFFFFF);
4078   StubRoutines::x86::_float_sign_flip       = generate_fp_mask(StubId::stubgen_float_sign_flip_id,  0x8000000080000000);
4079   StubRoutines::x86::_double_sign_mask      = generate_fp_mask(StubId::stubgen_double_sign_mask_id, 0x7FFFFFFFFFFFFFFF);
4080   StubRoutines::x86::_double_sign_flip      = generate_fp_mask(StubId::stubgen_double_sign_flip_id, 0x8000000000000000);
4081 
4082   if (UseCRC32Intrinsics) {

4086   if (UseCRC32CIntrinsics) {
4087     bool supports_clmul = VM_Version::supports_clmul();
4088     StubRoutines::_updateBytesCRC32C = generate_updateBytesCRC32C(supports_clmul);
4089   }
4090 
4091   if (VM_Version::supports_float16()) {
4092     // For results consistency both intrinsics should be enabled.
4093     // vmIntrinsics checks InlineIntrinsics flag, no need to check it here.
4094     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_float16ToFloat) &&
4095         vmIntrinsics::is_intrinsic_available(vmIntrinsics::_floatToFloat16)) {
4096       StubRoutines::_hf2f = generate_float16ToFloat();
4097       StubRoutines::_f2hf = generate_floatToFloat16();
4098     }
4099   }
4100 
4101   generate_libm_stubs();
4102 
4103   StubRoutines::_fmod = generate_libmFmod(); // from stubGenerator_x86_64_fmod.cpp
4104 }
4105 
















































































































































4106 void StubGenerator::generate_continuation_stubs() {
4107   // Continuation stubs:
4108   StubRoutines::_cont_thaw          = generate_cont_thaw();
4109   StubRoutines::_cont_returnBarrier = generate_cont_returnBarrier();
4110   StubRoutines::_cont_returnBarrierExc = generate_cont_returnBarrier_exception();
4111   StubRoutines::_cont_preempt_stub = generate_cont_preempt_stub();
4112 }
4113 
4114 void StubGenerator::generate_final_stubs() {
4115   // Generates the rest of stubs and initializes the entry points
4116 
4117   // support for verify_oop (must happen after universe_init)
4118   if (VerifyOops) {
4119     StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop();
4120   }
4121 
4122   // arraycopy stubs used by compilers
4123   generate_arraycopy_stubs();
4124 
4125   StubRoutines::_method_entry_barrier = generate_method_entry_barrier();

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "asm/assembler.hpp"
  26 #include "asm/macroAssembler.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/vmIntrinsics.hpp"
  29 #include "compiler/oopMap.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/barrierSetAssembler.hpp"
  32 #include "gc/shared/barrierSetNMethod.hpp"
  33 #include "gc/shared/gc_globals.hpp"
  34 #include "memory/universe.hpp"
  35 #include "prims/jvmtiExport.hpp"
  36 #include "prims/upcallLinker.hpp"
  37 #include "runtime/arguments.hpp"
  38 #include "runtime/continuationEntry.hpp"
  39 #include "runtime/javaThread.hpp"
  40 #include "runtime/sharedRuntime.hpp"
  41 #include "runtime/stubRoutines.hpp"
  42 #include "utilities/macros.hpp"
  43 #include "vmreg_x86.inline.hpp"
  44 #include "stubGenerator_x86_64.hpp"
  45 #ifdef COMPILER2
  46 #include "opto/runtime.hpp"
  47 #include "opto/c2_globals.hpp"
  48 #endif
  49 #if INCLUDE_JVMCI
  50 #include "jvmci/jvmci_globals.hpp"
  51 #endif
  52 
  53 // For a more detailed description of the stub routine structure
  54 // see the comment in stubRoutines.hpp
  55 
  56 #define __ _masm->
  57 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8)
  58 
  59 #ifdef PRODUCT
  60 #define BLOCK_COMMENT(str) /* nothing */
  61 #else
  62 #define BLOCK_COMMENT(str) __ block_comment(str)
  63 #endif // PRODUCT

 287   __ BIND(loop);
 288   __ movptr(rax, Address(c_rarg2, 0));// get parameter
 289   __ addptr(c_rarg2, wordSize);       // advance to next parameter
 290   __ decrementl(c_rarg1);             // decrement counter
 291   __ push(rax);                       // pass parameter
 292   __ jcc(Assembler::notZero, loop);
 293 
 294   // call Java function
 295   __ BIND(parameters_done);
 296   __ movptr(rbx, method);             // get Method*
 297   __ movptr(c_rarg1, entry_point);    // get entry_point
 298   __ mov(r13, rsp);                   // set sender sp
 299   BLOCK_COMMENT("call Java function");
 300   __ call(c_rarg1);
 301 
 302   BLOCK_COMMENT("call_stub_return_address:");
 303   return_address = __ pc();
 304 
 305   // store result depending on type (everything that is not
 306   // T_OBJECT, T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT)
 307   __ movptr(r13, result);
 308   Label is_long, is_float, is_double, check_prim, exit;
 309   __ movl(rbx, result_type);
 310   __ cmpl(rbx, T_OBJECT);
 311   __ jcc(Assembler::equal, check_prim);
 312   __ cmpl(rbx, T_LONG);
 313   __ jcc(Assembler::equal, is_long);
 314   __ cmpl(rbx, T_FLOAT);


 315   __ jcc(Assembler::equal, is_float);
 316   __ cmpl(rbx, T_DOUBLE);
 317   __ jcc(Assembler::equal, is_double);
 318 #ifdef ASSERT
 319   // make sure the type is INT
 320   {
 321     Label L;
 322     __ cmpl(rbx, T_INT);
 323     __ jcc(Assembler::equal, L);
 324     __ stop("StubRoutines::call_stub: unexpected result type");
 325     __ bind(L);
 326   }
 327 #endif
 328 
 329   // handle T_INT case
 330   __ movl(Address(r13, 0), rax);
 331 
 332   __ BIND(exit);
 333 
 334   // pop parameters
 335   __ lea(rsp, rsp_after_call);
 336 
 337 #ifdef ASSERT
 338   // verify that threads correspond
 339   {
 340    Label L1, L2, L3;
 341     __ cmpptr(r15_thread, thread);
 342     __ jcc(Assembler::equal, L1);
 343     __ stop("StubRoutines::call_stub: r15_thread is corrupted");
 344     __ bind(L1);
 345     __ get_thread_slow(rbx);
 346     __ cmpptr(r15_thread, thread);
 347     __ jcc(Assembler::equal, L2);
 348     __ stop("StubRoutines::call_stub: r15_thread is modified by call");
 349     __ bind(L2);
 350     __ cmpptr(r15_thread, rbx);

 368   __ movptr(r13, r13_save);
 369   __ movptr(r12, r12_save);
 370   __ movptr(rbx, rbx_save);
 371 
 372 #ifdef _WIN64
 373   __ movptr(rdi, rdi_save);
 374   __ movptr(rsi, rsi_save);
 375 #else
 376   __ ldmxcsr(mxcsr_save);
 377 #endif
 378 
 379   // restore rsp
 380   __ addptr(rsp, -rsp_after_call_off * wordSize);
 381 
 382   // return
 383   __ vzeroupper();
 384   __ pop(rbp);
 385   __ ret(0);
 386 
 387   // handle return types different from T_INT
 388   __ BIND(check_prim);
 389   if (InlineTypeReturnedAsFields) {
 390     // Check for scalarized return value
 391     __ testptr(rax, 1);
 392     __ jcc(Assembler::zero, is_long);
 393     // Load pack handler address
 394     __ andptr(rax, -2);
 395     __ movptr(rax, Address(rax, InstanceKlass::adr_inlineklass_fixed_block_offset()));
 396     __ movptr(rbx, Address(rax, InlineKlass::pack_handler_jobject_offset()));
 397     // Call pack handler to initialize the buffer
 398     __ call(rbx);
 399     __ jmp(exit);
 400   }
 401   __ BIND(is_long);
 402   __ movq(Address(r13, 0), rax);
 403   __ jmp(exit);
 404 
 405   __ BIND(is_float);
 406   __ movflt(Address(r13, 0), xmm0);
 407   __ jmp(exit);
 408 
 409   __ BIND(is_double);
 410   __ movdbl(Address(r13, 0), xmm0);
 411   __ jmp(exit);
 412 
 413   return start;
 414 }
 415 
 416 // Return point for a Java call if there's an exception thrown in
 417 // Java code.  The exception is caught and transformed into a
 418 // pending exception stored in JavaThread that can be tested from
 419 // within the VM.
 420 //
 421 // Note: Usually the parameters are removed by the callee. In case
 422 // of an exception crossing an activation frame boundary, that is
 423 // not the case if the callee is compiled code => need to setup the
 424 // rsp.
 425 //
 426 // rax: exception oop
 427 
 428 address StubGenerator::generate_catch_exception() {
 429   StubId stub_id = StubId::stubgen_catch_exception_id;
 430   StubCodeMark mark(this, stub_id);

3748 *  Output:
3749 *        rax   - float16  jshort
3750 */
3751 address StubGenerator::generate_floatToFloat16() {
3752   StubId stub_id = StubId::stubgen_f2hf_id;
3753   StubCodeMark mark(this, stub_id);
3754 
3755   address start = __ pc();
3756 
3757   BLOCK_COMMENT("Entry:");
3758   // No need for RuntimeStub frame since it is called only during JIT compilation
3759 
3760   // Convert and put result into rax
3761   __ flt_to_flt16(rax, xmm0, xmm1);
3762 
3763   __ ret(0);
3764 
3765   return start;
3766 }
3767 
3768 static void save_return_registers(MacroAssembler* masm) {
3769   masm->push_ppx(rax);
3770   if (InlineTypeReturnedAsFields) {
3771     masm->push(rdi);
3772     masm->push(rsi);
3773     masm->push(rdx);
3774     masm->push(rcx);
3775     masm->push(r8);
3776     masm->push(r9);
3777   }
3778   masm->push_d(xmm0);
3779   if (InlineTypeReturnedAsFields) {
3780     masm->push_d(xmm1);
3781     masm->push_d(xmm2);
3782     masm->push_d(xmm3);
3783     masm->push_d(xmm4);
3784     masm->push_d(xmm5);
3785     masm->push_d(xmm6);
3786     masm->push_d(xmm7);
3787   }
3788 #ifdef ASSERT
3789   masm->movq(rax, 0xBADC0FFE);
3790   masm->movq(rdi, rax);
3791   masm->movq(rsi, rax);
3792   masm->movq(rdx, rax);
3793   masm->movq(rcx, rax);
3794   masm->movq(r8, rax);
3795   masm->movq(r9, rax);
3796   masm->movq(xmm0, rax);
3797   masm->movq(xmm1, rax);
3798   masm->movq(xmm2, rax);
3799   masm->movq(xmm3, rax);
3800   masm->movq(xmm4, rax);
3801   masm->movq(xmm5, rax);
3802   masm->movq(xmm6, rax);
3803   masm->movq(xmm7, rax);
3804 #endif
3805 }
3806 
3807 static void restore_return_registers(MacroAssembler* masm) {
3808   if (InlineTypeReturnedAsFields) {
3809     masm->pop_d(xmm7);
3810     masm->pop_d(xmm6);
3811     masm->pop_d(xmm5);
3812     masm->pop_d(xmm4);
3813     masm->pop_d(xmm3);
3814     masm->pop_d(xmm2);
3815     masm->pop_d(xmm1);
3816   }
3817   masm->pop_d(xmm0);
3818   if (InlineTypeReturnedAsFields) {
3819     masm->pop(r9);
3820     masm->pop(r8);
3821     masm->pop(rcx);
3822     masm->pop(rdx);
3823     masm->pop(rsi);
3824     masm->pop(rdi);
3825   }
3826   masm->pop_ppx(rax);
3827 }
3828 
3829 address StubGenerator::generate_cont_thaw(StubId stub_id) {
3830   if (!Continuations::enabled()) return nullptr;
3831 
3832   bool return_barrier;
3833   bool return_barrier_exception;
3834   Continuation::thaw_kind kind;
3835 
3836   switch (stub_id) {
3837   case StubId::stubgen_cont_thaw_id:
3838     return_barrier = false;
3839     return_barrier_exception = false;
3840     kind = Continuation::thaw_top;
3841     break;
3842   case StubId::stubgen_cont_returnBarrier_id:
3843     return_barrier = true;
3844     return_barrier_exception = false;
3845     kind = Continuation::thaw_return_barrier;
3846     break;
3847   case StubId::stubgen_cont_returnBarrierExc_id:
3848     return_barrier = true;

3860   if (!return_barrier) {
3861     // Pop return address. If we don't do this, we get a drift,
3862     // where the bottom-most frozen frame continuously grows.
3863     __ pop(c_rarg3);
3864   } else {
3865     __ movptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset()));
3866   }
3867 
3868 #ifdef ASSERT
3869   {
3870     Label L_good_sp;
3871     __ cmpptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset()));
3872     __ jcc(Assembler::equal, L_good_sp);
3873     __ stop("Incorrect rsp at thaw entry");
3874     __ BIND(L_good_sp);
3875   }
3876 #endif // ASSERT
3877 
3878   if (return_barrier) {
3879     // Preserve possible return value from a method returning to the return barrier.
3880     save_return_registers(_masm);

3881   }
3882 
3883   __ movptr(c_rarg0, r15_thread);
3884   __ movptr(c_rarg1, (return_barrier ? 1 : 0));
3885   __ call_VM_leaf(CAST_FROM_FN_PTR(address, Continuation::prepare_thaw), 2);
3886   __ movptr(rbx, rax);
3887 
3888   if (return_barrier) {
3889     // Restore return value from a method returning to the return barrier.
3890     // No safepoint in the call to thaw, so even an oop return value should be OK.
3891     restore_return_registers(_masm);

3892   }
3893 
3894 #ifdef ASSERT
3895   {
3896     Label L_good_sp;
3897     __ cmpptr(rsp, Address(r15_thread, JavaThread::cont_entry_offset()));
3898     __ jcc(Assembler::equal, L_good_sp);
3899     __ stop("Incorrect rsp after prepare thaw");
3900     __ BIND(L_good_sp);
3901   }
3902 #endif // ASSERT
3903 
3904   // rbx contains the size of the frames to thaw, 0 if overflow or no more frames
3905   Label L_thaw_success;
3906   __ testptr(rbx, rbx);
3907   __ jccb(Assembler::notZero, L_thaw_success);
3908   __ jump(RuntimeAddress(SharedRuntime::throw_StackOverflowError_entry()));
3909   __ bind(L_thaw_success);
3910 
3911   // Make room for the thawed frames and align the stack.
3912   __ subptr(rsp, rbx);
3913   __ andptr(rsp, -StackAlignmentInBytes);
3914 
3915   if (return_barrier) {
3916     // Preserve possible return value from a method returning to the return barrier. (Again.)
3917     save_return_registers(_masm);

3918   }
3919 
3920   // If we want, we can templatize thaw by kind, and have three different entries.
3921   __ movptr(c_rarg0, r15_thread);
3922   __ movptr(c_rarg1, kind);
3923   __ call_VM_leaf(Continuation::thaw_entry(), 2);
3924   __ movptr(rbx, rax);
3925 
3926   if (return_barrier) {
3927     // Restore return value from a method returning to the return barrier. (Again.)
3928     // No safepoint in the call to thaw, so even an oop return value should be OK.
3929     restore_return_registers(_masm);

3930   } else {
3931     // Return 0 (success) from doYield.
3932     __ xorptr(rax, rax);
3933   }
3934 
3935   // After thawing, rbx is the SP of the yielding frame.
3936   // Move there, and then to saved RBP slot.
3937   __ movptr(rsp, rbx);
3938   __ subptr(rsp, 2*wordSize);
3939 
3940   if (return_barrier_exception) {
3941     __ movptr(c_rarg0, r15_thread);
3942     __ movptr(c_rarg1, Address(rsp, wordSize)); // return address
3943 
3944     // rax still holds the original exception oop, save it before the call
3945     __ push_ppx(rax);
3946 
3947     __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), 2);
3948     __ movptr(rbx, rax);
3949 

4116 
4117 void StubGenerator::generate_initial_stubs() {
4118   // Generates all stubs and initializes the entry points
4119 
4120   // This platform-specific settings are needed by generate_call_stub()
4121   create_control_words();
4122 
4123   // Initialize table for unsafe copy memeory check.
4124   if (UnsafeMemoryAccess::_table == nullptr) {
4125     UnsafeMemoryAccess::create_table(16 + 4); // 16 for copyMemory; 4 for setMemory
4126   }
4127 
4128   // entry points that exist in all platforms Note: This is code
4129   // that could be shared among different platforms - however the
4130   // benefit seems to be smaller than the disadvantage of having a
4131   // much more complicated generator structure. See also comment in
4132   // stubRoutines.hpp.
4133 
4134   StubRoutines::_forward_exception_entry = generate_forward_exception();
4135 
4136   // Generate these first because they are called from other stubs
4137   if (InlineTypeReturnedAsFields) {
4138     StubRoutines::_load_inline_type_fields_in_regs =
4139       generate_return_value_stub(CAST_FROM_FN_PTR(address, SharedRuntime::load_inline_type_fields_in_regs),
4140                                  "load_inline_type_fields_in_regs", false);
4141     StubRoutines::_store_inline_type_fields_to_buf =
4142       generate_return_value_stub(CAST_FROM_FN_PTR(address, SharedRuntime::store_inline_type_fields_to_buf),
4143                                  "store_inline_type_fields_to_buf", true);
4144   }
4145 
4146   StubRoutines::_call_stub_entry =
4147     generate_call_stub(StubRoutines::_call_stub_return_address);
4148 
4149   // is referenced by megamorphic call
4150   StubRoutines::_catch_exception_entry = generate_catch_exception();
4151 
4152   // platform dependent
4153   StubRoutines::x86::_verify_mxcsr_entry    = generate_verify_mxcsr();
4154 
4155   StubRoutines::x86::_f2i_fixup             = generate_f2i_fixup();
4156   StubRoutines::x86::_f2l_fixup             = generate_f2l_fixup();
4157   StubRoutines::x86::_d2i_fixup             = generate_d2i_fixup();
4158   StubRoutines::x86::_d2l_fixup             = generate_d2l_fixup();
4159 
4160   StubRoutines::x86::_float_sign_mask       = generate_fp_mask(StubId::stubgen_float_sign_mask_id,  0x7FFFFFFF7FFFFFFF);
4161   StubRoutines::x86::_float_sign_flip       = generate_fp_mask(StubId::stubgen_float_sign_flip_id,  0x8000000080000000);
4162   StubRoutines::x86::_double_sign_mask      = generate_fp_mask(StubId::stubgen_double_sign_mask_id, 0x7FFFFFFFFFFFFFFF);
4163   StubRoutines::x86::_double_sign_flip      = generate_fp_mask(StubId::stubgen_double_sign_flip_id, 0x8000000000000000);
4164 
4165   if (UseCRC32Intrinsics) {

4169   if (UseCRC32CIntrinsics) {
4170     bool supports_clmul = VM_Version::supports_clmul();
4171     StubRoutines::_updateBytesCRC32C = generate_updateBytesCRC32C(supports_clmul);
4172   }
4173 
4174   if (VM_Version::supports_float16()) {
4175     // For results consistency both intrinsics should be enabled.
4176     // vmIntrinsics checks InlineIntrinsics flag, no need to check it here.
4177     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_float16ToFloat) &&
4178         vmIntrinsics::is_intrinsic_available(vmIntrinsics::_floatToFloat16)) {
4179       StubRoutines::_hf2f = generate_float16ToFloat();
4180       StubRoutines::_f2hf = generate_floatToFloat16();
4181     }
4182   }
4183 
4184   generate_libm_stubs();
4185 
4186   StubRoutines::_fmod = generate_libmFmod(); // from stubGenerator_x86_64_fmod.cpp
4187 }
4188 
4189 // Call here from the interpreter or compiled code to either load
4190 // multiple returned values from the inline type instance being
4191 // returned to registers or to store returned values to a newly
4192 // allocated inline type instance.
4193 // Register is a class, but it would be assigned numerical value.
4194 // "0" is assigned for xmm0. Thus we need to ignore -Wnonnull.
4195 PRAGMA_DIAG_PUSH
4196 PRAGMA_NONNULL_IGNORED
4197 address StubGenerator::generate_return_value_stub(address destination, const char* name, bool has_res) {
4198   // We need to save all registers the calling convention may use so
4199   // the runtime calls read or update those registers. This needs to
4200   // be in sync with SharedRuntime::java_return_convention().
4201   enum layout {
4202     pad_off = frame::arg_reg_save_area_bytes/BytesPerInt, pad_off_2,
4203     rax_off, rax_off_2,
4204     j_rarg5_off, j_rarg5_2,
4205     j_rarg4_off, j_rarg4_2,
4206     j_rarg3_off, j_rarg3_2,
4207     j_rarg2_off, j_rarg2_2,
4208     j_rarg1_off, j_rarg1_2,
4209     j_rarg0_off, j_rarg0_2,
4210     j_farg0_off, j_farg0_2,
4211     j_farg1_off, j_farg1_2,
4212     j_farg2_off, j_farg2_2,
4213     j_farg3_off, j_farg3_2,
4214     j_farg4_off, j_farg4_2,
4215     j_farg5_off, j_farg5_2,
4216     j_farg6_off, j_farg6_2,
4217     j_farg7_off, j_farg7_2,
4218     rbp_off, rbp_off_2,
4219     return_off, return_off_2,
4220 
4221     framesize
4222   };
4223 
4224   CodeBuffer buffer(name, 1000, 512);
4225   MacroAssembler* _masm = new MacroAssembler(&buffer);
4226 
4227   int frame_size_in_bytes = align_up(framesize*BytesPerInt, 16);
4228   assert(frame_size_in_bytes == framesize*BytesPerInt, "misaligned");
4229   int frame_size_in_slots = frame_size_in_bytes / BytesPerInt;
4230   int frame_size_in_words = frame_size_in_bytes / wordSize;
4231 
4232   OopMapSet *oop_maps = new OopMapSet();
4233   OopMap* map = new OopMap(frame_size_in_slots, 0);
4234 
4235   map->set_callee_saved(VMRegImpl::stack2reg(rax_off), rax->as_VMReg());
4236   map->set_callee_saved(VMRegImpl::stack2reg(j_rarg5_off), j_rarg5->as_VMReg());
4237   map->set_callee_saved(VMRegImpl::stack2reg(j_rarg4_off), j_rarg4->as_VMReg());
4238   map->set_callee_saved(VMRegImpl::stack2reg(j_rarg3_off), j_rarg3->as_VMReg());
4239   map->set_callee_saved(VMRegImpl::stack2reg(j_rarg2_off), j_rarg2->as_VMReg());
4240   map->set_callee_saved(VMRegImpl::stack2reg(j_rarg1_off), j_rarg1->as_VMReg());
4241   map->set_callee_saved(VMRegImpl::stack2reg(j_rarg0_off), j_rarg0->as_VMReg());
4242   map->set_callee_saved(VMRegImpl::stack2reg(j_farg0_off), j_farg0->as_VMReg());
4243   map->set_callee_saved(VMRegImpl::stack2reg(j_farg1_off), j_farg1->as_VMReg());
4244   map->set_callee_saved(VMRegImpl::stack2reg(j_farg2_off), j_farg2->as_VMReg());
4245   map->set_callee_saved(VMRegImpl::stack2reg(j_farg3_off), j_farg3->as_VMReg());
4246   map->set_callee_saved(VMRegImpl::stack2reg(j_farg4_off), j_farg4->as_VMReg());
4247   map->set_callee_saved(VMRegImpl::stack2reg(j_farg5_off), j_farg5->as_VMReg());
4248   map->set_callee_saved(VMRegImpl::stack2reg(j_farg6_off), j_farg6->as_VMReg());
4249   map->set_callee_saved(VMRegImpl::stack2reg(j_farg7_off), j_farg7->as_VMReg());
4250 
4251   int start = __ offset();
4252 
4253   __ subptr(rsp, frame_size_in_bytes - 8 /* return address*/);
4254 
4255   __ movptr(Address(rsp, rbp_off * BytesPerInt), rbp);
4256   __ movdbl(Address(rsp, j_farg7_off * BytesPerInt), j_farg7);
4257   __ movdbl(Address(rsp, j_farg6_off * BytesPerInt), j_farg6);
4258   __ movdbl(Address(rsp, j_farg5_off * BytesPerInt), j_farg5);
4259   __ movdbl(Address(rsp, j_farg4_off * BytesPerInt), j_farg4);
4260   __ movdbl(Address(rsp, j_farg3_off * BytesPerInt), j_farg3);
4261   __ movdbl(Address(rsp, j_farg2_off * BytesPerInt), j_farg2);
4262   __ movdbl(Address(rsp, j_farg1_off * BytesPerInt), j_farg1);
4263   __ movdbl(Address(rsp, j_farg0_off * BytesPerInt), j_farg0);
4264 
4265   __ movptr(Address(rsp, j_rarg0_off * BytesPerInt), j_rarg0);
4266   __ movptr(Address(rsp, j_rarg1_off * BytesPerInt), j_rarg1);
4267   __ movptr(Address(rsp, j_rarg2_off * BytesPerInt), j_rarg2);
4268   __ movptr(Address(rsp, j_rarg3_off * BytesPerInt), j_rarg3);
4269   __ movptr(Address(rsp, j_rarg4_off * BytesPerInt), j_rarg4);
4270   __ movptr(Address(rsp, j_rarg5_off * BytesPerInt), j_rarg5);
4271   __ movptr(Address(rsp, rax_off * BytesPerInt), rax);
4272 
4273   int frame_complete = __ offset();
4274 
4275   __ set_last_Java_frame(noreg, noreg, nullptr, rscratch1);
4276 
4277   __ mov(c_rarg0, r15_thread);
4278   __ mov(c_rarg1, rax);
4279 
4280   __ call(RuntimeAddress(destination));
4281 
4282   // Set an oopmap for the call site.
4283 
4284   oop_maps->add_gc_map( __ offset() - start, map);
4285 
4286   // clear last_Java_sp
4287   __ reset_last_Java_frame(false);
4288 
4289   __ movptr(rbp, Address(rsp, rbp_off * BytesPerInt));
4290   __ movdbl(j_farg7, Address(rsp, j_farg7_off * BytesPerInt));
4291   __ movdbl(j_farg6, Address(rsp, j_farg6_off * BytesPerInt));
4292   __ movdbl(j_farg5, Address(rsp, j_farg5_off * BytesPerInt));
4293   __ movdbl(j_farg4, Address(rsp, j_farg4_off * BytesPerInt));
4294   __ movdbl(j_farg3, Address(rsp, j_farg3_off * BytesPerInt));
4295   __ movdbl(j_farg2, Address(rsp, j_farg2_off * BytesPerInt));
4296   __ movdbl(j_farg1, Address(rsp, j_farg1_off * BytesPerInt));
4297   __ movdbl(j_farg0, Address(rsp, j_farg0_off * BytesPerInt));
4298 
4299   __ movptr(j_rarg0, Address(rsp, j_rarg0_off * BytesPerInt));
4300   __ movptr(j_rarg1, Address(rsp, j_rarg1_off * BytesPerInt));
4301   __ movptr(j_rarg2, Address(rsp, j_rarg2_off * BytesPerInt));
4302   __ movptr(j_rarg3, Address(rsp, j_rarg3_off * BytesPerInt));
4303   __ movptr(j_rarg4, Address(rsp, j_rarg4_off * BytesPerInt));
4304   __ movptr(j_rarg5, Address(rsp, j_rarg5_off * BytesPerInt));
4305   __ movptr(rax, Address(rsp, rax_off * BytesPerInt));
4306 
4307   __ addptr(rsp, frame_size_in_bytes-8);
4308 
4309   // check for pending exceptions
4310   Label pending;
4311   __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
4312   __ jcc(Assembler::notEqual, pending);
4313 
4314   if (has_res) {
4315     __ get_vm_result_oop(rax);
4316   }
4317 
4318   __ ret(0);
4319 
4320   __ bind(pending);
4321 
4322   __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
4323   __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
4324 
4325   // -------------
4326   // make sure all code is generated
4327   _masm->flush();
4328 
4329   RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_words, oop_maps, false);
4330   return stub->entry_point();
4331 }
4332 
4333 void StubGenerator::generate_continuation_stubs() {
4334   // Continuation stubs:
4335   StubRoutines::_cont_thaw          = generate_cont_thaw();
4336   StubRoutines::_cont_returnBarrier = generate_cont_returnBarrier();
4337   StubRoutines::_cont_returnBarrierExc = generate_cont_returnBarrier_exception();
4338   StubRoutines::_cont_preempt_stub = generate_cont_preempt_stub();
4339 }
4340 
4341 void StubGenerator::generate_final_stubs() {
4342   // Generates the rest of stubs and initializes the entry points
4343 
4344   // support for verify_oop (must happen after universe_init)
4345   if (VerifyOops) {
4346     StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop();
4347   }
4348 
4349   // arraycopy stubs used by compilers
4350   generate_arraycopy_stubs();
4351 
4352   StubRoutines::_method_entry_barrier = generate_method_entry_barrier();
< prev index next >