< prev index next >

src/hotspot/cpu/x86/foreign_globals_x86.cpp

Print this page
@@ -20,15 +20,16 @@
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  #include "precompiled.hpp"
- #include "runtime/jniHandles.hpp"
  #include "runtime/jniHandles.inline.hpp"
  #include "oops/typeArrayOop.inline.hpp"
- #include "prims/foreign_globals.hpp"
+ #include "oops/oopCast.inline.hpp"
  #include "prims/foreign_globals.inline.hpp"
+ #include "runtime/sharedRuntime.hpp"
+ #include "utilities/formatBuffer.hpp"
  
  bool ABIDescriptor::is_volatile_reg(Register reg) const {
      return _integer_argument_registers.contains(reg)
          || _integer_additional_volatile_registers.contains(reg);
  }

@@ -44,75 +45,117 @@
  
  const ABIDescriptor ForeignGlobals::parse_abi_descriptor_impl(jobject jabi) const {
    oop abi_oop = JNIHandles::resolve_non_null(jabi);
    ABIDescriptor abi;
  
-   objArrayOop inputStorage = cast<objArrayOop>(abi_oop->obj_field(ABI.inputStorage_offset));
+   objArrayOop inputStorage = oop_cast<objArrayOop>(abi_oop->obj_field(ABI.inputStorage_offset));
    loadArray(inputStorage, INTEGER_TYPE, abi._integer_argument_registers, as_Register);
    loadArray(inputStorage, VECTOR_TYPE, abi._vector_argument_registers, as_XMMRegister);
  
-   objArrayOop outputStorage = cast<objArrayOop>(abi_oop->obj_field(ABI.outputStorage_offset));
+   objArrayOop outputStorage = oop_cast<objArrayOop>(abi_oop->obj_field(ABI.outputStorage_offset));
    loadArray(outputStorage, INTEGER_TYPE, abi._integer_return_registers, as_Register);
    loadArray(outputStorage, VECTOR_TYPE, abi._vector_return_registers, as_XMMRegister);
-   objArrayOop subarray = cast<objArrayOop>(outputStorage->obj_at(X87_TYPE));
+   objArrayOop subarray = oop_cast<objArrayOop>(outputStorage->obj_at(X87_TYPE));
    abi._X87_return_registers_noof = subarray->length();
  
-   objArrayOop volatileStorage = cast<objArrayOop>(abi_oop->obj_field(ABI.volatileStorage_offset));
+   objArrayOop volatileStorage = oop_cast<objArrayOop>(abi_oop->obj_field(ABI.volatileStorage_offset));
    loadArray(volatileStorage, INTEGER_TYPE, abi._integer_additional_volatile_registers, as_Register);
    loadArray(volatileStorage, VECTOR_TYPE, abi._vector_additional_volatile_registers, as_XMMRegister);
  
    abi._stack_alignment_bytes = abi_oop->int_field(ABI.stackAlignment_offset);
    abi._shadow_space_bytes = abi_oop->int_field(ABI.shadowSpace_offset);
  
+   abi._target_addr_reg = parse_vmstorage(abi_oop->obj_field(ABI.targetAddrStorage_offset))->as_Register();
+   abi._ret_buf_addr_reg = parse_vmstorage(abi_oop->obj_field(ABI.retBufAddrStorage_offset))->as_Register();
+ 
    return abi;
  }
  
- const BufferLayout ForeignGlobals::parse_buffer_layout_impl(jobject jlayout) const {
-   oop layout_oop = JNIHandles::resolve_non_null(jlayout);
-   BufferLayout layout;
- 
-   layout.stack_args_bytes = layout_oop->long_field(BL.stack_args_bytes_offset);
-   layout.stack_args = layout_oop->long_field(BL.stack_args_offset);
-   layout.arguments_next_pc = layout_oop->long_field(BL.arguments_next_pc_offset);
- 
-   typeArrayOop input_offsets = cast<typeArrayOop>(layout_oop->obj_field(BL.input_type_offsets_offset));
-   layout.arguments_integer = (size_t) input_offsets->long_at(INTEGER_TYPE);
-   layout.arguments_vector = (size_t) input_offsets->long_at(VECTOR_TYPE);
- 
-   typeArrayOop output_offsets = cast<typeArrayOop>(layout_oop->obj_field(BL.output_type_offsets_offset));
-   layout.returns_integer = (size_t) output_offsets->long_at(INTEGER_TYPE);
-   layout.returns_vector = (size_t) output_offsets->long_at(VECTOR_TYPE);
-   layout.returns_x87 = (size_t) output_offsets->long_at(X87_TYPE);
- 
-   layout.buffer_size = layout_oop->long_field(BL.size_offset);
- 
-   return layout;
+ enum class RegType {
+   INTEGER = 0,
+   VECTOR = 1,
+   X87 = 2,
+   STACK = 3
+ };
+ 
+ VMReg ForeignGlobals::vmstorage_to_vmreg(int type, int index) {
+   switch(static_cast<RegType>(type)) {
+     case RegType::INTEGER: return ::as_Register(index)->as_VMReg();
+     case RegType::VECTOR: return ::as_XMMRegister(index)->as_VMReg();
+     case RegType::STACK: return VMRegImpl::stack2reg(index LP64_ONLY(* 2)); // numbering on x64 goes per 64-bits
+     case RegType::X87: break;
+   }
+   return VMRegImpl::Bad();
  }
  
- const CallRegs ForeignGlobals::parse_call_regs_impl(jobject jconv) const {
-   oop conv_oop = JNIHandles::resolve_non_null(jconv);
-   objArrayOop arg_regs_oop = cast<objArrayOop>(conv_oop->obj_field(CallConvOffsets.arg_regs_offset));
-   objArrayOop ret_regs_oop = cast<objArrayOop>(conv_oop->obj_field(CallConvOffsets.ret_regs_offset));
- 
-   CallRegs result;
-   result._args_length = arg_regs_oop->length();
-   result._arg_regs = NEW_RESOURCE_ARRAY(VMReg, result._args_length);
- 
-   result._rets_length = ret_regs_oop->length();
-   result._ret_regs = NEW_RESOURCE_ARRAY(VMReg, result._rets_length);
+ int RegSpiller::pd_reg_size(VMReg reg) {
+   if (reg->is_Register()) {
+     return 8;
+   } else if (reg->is_XMMRegister()) {
+     return 16;
+   }
+   return 0; // stack and BAD
+ }
  
-   for (int i = 0; i < result._args_length; i++) {
-     oop storage = arg_regs_oop->obj_at(i);
-     jint index = storage->int_field(VMS.index_offset);
-     jint type = storage->int_field(VMS.type_offset);
-     result._arg_regs[i] = VMRegImpl::vmStorageToVMReg(type, index);
+ void RegSpiller::pd_store_reg(MacroAssembler* masm, int offset, VMReg reg) {
+   if (reg->is_Register()) {
+     masm->movptr(Address(rsp, offset), reg->as_Register());
+   } else if (reg->is_XMMRegister()) {
+     masm->movdqu(Address(rsp, offset), reg->as_XMMRegister());
+   } else {
+     // stack and BAD
    }
+ }
  
-   for (int i = 0; i < result._rets_length; i++) {
-     oop storage = ret_regs_oop->obj_at(i);
-     jint index = storage->int_field(VMS.index_offset);
-     jint type = storage->int_field(VMS.type_offset);
-     result._ret_regs[i] = VMRegImpl::vmStorageToVMReg(type, index);
+ void RegSpiller::pd_load_reg(MacroAssembler* masm, int offset, VMReg reg) {
+   if (reg->is_Register()) {
+     masm->movptr(reg->as_Register(), Address(rsp, offset));
+   } else if (reg->is_XMMRegister()) {
+     masm->movdqu(reg->as_XMMRegister(), Address(rsp, offset));
+   } else {
+     // stack and BAD
    }
+ }
  
-   return result;
+ void ArgumentShuffle::pd_generate(MacroAssembler* masm, VMReg tmp, int in_stk_bias, int out_stk_bias) const {
+   Register tmp_reg = tmp->as_Register();
+   for (int i = 0; i < _moves.length(); i++) {
+     Move move = _moves.at(i);
+     BasicType arg_bt     = move.bt;
+     VMRegPair from_vmreg = move.from;
+     VMRegPair to_vmreg   = move.to;
+ 
+     masm->block_comment(err_msg("bt=%s", null_safe_string(type2name(arg_bt))));
+     switch (arg_bt) {
+       case T_BOOLEAN:
+       case T_BYTE:
+       case T_SHORT:
+       case T_CHAR:
+       case T_INT:
+         masm->move32_64(from_vmreg, to_vmreg, tmp_reg, in_stk_bias, out_stk_bias);
+         break;
+ 
+       case T_FLOAT:
+         if (to_vmreg.first()->is_Register()) { // Windows vararg call
+           masm->movq(to_vmreg.first()->as_Register(), from_vmreg.first()->as_XMMRegister());
+         } else {
+           masm->float_move(from_vmreg, to_vmreg, tmp_reg, in_stk_bias, out_stk_bias);
+         }
+         break;
+ 
+       case T_DOUBLE:
+         if (to_vmreg.first()->is_Register()) { // Windows vararg call
+           masm->movq(to_vmreg.first()->as_Register(), from_vmreg.first()->as_XMMRegister());
+         } else {
+           masm->double_move(from_vmreg, to_vmreg, tmp_reg, in_stk_bias, out_stk_bias);
+         }
+         break;
+ 
+       case T_LONG:
+         masm->long_move(from_vmreg, to_vmreg, tmp_reg, in_stk_bias, out_stk_bias);
+         break;
+ 
+       default:
+         fatal("found in upcall args: %s", type2name(arg_bt));
+     }
+   }
  }
< prev index next >