hotspot/src/cpu/x86/vm/methodHandles_x86.cpp
author twisti
Wed, 22 Dec 2010 02:02:53 -0800
changeset 7712 cee30a0f4315
parent 7397 5b173b4ca846
child 7887 7aa0354cbf25
permissions -rw-r--r--
7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot Reviewed-by: kvn, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5420
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     4
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     7
 * published by the Free Software Foundation.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     8
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    13
 * accompanied this code).
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    14
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5420
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5420
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5420
diff changeset
    21
 * questions.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    22
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    23
 */
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6969
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6969
diff changeset
    26
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6969
diff changeset
    27
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6969
diff changeset
    28
#include "prims/methodHandles.hpp"
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    29
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    30
#define __ _masm->
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    31
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    32
#ifdef PRODUCT
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    33
#define BLOCK_COMMENT(str) /* nothing */
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    34
#else
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    35
#define BLOCK_COMMENT(str) __ block_comment(str)
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    36
#endif
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    37
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    38
#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    39
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    40
address MethodHandleEntry::start_compiled_entry(MacroAssembler* _masm,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    41
                                                address interpreted_entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    42
  // Just before the actual machine code entry point, allocate space
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    43
  // for a MethodHandleEntry::Data record, so that we can manage everything
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    44
  // from one base pointer.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    45
  __ align(wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    46
  address target = __ pc() + sizeof(Data);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    47
  while (__ pc() < target) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    48
    __ nop();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    49
    __ align(wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    50
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    51
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    52
  MethodHandleEntry* me = (MethodHandleEntry*) __ pc();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    53
  me->set_end_address(__ pc());         // set a temporary end_address
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    54
  me->set_from_interpreted_entry(interpreted_entry);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    55
  me->set_type_checking_entry(NULL);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    56
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    57
  return (address) me;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    58
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    59
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    60
MethodHandleEntry* MethodHandleEntry::finish_compiled_entry(MacroAssembler* _masm,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    61
                                                address start_addr) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    62
  MethodHandleEntry* me = (MethodHandleEntry*) start_addr;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    63
  assert(me->end_address() == start_addr, "valid ME");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    65
  // Fill in the real end_address:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    66
  __ align(wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    67
  me->set_end_address(__ pc());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    68
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    69
  return me;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    70
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    71
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    72
#ifdef ASSERT
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
    73
static void verify_argslot(MacroAssembler* _masm, Register argslot_reg,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    74
                           const char* error_message) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    75
  // Verify that argslot lies within (rsp, rbp].
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    76
  Label L_ok, L_bad;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    77
  BLOCK_COMMENT("{ verify_argslot");
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
    78
  __ cmpptr(argslot_reg, rbp);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
    79
  __ jccb(Assembler::above, L_bad);
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
    80
  __ cmpptr(rsp, argslot_reg);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
    81
  __ jccb(Assembler::below, L_ok);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    82
  __ bind(L_bad);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    83
  __ stop(error_message);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    84
  __ bind(L_ok);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    85
  BLOCK_COMMENT("} verify_argslot");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    86
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    87
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    88
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    89
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    90
// Code generation
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    91
address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    92
  // rbx: methodOop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    93
  // rcx: receiver method handle (must load from sp[MethodTypeForm.vmslots])
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    94
  // rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted)
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
    95
  // rdx, rdi: garbage temp, blown away
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    96
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    97
  Register rbx_method = rbx;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    98
  Register rcx_recv   = rcx;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    99
  Register rax_mtype  = rax;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   100
  Register rdx_temp   = rdx;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   101
  Register rdi_temp   = rdi;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   102
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   103
  // emit WrongMethodType path first, to enable jccb back-branch from main path
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   104
  Label wrong_method_type;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   105
  __ bind(wrong_method_type);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   106
  Label invoke_generic_slow_path;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   107
  assert(methodOopDesc::intrinsic_id_size_in_bytes() == sizeof(u1), "");;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   108
  __ cmpb(Address(rbx_method, methodOopDesc::intrinsic_id_offset_in_bytes()), (int) vmIntrinsics::_invokeExact);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   109
  __ jcc(Assembler::notEqual, invoke_generic_slow_path);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   110
  __ push(rax_mtype);       // required mtype
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   111
  __ push(rcx_recv);        // bad mh (1st stacked argument)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   112
  __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   113
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   114
  // here's where control starts out:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   115
  __ align(CodeEntryAlignment);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   116
  address entry_point = __ pc();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   117
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   118
  // fetch the MethodType from the method handle into rax (the 'check' register)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   119
  {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   120
    Register tem = rbx_method;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   121
    for (jint* pchase = methodOopDesc::method_type_offsets_chain(); (*pchase) != -1; pchase++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   122
      __ movptr(rax_mtype, Address(tem, *pchase));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   123
      tem = rax_mtype;          // in case there is another indirection
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   124
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   125
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   126
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   127
  // given the MethodType, find out where the MH argument is buried
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   128
  __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rdi_temp)));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   129
  Register rdx_vmslots = rdx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   130
  __ movl(rdx_vmslots, Address(rdx_temp, __ delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, rdi_temp)));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   131
  __ movptr(rcx_recv, __ argument_address(rdx_vmslots));
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   132
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   133
  trace_method_handle(_masm, "invokeExact");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   134
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   135
  __ check_method_handle_type(rax_mtype, rcx_recv, rdi_temp, wrong_method_type);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   136
  __ jump_to_method_handle_entry(rcx_recv, rdi_temp);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   137
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   138
  // for invokeGeneric (only), apply argument and result conversions on the fly
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   139
  __ bind(invoke_generic_slow_path);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   140
#ifdef ASSERT
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   141
  { Label L;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   142
    __ cmpb(Address(rbx_method, methodOopDesc::intrinsic_id_offset_in_bytes()), (int) vmIntrinsics::_invokeGeneric);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   143
    __ jcc(Assembler::equal, L);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   144
    __ stop("bad methodOop::intrinsic_id");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   145
    __ bind(L);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   146
  }
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   147
#endif //ASSERT
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   148
  Register rbx_temp = rbx_method;  // don't need it now
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   149
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   150
  // make room on the stack for another pointer:
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   151
  Register rcx_argslot = rcx_recv;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   152
  __ lea(rcx_argslot, __ argument_address(rdx_vmslots, 1));
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   153
  insert_arg_slots(_masm, 2 * stack_move_unit(), _INSERT_REF_MASK,
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   154
                   rcx_argslot, rbx_temp, rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   155
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   156
  // load up an adapter from the calling type (Java weaves this)
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   157
  __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rdi_temp)));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   158
  Register rdx_adapter = rdx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   159
  // __ load_heap_oop(rdx_adapter, Address(rdx_temp, java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes()));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   160
  // deal with old JDK versions:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   161
  __ lea(rdi_temp, Address(rdx_temp, __ delayed_value(java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes, rdi_temp)));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   162
  __ cmpptr(rdi_temp, rdx_temp);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   163
  Label sorry_no_invoke_generic;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   164
  __ jcc(Assembler::below, sorry_no_invoke_generic);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   165
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   166
  __ load_heap_oop(rdx_adapter, Address(rdi_temp, 0));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   167
  __ testptr(rdx_adapter, rdx_adapter);
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   168
  __ jcc(Assembler::zero, sorry_no_invoke_generic);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   169
  __ movptr(Address(rcx_argslot, 1 * Interpreter::stackElementSize), rdx_adapter);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   170
  // As a trusted first argument, pass the type being called, so the adapter knows
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   171
  // the actual types of the arguments and return values.
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   172
  // (Generic invokers are shared among form-families of method-type.)
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   173
  __ movptr(Address(rcx_argslot, 0 * Interpreter::stackElementSize), rax_mtype);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   174
  // FIXME: assert that rdx_adapter is of the right method-type.
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   175
  __ mov(rcx, rdx_adapter);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   176
  trace_method_handle(_masm, "invokeGeneric");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   177
  __ jump_to_method_handle_entry(rcx, rdi_temp);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   178
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   179
  __ bind(sorry_no_invoke_generic); // no invokeGeneric implementation available!
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   180
  __ movptr(rcx_recv, Address(rcx_argslot, -1 * Interpreter::stackElementSize));  // recover original MH
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   181
  __ push(rax_mtype);       // required mtype
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   182
  __ push(rcx_recv);        // bad mh (1st stacked argument)
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   183
  __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   184
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   185
  return entry_point;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   186
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   187
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   188
// Helper to insert argument slots into the stack.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   189
// arg_slots must be a multiple of stack_move_unit() and <= 0
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   190
void MethodHandles::insert_arg_slots(MacroAssembler* _masm,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   191
                                     RegisterOrConstant arg_slots,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   192
                                     int arg_mask,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   193
                                     Register rax_argslot,
5416
5f6377fcfd3e 6829193: JSR 292 needs to support SPARC
twisti
parents: 5095
diff changeset
   194
                                     Register rbx_temp, Register rdx_temp, Register temp3_reg) {
5f6377fcfd3e 6829193: JSR 292 needs to support SPARC
twisti
parents: 5095
diff changeset
   195
  assert(temp3_reg == noreg, "temp3 not required");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   196
  assert_different_registers(rax_argslot, rbx_temp, rdx_temp,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   197
                             (!arg_slots.is_register() ? rsp : arg_slots.as_register()));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   198
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   199
#ifdef ASSERT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   200
  verify_argslot(_masm, rax_argslot, "insertion point must fall within current frame");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   201
  if (arg_slots.is_register()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   202
    Label L_ok, L_bad;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   203
    __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   204
    __ jccb(Assembler::greater, L_bad);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   205
    __ testl(arg_slots.as_register(), -stack_move_unit() - 1);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   206
    __ jccb(Assembler::zero, L_ok);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   207
    __ bind(L_bad);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   208
    __ stop("assert arg_slots <= 0 and clear low bits");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   209
    __ bind(L_ok);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   210
  } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   211
    assert(arg_slots.as_constant() <= 0, "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   212
    assert(arg_slots.as_constant() % -stack_move_unit() == 0, "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   213
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   214
#endif //ASSERT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   215
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   216
#ifdef _LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   217
  if (arg_slots.is_register()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   218
    // clean high bits of stack motion register (was loaded as an int)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   219
    __ movslq(arg_slots.as_register(), arg_slots.as_register());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   220
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   221
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   222
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   223
  // Make space on the stack for the inserted argument(s).
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   224
  // Then pull down everything shallower than rax_argslot.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   225
  // The stacked return address gets pulled down with everything else.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   226
  // That is, copy [rsp, argslot) downward by -size words.  In pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   227
  //   rsp -= size;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   228
  //   for (rdx = rsp + size; rdx < argslot; rdx++)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   229
  //     rdx[-size] = rdx[0]
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   230
  //   argslot -= size;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   231
  BLOCK_COMMENT("insert_arg_slots {");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   232
  __ mov(rdx_temp, rsp);                        // source pointer for copy
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   233
  __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   234
  {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   235
    Label loop;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   236
    __ BIND(loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   237
    // pull one word down each time through the loop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   238
    __ movptr(rbx_temp, Address(rdx_temp, 0));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   239
    __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   240
    __ addptr(rdx_temp, wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   241
    __ cmpptr(rdx_temp, rax_argslot);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   242
    __ jccb(Assembler::less, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   243
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   244
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   245
  // Now move the argslot down, to point to the opened-up space.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   246
  __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   247
  BLOCK_COMMENT("} insert_arg_slots");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   248
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   249
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   250
// Helper to remove argument slots from the stack.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   251
// arg_slots must be a multiple of stack_move_unit() and >= 0
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   252
void MethodHandles::remove_arg_slots(MacroAssembler* _masm,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   253
                                    RegisterOrConstant arg_slots,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   254
                                    Register rax_argslot,
5416
5f6377fcfd3e 6829193: JSR 292 needs to support SPARC
twisti
parents: 5095
diff changeset
   255
                                     Register rbx_temp, Register rdx_temp, Register temp3_reg) {
5f6377fcfd3e 6829193: JSR 292 needs to support SPARC
twisti
parents: 5095
diff changeset
   256
  assert(temp3_reg == noreg, "temp3 not required");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   257
  assert_different_registers(rax_argslot, rbx_temp, rdx_temp,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   258
                             (!arg_slots.is_register() ? rsp : arg_slots.as_register()));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   259
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   260
#ifdef ASSERT
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   261
  // Verify that [argslot..argslot+size) lies within (rsp, rbp).
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   262
  __ lea(rbx_temp, Address(rax_argslot, arg_slots, Address::times_ptr));
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   263
  verify_argslot(_masm, rbx_temp, "deleted argument(s) must fall within current frame");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   264
  if (arg_slots.is_register()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   265
    Label L_ok, L_bad;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   266
    __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   267
    __ jccb(Assembler::less, L_bad);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   268
    __ testl(arg_slots.as_register(), -stack_move_unit() - 1);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   269
    __ jccb(Assembler::zero, L_ok);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   270
    __ bind(L_bad);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   271
    __ stop("assert arg_slots >= 0 and clear low bits");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   272
    __ bind(L_ok);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   273
  } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   274
    assert(arg_slots.as_constant() >= 0, "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   275
    assert(arg_slots.as_constant() % -stack_move_unit() == 0, "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   276
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   277
#endif //ASSERT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   278
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   279
#ifdef _LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   280
  if (false) {                  // not needed, since register is positive
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   281
    // clean high bits of stack motion register (was loaded as an int)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   282
    if (arg_slots.is_register())
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   283
      __ movslq(arg_slots.as_register(), arg_slots.as_register());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   284
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   285
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   286
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   287
  BLOCK_COMMENT("remove_arg_slots {");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   288
  // Pull up everything shallower than rax_argslot.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   289
  // Then remove the excess space on the stack.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   290
  // The stacked return address gets pulled up with everything else.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   291
  // That is, copy [rsp, argslot) upward by size words.  In pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   292
  //   for (rdx = argslot-1; rdx >= rsp; --rdx)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   293
  //     rdx[size] = rdx[0]
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   294
  //   argslot += size;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   295
  //   rsp += size;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   296
  __ lea(rdx_temp, Address(rax_argslot, -wordSize)); // source pointer for copy
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   297
  {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   298
    Label loop;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   299
    __ BIND(loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   300
    // pull one word up each time through the loop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   301
    __ movptr(rbx_temp, Address(rdx_temp, 0));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   302
    __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   303
    __ addptr(rdx_temp, -wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   304
    __ cmpptr(rdx_temp, rsp);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   305
    __ jccb(Assembler::greaterEqual, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   306
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   307
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   308
  // Now move the argslot up, to point to the just-copied block.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   309
  __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   310
  // And adjust the argslot address to point at the deletion point.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   311
  __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   312
  BLOCK_COMMENT("} remove_arg_slots");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   313
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   314
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   315
#ifndef PRODUCT
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents: 4478
diff changeset
   316
extern "C" void print_method_handle(oop mh);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   317
void trace_method_handle_stub(const char* adaptername,
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents: 4478
diff changeset
   318
                              oop mh,
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   319
                              intptr_t* saved_regs,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   320
                              intptr_t* entry_sp,
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   321
                              intptr_t* saved_sp,
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   322
                              intptr_t* saved_bp) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   323
  // called as a leaf from native code: do not block the JVM!
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   324
  intptr_t* last_sp = (intptr_t*) saved_bp[frame::interpreter_frame_last_sp_offset];
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   325
  intptr_t* base_sp = (intptr_t*) saved_bp[frame::interpreter_frame_monitor_block_top_offset];
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   326
  printf("MH %s mh="INTPTR_FORMAT" sp=("INTPTR_FORMAT"+"INTX_FORMAT") stack_size="INTX_FORMAT" bp="INTPTR_FORMAT"\n",
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   327
         adaptername, (intptr_t)mh, (intptr_t)entry_sp, (intptr_t)(saved_sp - entry_sp), (intptr_t)(base_sp - last_sp), (intptr_t)saved_bp);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   328
  if (last_sp != saved_sp && last_sp != NULL)
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   329
    printf("*** last_sp="INTPTR_FORMAT"\n", (intptr_t)last_sp);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   330
  if (Verbose) {
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   331
    printf(" reg dump: ");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   332
    int saved_regs_count = (entry_sp-1) - saved_regs;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   333
    // 32 bit: rdi rsi rbp rsp; rbx rdx rcx (*) rax
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   334
    int i;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   335
    for (i = 0; i <= saved_regs_count; i++) {
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   336
      if (i > 0 && i % 4 == 0 && i != saved_regs_count)
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   337
        printf("\n   + dump: ");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   338
      printf(" %d: "INTPTR_FORMAT, i, saved_regs[i]);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   339
    }
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   340
    printf("\n");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   341
    int stack_dump_count = 16;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   342
    if (stack_dump_count < (int)(saved_bp + 2 - saved_sp))
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   343
      stack_dump_count = (int)(saved_bp + 2 - saved_sp);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   344
    if (stack_dump_count > 64)  stack_dump_count = 48;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   345
    for (i = 0; i < stack_dump_count; i += 4) {
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   346
      printf(" dump at SP[%d] "INTPTR_FORMAT": "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT"\n",
6744
dd08c62a68c7 6986944: JSR 292 assert(caller_nm->is_method_handle_return(caller_frame.pc())) failed: must be MH call site
twisti
parents: 6463
diff changeset
   347
             i, (intptr_t) &entry_sp[i+0], entry_sp[i+0], entry_sp[i+1], entry_sp[i+2], entry_sp[i+3]);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   348
    }
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   349
    print_method_handle(mh);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   350
  }
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   351
}
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   352
void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adaptername) {
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   353
  if (!TraceMethodHandles)  return;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   354
  BLOCK_COMMENT("trace_method_handle {");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   355
  __ push(rax);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   356
  __ lea(rax, Address(rsp, wordSize*6)); // entry_sp
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   357
  __ pusha();
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   358
  // arguments:
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   359
  __ push(rbp);               // interpreter frame pointer
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   360
  __ push(rsi);               // saved_sp
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   361
  __ push(rax);               // entry_sp
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   362
  __ push(rcx);               // mh
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   363
  __ push(rcx);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   364
  __ movptr(Address(rsp, 0), (intptr_t) adaptername);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   365
  __ call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub), 5);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   366
  __ popa();
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   367
  __ pop(rax);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   368
  BLOCK_COMMENT("} trace_method_handle");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   369
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   370
#endif //PRODUCT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   371
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   372
// which conversion op types are implemented here?
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   373
int MethodHandles::adapter_conversion_ops_supported_mask() {
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   374
  return ((1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   375
         |(1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   376
         |(1<<sun_dyn_AdapterMethodHandle::OP_CHECK_CAST)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   377
         |(1<<sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   378
         |(1<<sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   379
         |(1<<sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   380
         |(1<<sun_dyn_AdapterMethodHandle::OP_ROT_ARGS)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   381
         |(1<<sun_dyn_AdapterMethodHandle::OP_DUP_ARGS)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   382
         |(1<<sun_dyn_AdapterMethodHandle::OP_DROP_ARGS)
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   383
         //|(1<<sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS) //BUG!
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   384
         );
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   385
  // FIXME: MethodHandlesTest gets a crash if we enable OP_SPREAD_ARGS.
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   386
}
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
   387
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   388
//------------------------------------------------------------------------------
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   389
// MethodHandles::generate_method_handle_stub
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   390
//
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   391
// Generate an "entry" field for a method handle.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   392
// This determines how the method handle will respond to calls.
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   393
void MethodHandles::generate_method_handle_stub(MacroAssembler* _masm, MethodHandles::EntryKind ek, TRAPS) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   394
  // Here is the register state during an interpreted call,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   395
  // as set up by generate_method_handle_interpreter_entry():
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   396
  // - rbx: garbage temp (was MethodHandle.invoke methodOop, unused)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   397
  // - rcx: receiver method handle
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   398
  // - rax: method handle type (only used by the check_mtype entry point)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   399
  // - rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   400
  // - rdx: garbage temp, can blow away
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   401
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   402
  const Register rcx_recv    = rcx;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   403
  const Register rax_argslot = rax;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   404
  const Register rbx_temp    = rbx;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   405
  const Register rdx_temp    = rdx;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   406
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   407
  // This guy is set up by prepare_to_jump_from_interpreted (from interpreted calls)
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   408
  // and gen_c2i_adapter (from compiled calls):
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   409
  const Register saved_last_sp = LP64_ONLY(r13) NOT_LP64(rsi);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   410
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   411
  // Argument registers for _raise_exception.
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   412
  // 32-bit: Pass first two oop/int args in registers ECX and EDX.
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   413
  const Register rarg0_code     = LP64_ONLY(j_rarg0) NOT_LP64(rcx);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   414
  const Register rarg1_actual   = LP64_ONLY(j_rarg1) NOT_LP64(rdx);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   415
  const Register rarg2_required = LP64_ONLY(j_rarg2) NOT_LP64(rdi);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   416
  assert_different_registers(rarg0_code, rarg1_actual, rarg2_required, saved_last_sp);
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   417
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   418
  guarantee(java_dyn_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   419
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   420
  // some handy addresses
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   421
  Address rbx_method_fie(     rbx,      methodOopDesc::from_interpreted_offset() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   422
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   423
  Address rcx_mh_vmtarget(    rcx_recv, java_dyn_MethodHandle::vmtarget_offset_in_bytes() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   424
  Address rcx_dmh_vmindex(    rcx_recv, sun_dyn_DirectMethodHandle::vmindex_offset_in_bytes() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   425
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   426
  Address rcx_bmh_vmargslot(  rcx_recv, sun_dyn_BoundMethodHandle::vmargslot_offset_in_bytes() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   427
  Address rcx_bmh_argument(   rcx_recv, sun_dyn_BoundMethodHandle::argument_offset_in_bytes() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   428
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   429
  Address rcx_amh_vmargslot(  rcx_recv, sun_dyn_AdapterMethodHandle::vmargslot_offset_in_bytes() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   430
  Address rcx_amh_argument(   rcx_recv, sun_dyn_AdapterMethodHandle::argument_offset_in_bytes() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   431
  Address rcx_amh_conversion( rcx_recv, sun_dyn_AdapterMethodHandle::conversion_offset_in_bytes() );
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   432
  Address vmarg;                // __ argument_address(vmargslot)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   433
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   434
  const int java_mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   435
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   436
  if (have_entry(ek)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   437
    __ nop();                   // empty stubs make SG sick
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   438
    return;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   439
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   440
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   441
  address interp_entry = __ pc();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   442
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   443
  trace_method_handle(_masm, entry_name(ek));
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   444
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   445
  BLOCK_COMMENT(entry_name(ek));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   446
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   447
  switch ((int) ek) {
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   448
  case _raise_exception:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   449
    {
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   450
      // Not a real MH entry, but rather shared code for raising an
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   451
      // exception.  Since we use a C2I adapter to set up the
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   452
      // interpreter state, arguments are expected in compiler
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   453
      // argument registers.
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   454
      methodHandle mh(raise_exception_method());
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   455
      address c2i_entry = methodOopDesc::make_adapters(mh, CHECK);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   456
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   457
      const Register rdi_pc = rax;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   458
      __ pop(rdi_pc);  // caller PC
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   459
      __ mov(rsp, saved_last_sp);  // cut the stack back to where the caller started
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   460
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   461
      Register rbx_method = rbx_temp;
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   462
      Label L_no_method;
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   463
      // FIXME: fill in _raise_exception_method with a suitable sun.dyn method
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   464
      __ movptr(rbx_method, ExternalAddress((address) &_raise_exception_method));
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   465
      __ testptr(rbx_method, rbx_method);
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   466
      __ jccb(Assembler::zero, L_no_method);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   467
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   468
      const int jobject_oop_offset = 0;
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   469
      __ movptr(rbx_method, Address(rbx_method, jobject_oop_offset));  // dereference the jobject
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   470
      __ testptr(rbx_method, rbx_method);
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   471
      __ jccb(Assembler::zero, L_no_method);
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   472
      __ verify_oop(rbx_method);
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   473
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   474
      // 32-bit: push remaining arguments as if coming from the compiler.
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   475
      NOT_LP64(__ push(rarg2_required));
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   476
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   477
      __ push(rdi_pc);  // restore caller PC
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   478
      __ jump(ExternalAddress(c2i_entry));  // do C2I transition
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   479
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   480
      // If we get here, the Java runtime did not do its job of creating the exception.
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   481
      // Do something that is at least causes a valid throw from the interpreter.
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   482
      __ bind(L_no_method);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   483
      __ push(rarg2_required);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   484
      __ push(rarg1_actual);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   485
      __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   486
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   487
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   488
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   489
  case _invokestatic_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   490
  case _invokespecial_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   491
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   492
      Register rbx_method = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   493
      __ load_heap_oop(rbx_method, rcx_mh_vmtarget); // target is a methodOop
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   494
      __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   495
      // same as TemplateTable::invokestatic or invokespecial,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   496
      // minus the CP setup and profiling:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   497
      if (ek == _invokespecial_mh) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   498
        // Must load & check the first argument before entering the target method.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   499
        __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   500
        __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   501
        __ null_check(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   502
        __ verify_oop(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   503
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   504
      __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   505
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   506
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   507
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   508
  case _invokevirtual_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   509
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   510
      // same as TemplateTable::invokevirtual,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   511
      // minus the CP setup and profiling:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   512
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   513
      // pick out the vtable index and receiver offset from the MH,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   514
      // and then we can discard it:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   515
      __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   516
      Register rbx_index = rbx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   517
      __ movl(rbx_index, rcx_dmh_vmindex);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   518
      // Note:  The verifier allows us to ignore rcx_mh_vmtarget.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   519
      __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   520
      __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   521
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   522
      // get receiver klass
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   523
      Register rax_klass = rax_argslot;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   524
      __ load_klass(rax_klass, rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   525
      __ verify_oop(rax_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   526
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   527
      // get target methodOop & entry point
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   528
      const int base = instanceKlass::vtable_start_offset() * wordSize;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   529
      assert(vtableEntry::size() * wordSize == wordSize, "adjust the scaling in the code below");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   530
      Address vtable_entry_addr(rax_klass,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   531
                                rbx_index, Address::times_ptr,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   532
                                base + vtableEntry::method_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   533
      Register rbx_method = rbx_temp;
4478
c3a8af0fc6b0 6829192: JSR 292 needs to support 64-bit x86
twisti
parents: 4094
diff changeset
   534
      __ movptr(rbx_method, vtable_entry_addr);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   535
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   536
      __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   537
      __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   538
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   539
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   540
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   541
  case _invokeinterface_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   542
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   543
      // same as TemplateTable::invokeinterface,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   544
      // minus the CP setup and profiling:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   545
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   546
      // pick out the interface and itable index from the MH.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   547
      __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   548
      Register rdx_intf  = rdx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   549
      Register rbx_index = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   550
      __ load_heap_oop(rdx_intf, rcx_mh_vmtarget);
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   551
      __ movl(rbx_index, rcx_dmh_vmindex);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   552
      __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   553
      __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   554
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   555
      // get receiver klass
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   556
      Register rax_klass = rax_argslot;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   557
      __ load_klass(rax_klass, rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   558
      __ verify_oop(rax_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   559
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   560
      Register rdi_temp   = rdi;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   561
      Register rbx_method = rbx_index;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   562
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   563
      // get interface klass
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   564
      Label no_such_interface;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   565
      __ verify_oop(rdx_intf);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   566
      __ lookup_interface_method(rax_klass, rdx_intf,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   567
                                 // note: next two args must be the same:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   568
                                 rbx_index, rbx_method,
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   569
                                 rdi_temp,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   570
                                 no_such_interface);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   571
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   572
      __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   573
      __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   574
      __ hlt();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   575
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   576
      __ bind(no_such_interface);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   577
      // Throw an exception.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   578
      // For historical reasons, it will be IncompatibleClassChangeError.
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   579
      __ mov(rbx_temp, rcx_recv);  // rarg2_required might be RCX
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   580
      assert_different_registers(rarg2_required, rbx_temp);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   581
      __ movptr(rarg2_required, Address(rdx_intf, java_mirror_offset));  // required interface
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   582
      __ mov(   rarg1_actual,   rbx_temp);                               // bad receiver
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   583
      __ movl(  rarg0_code,     (int) Bytecodes::_invokeinterface);      // who is complaining?
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   584
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   585
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   586
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   587
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   588
  case _bound_ref_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   589
  case _bound_int_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   590
  case _bound_long_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   591
  case _bound_ref_direct_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   592
  case _bound_int_direct_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   593
  case _bound_long_direct_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   594
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   595
      bool direct_to_method = (ek >= _bound_ref_direct_mh);
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   596
      BasicType arg_type  = T_ILLEGAL;
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   597
      int       arg_mask  = _INSERT_NO_MASK;
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   598
      int       arg_slots = -1;
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   599
      get_ek_bound_mh_info(ek, arg_type, arg_mask, arg_slots);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   600
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   601
      // make room for the new argument:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   602
      __ movl(rax_argslot, rcx_bmh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   603
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   604
      insert_arg_slots(_masm, arg_slots * stack_move_unit(), arg_mask,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   605
                       rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   606
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   607
      // store bound argument into the new stack slot:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   608
      __ load_heap_oop(rbx_temp, rcx_bmh_argument);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   609
      Address prim_value_addr(rbx_temp, java_lang_boxing_object::value_offset_in_bytes(arg_type));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   610
      if (arg_type == T_OBJECT) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   611
        __ movptr(Address(rax_argslot, 0), rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   612
      } else {
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   613
        __ load_sized_value(rdx_temp, prim_value_addr,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   614
                            type2aelembytes(arg_type), is_signed_subword_type(arg_type));
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   615
        __ movptr(Address(rax_argslot, 0), rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   616
#ifndef _LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   617
        if (arg_slots == 2) {
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   618
          __ movl(rdx_temp, prim_value_addr.plus_disp(wordSize));
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
   619
          __ movl(Address(rax_argslot, Interpreter::stackElementSize), rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   620
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   621
#endif //_LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   622
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   623
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   624
      if (direct_to_method) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   625
        Register rbx_method = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   626
        __ load_heap_oop(rbx_method, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   627
        __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   628
        __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   629
      } else {
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   630
        __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   631
        __ verify_oop(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   632
        __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   633
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   634
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   635
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   636
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   637
  case _adapter_retype_only:
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   638
  case _adapter_retype_raw:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   639
    // immediately jump to the next MH layer:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   640
    __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   641
    __ verify_oop(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   642
    __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   643
    // This is OK when all parameter types widen.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   644
    // It is also OK when a return type narrows.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   645
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   646
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   647
  case _adapter_check_cast:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   648
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   649
      // temps:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   650
      Register rbx_klass = rbx_temp; // interesting AMH data
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   651
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   652
      // check a reference argument before jumping to the next layer of MH:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   653
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   654
      vmarg = __ argument_address(rax_argslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   655
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   656
      // What class are we casting to?
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   657
      __ load_heap_oop(rbx_klass, rcx_amh_argument); // this is a Class object!
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   658
      __ load_heap_oop(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes()));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   659
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   660
      Label done;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   661
      __ movptr(rdx_temp, vmarg);
5028
5a7f933d81c1 6928839: JSR 292 typo in x86 _adapter_check_cast
twisti
parents: 4564
diff changeset
   662
      __ testptr(rdx_temp, rdx_temp);
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   663
      __ jcc(Assembler::zero, done);         // no cast if null
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   664
      __ load_klass(rdx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   665
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   666
      // live at this point:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   667
      // - rbx_klass:  klass required by the target method
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   668
      // - rdx_temp:   argument klass to test
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   669
      // - rcx_recv:   adapter method handle
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   670
      __ check_klass_subtype(rdx_temp, rbx_klass, rax_argslot, done);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   671
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   672
      // If we get here, the type check failed!
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   673
      // Call the wrong_method_type stub, passing the failing argument type in rax.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   674
      Register rax_mtype = rax_argslot;
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   675
      __ movl(rax_argslot, rcx_amh_vmargslot);  // reload argslot field
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   676
      __ movptr(rdx_temp, vmarg);
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   677
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   678
      assert_different_registers(rarg2_required, rdx_temp);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   679
      __ load_heap_oop(rarg2_required, rcx_amh_argument);             // required class
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   680
      __ mov(          rarg1_actual,   rdx_temp);                     // bad object
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
   681
      __ movl(         rarg0_code,     (int) Bytecodes::_checkcast);  // who is complaining?
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   682
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   683
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   684
      __ bind(done);
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
   685
      // get the new MH:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   686
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   687
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   688
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   689
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   690
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   691
  case _adapter_prim_to_prim:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   692
  case _adapter_ref_to_prim:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   693
    // handled completely by optimized cases
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   694
    __ stop("init_AdapterMethodHandle should not issue this");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   695
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   696
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   697
  case _adapter_opt_i2i:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   698
//case _adapter_opt_f2i:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   699
  case _adapter_opt_l2i:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   700
  case _adapter_opt_unboxi:     // optimized subcase of adapt_ref_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   701
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   702
      // perform an in-place conversion to int or an int subword
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   703
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   704
      vmarg = __ argument_address(rax_argslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   705
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   706
      switch (ek) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   707
      case _adapter_opt_i2i:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   708
        __ movl(rdx_temp, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   709
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   710
      case _adapter_opt_l2i:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   711
        {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   712
          // just delete the extra slot; on a little-endian machine we keep the first
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   713
          __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   714
          remove_arg_slots(_masm, -stack_move_unit(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   715
                           rax_argslot, rbx_temp, rdx_temp);
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
   716
          vmarg = Address(rax_argslot, -Interpreter::stackElementSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   717
          __ movl(rdx_temp, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   718
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   719
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   720
      case _adapter_opt_unboxi:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   721
        {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   722
          // Load the value up from the heap.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   723
          __ movptr(rdx_temp, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   724
          int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_INT);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   725
#ifdef ASSERT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   726
          for (int bt = T_BOOLEAN; bt < T_INT; bt++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   727
            if (is_subword_type(BasicType(bt)))
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   728
              assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(BasicType(bt)), "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   729
          }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   730
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   731
          __ null_check(rdx_temp, value_offset);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   732
          __ movl(rdx_temp, Address(rdx_temp, value_offset));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   733
          // We load this as a word.  Because we are little-endian,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   734
          // the low bits will be correct, but the high bits may need cleaning.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   735
          // The vminfo will guide us to clean those bits.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   736
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   737
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   738
      default:
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   739
        ShouldNotReachHere();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   740
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   741
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   742
      // Do the requested conversion and store the value.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   743
      Register rbx_vminfo = rbx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   744
      __ movl(rbx_vminfo, rcx_amh_conversion);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   745
      assert(CONV_VMINFO_SHIFT == 0, "preshifted");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   746
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   747
      // get the new MH:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   748
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   749
      // (now we are done with the old MH)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   750
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   751
      // original 32-bit vmdata word must be of this form:
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   752
      //    | MBZ:6 | signBitCount:8 | srcDstTypes:8 | conversionOp:8 |
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   753
      __ xchgptr(rcx, rbx_vminfo);                // free rcx for shifts
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   754
      __ shll(rdx_temp /*, rcx*/);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   755
      Label zero_extend, done;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   756
      __ testl(rcx, CONV_VMINFO_SIGN_FLAG);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   757
      __ jccb(Assembler::zero, zero_extend);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   758
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   759
      // this path is taken for int->byte, int->short
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   760
      __ sarl(rdx_temp /*, rcx*/);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   761
      __ jmpb(done);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   762
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   763
      __ bind(zero_extend);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   764
      // this is taken for int->char
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   765
      __ shrl(rdx_temp /*, rcx*/);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   766
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   767
      __ bind(done);
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   768
      __ movl(vmarg, rdx_temp);  // Store the value.
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   769
      __ xchgptr(rcx, rbx_vminfo);                // restore rcx_recv
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   770
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   771
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   772
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   773
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   774
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   775
  case _adapter_opt_i2l:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   776
  case _adapter_opt_unboxl:     // optimized subcase of adapt_ref_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   777
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   778
      // perform an in-place int-to-long or ref-to-long conversion
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   779
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   780
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   781
      // on a little-endian machine we keep the first slot and add another after
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   782
      __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   783
      insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   784
                       rax_argslot, rbx_temp, rdx_temp);
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
   785
      Address vmarg1(rax_argslot, -Interpreter::stackElementSize);
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
   786
      Address vmarg2 = vmarg1.plus_disp(Interpreter::stackElementSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   787
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   788
      switch (ek) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   789
      case _adapter_opt_i2l:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   790
        {
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   791
#ifdef _LP64
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   792
          __ movslq(rdx_temp, vmarg1);  // Load sign-extended
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   793
          __ movq(vmarg1, rdx_temp);    // Store into first slot
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   794
#else
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   795
          __ movl(rdx_temp, vmarg1);
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   796
          __ sarl(rdx_temp, BitsPerInt - 1);  // __ extend_sign()
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   797
          __ movl(vmarg2, rdx_temp); // store second word
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   798
#endif
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   799
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   800
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   801
      case _adapter_opt_unboxl:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   802
        {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   803
          // Load the value up from the heap.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   804
          __ movptr(rdx_temp, vmarg1);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   805
          int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_LONG);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   806
          assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE), "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   807
          __ null_check(rdx_temp, value_offset);
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   808
#ifdef _LP64
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   809
          __ movq(rbx_temp, Address(rdx_temp, value_offset));
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   810
          __ movq(vmarg1, rbx_temp);
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   811
#else
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   812
          __ movl(rbx_temp, Address(rdx_temp, value_offset + 0*BytesPerInt));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   813
          __ movl(rdx_temp, Address(rdx_temp, value_offset + 1*BytesPerInt));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   814
          __ movl(vmarg1, rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   815
          __ movl(vmarg2, rdx_temp);
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   816
#endif
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   817
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   818
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   819
      default:
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   820
        ShouldNotReachHere();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   821
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   822
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   823
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   824
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   825
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   826
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   827
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   828
  case _adapter_opt_f2d:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   829
  case _adapter_opt_d2f:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   830
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   831
      // perform an in-place floating primitive conversion
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   832
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   833
      __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   834
      if (ek == _adapter_opt_f2d) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   835
        insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   836
                         rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   837
      }
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
   838
      Address vmarg(rax_argslot, -Interpreter::stackElementSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   839
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   840
#ifdef _LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   841
      if (ek == _adapter_opt_f2d) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   842
        __ movflt(xmm0, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   843
        __ cvtss2sd(xmm0, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   844
        __ movdbl(vmarg, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   845
      } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   846
        __ movdbl(xmm0, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   847
        __ cvtsd2ss(xmm0, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   848
        __ movflt(vmarg, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   849
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   850
#else //_LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   851
      if (ek == _adapter_opt_f2d) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   852
        __ fld_s(vmarg);        // load float to ST0
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   853
        __ fstp_s(vmarg);       // store single
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   854
      } else {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   855
        __ fld_d(vmarg);        // load double to ST0
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   856
        __ fstp_s(vmarg);       // store single
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   857
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   858
#endif //_LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   859
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   860
      if (ek == _adapter_opt_d2f) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   861
        remove_arg_slots(_masm, -stack_move_unit(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   862
                         rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   863
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   864
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   865
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   866
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   867
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   868
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   869
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   870
  case _adapter_prim_to_ref:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   871
    __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   872
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   873
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   874
  case _adapter_swap_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   875
  case _adapter_rot_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   876
    // handled completely by optimized cases
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   877
    __ stop("init_AdapterMethodHandle should not issue this");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   878
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   879
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   880
  case _adapter_opt_swap_1:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   881
  case _adapter_opt_swap_2:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   882
  case _adapter_opt_rot_1_up:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   883
  case _adapter_opt_rot_1_down:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   884
  case _adapter_opt_rot_2_up:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   885
  case _adapter_opt_rot_2_down:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   886
    {
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   887
      int swap_bytes = 0, rotate = 0;
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   888
      get_ek_adapter_opt_swap_rot_info(ek, swap_bytes, rotate);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   889
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   890
      // 'argslot' is the position of the first argument to swap
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   891
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   892
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   893
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   894
      // 'vminfo' is the second
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   895
      Register rbx_destslot = rbx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   896
      __ movl(rbx_destslot, rcx_amh_conversion);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   897
      assert(CONV_VMINFO_SHIFT == 0, "preshifted");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   898
      __ andl(rbx_destslot, CONV_VMINFO_MASK);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   899
      __ lea(rbx_destslot, __ argument_address(rbx_destslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   900
      DEBUG_ONLY(verify_argslot(_masm, rbx_destslot, "swap point must fall within current frame"));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   901
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   902
      if (!rotate) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   903
        for (int i = 0; i < swap_bytes; i += wordSize) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   904
          __ movptr(rdx_temp, Address(rax_argslot , i));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   905
          __ push(rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   906
          __ movptr(rdx_temp, Address(rbx_destslot, i));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   907
          __ movptr(Address(rax_argslot, i), rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   908
          __ pop(rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   909
          __ movptr(Address(rbx_destslot, i), rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   910
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   911
      } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   912
        // push the first chunk, which is going to get overwritten
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   913
        for (int i = swap_bytes; (i -= wordSize) >= 0; ) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   914
          __ movptr(rdx_temp, Address(rax_argslot, i));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   915
          __ push(rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   916
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   917
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   918
        if (rotate > 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   919
          // rotate upward
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   920
          __ subptr(rax_argslot, swap_bytes);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   921
#ifdef ASSERT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   922
          {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   923
            // Verify that argslot > destslot, by at least swap_bytes.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   924
            Label L_ok;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   925
            __ cmpptr(rax_argslot, rbx_destslot);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   926
            __ jccb(Assembler::aboveEqual, L_ok);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   927
            __ stop("source must be above destination (upward rotation)");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   928
            __ bind(L_ok);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   929
          }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   930
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   931
          // work argslot down to destslot, copying contiguous data upwards
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   932
          // pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   933
          //   rax = src_addr - swap_bytes
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   934
          //   rbx = dest_addr
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   935
          //   while (rax >= rbx) *(rax + swap_bytes) = *(rax + 0), rax--;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   936
          Label loop;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   937
          __ bind(loop);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   938
          __ movptr(rdx_temp, Address(rax_argslot, 0));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   939
          __ movptr(Address(rax_argslot, swap_bytes), rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   940
          __ addptr(rax_argslot, -wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   941
          __ cmpptr(rax_argslot, rbx_destslot);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   942
          __ jccb(Assembler::aboveEqual, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   943
        } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   944
          __ addptr(rax_argslot, swap_bytes);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   945
#ifdef ASSERT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   946
          {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   947
            // Verify that argslot < destslot, by at least swap_bytes.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   948
            Label L_ok;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   949
            __ cmpptr(rax_argslot, rbx_destslot);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   950
            __ jccb(Assembler::belowEqual, L_ok);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   951
            __ stop("source must be below destination (downward rotation)");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   952
            __ bind(L_ok);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   953
          }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   954
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   955
          // work argslot up to destslot, copying contiguous data downwards
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   956
          // pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   957
          //   rax = src_addr + swap_bytes
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   958
          //   rbx = dest_addr
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   959
          //   while (rax <= rbx) *(rax - swap_bytes) = *(rax + 0), rax++;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   960
          Label loop;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   961
          __ bind(loop);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   962
          __ movptr(rdx_temp, Address(rax_argslot, 0));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   963
          __ movptr(Address(rax_argslot, -swap_bytes), rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   964
          __ addptr(rax_argslot, wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   965
          __ cmpptr(rax_argslot, rbx_destslot);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   966
          __ jccb(Assembler::belowEqual, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   967
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   968
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   969
        // pop the original first chunk into the destination slot, now free
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   970
        for (int i = 0; i < swap_bytes; i += wordSize) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   971
          __ pop(rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   972
          __ movptr(Address(rbx_destslot, i), rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   973
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   974
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   975
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   976
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   977
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   978
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   979
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   980
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   981
  case _adapter_dup_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   982
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   983
      // 'argslot' is the position of the first argument to duplicate
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   984
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   985
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   986
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   987
      // 'stack_move' is negative number of words to duplicate
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   988
      Register rdx_stack_move = rdx_temp;
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   989
      __ movl2ptr(rdx_stack_move, rcx_amh_conversion);
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
   990
      __ sarptr(rdx_stack_move, CONV_STACK_MOVE_SHIFT);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   991
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   992
      int argslot0_num = 0;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   993
      Address argslot0 = __ argument_address(RegisterOrConstant(argslot0_num));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   994
      assert(argslot0.base() == rsp, "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   995
      int pre_arg_size = argslot0.disp();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   996
      assert(pre_arg_size % wordSize == 0, "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   997
      assert(pre_arg_size > 0, "must include PC");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   998
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   999
      // remember the old rsp+1 (argslot[0])
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1000
      Register rbx_oldarg = rbx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1001
      __ lea(rbx_oldarg, argslot0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1002
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1003
      // move rsp down to make room for dups
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1004
      __ lea(rsp, Address(rsp, rdx_stack_move, Address::times_ptr));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1005
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1006
      // compute the new rsp+1 (argslot[0])
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1007
      Register rdx_newarg = rdx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1008
      __ lea(rdx_newarg, argslot0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1009
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1010
      __ push(rdi);             // need a temp
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1011
      // (preceding push must be done after arg addresses are taken!)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1012
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1013
      // pull down the pre_arg_size data (PC)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1014
      for (int i = -pre_arg_size; i < 0; i += wordSize) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1015
        __ movptr(rdi, Address(rbx_oldarg, i));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1016
        __ movptr(Address(rdx_newarg, i), rdi);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1017
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1018
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1019
      // copy from rax_argslot[0...] down to new_rsp[1...]
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1020
      // pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1021
      //   rbx = old_rsp+1
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1022
      //   rdx = new_rsp+1
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1023
      //   rax = argslot
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1024
      //   while (rdx < rbx) *rdx++ = *rax++
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1025
      Label loop;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1026
      __ bind(loop);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1027
      __ movptr(rdi, Address(rax_argslot, 0));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1028
      __ movptr(Address(rdx_newarg, 0), rdi);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1029
      __ addptr(rax_argslot, wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1030
      __ addptr(rdx_newarg, wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1031
      __ cmpptr(rdx_newarg, rbx_oldarg);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
  1032
      __ jccb(Assembler::less, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1033
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1034
      __ pop(rdi);              // restore temp
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1035
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1036
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1037
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1038
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1039
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1040
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1041
  case _adapter_drop_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1042
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1043
      // 'argslot' is the position of the first argument to nuke
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1044
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1045
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1046
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1047
      __ push(rdi);             // need a temp
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1048
      // (must do previous push after argslot address is taken)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1049
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1050
      // 'stack_move' is number of words to drop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1051
      Register rdi_stack_move = rdi;
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1052
      __ movl2ptr(rdi_stack_move, rcx_amh_conversion);
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1053
      __ sarptr(rdi_stack_move, CONV_STACK_MOVE_SHIFT);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1054
      remove_arg_slots(_masm, rdi_stack_move,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1055
                       rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1056
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1057
      __ pop(rdi);              // restore temp
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1058
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1059
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1060
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1061
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1062
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1063
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1064
  case _adapter_collect_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1065
    __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1066
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1067
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1068
  case _adapter_spread_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1069
    // handled completely by optimized cases
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1070
    __ stop("init_AdapterMethodHandle should not issue this");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1071
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1072
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1073
  case _adapter_opt_spread_0:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1074
  case _adapter_opt_spread_1:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1075
  case _adapter_opt_spread_more:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1076
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1077
      // spread an array out into a group of arguments
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
  1078
      int length_constant = get_ek_adapter_opt_spread_info(ek);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1079
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1080
      // find the address of the array argument
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1081
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1082
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1083
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1084
      // grab some temps
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1085
      { __ push(rsi); __ push(rdi); }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1086
      // (preceding pushes must be done after argslot address is taken!)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1087
#define UNPUSH_RSI_RDI \
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1088
      { __ pop(rdi); __ pop(rsi); }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1089
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1090
      // arx_argslot points both to the array and to the first output arg
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1091
      vmarg = Address(rax_argslot, 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1092
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1093
      // Get the array value.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1094
      Register  rsi_array       = rsi;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1095
      Register  rdx_array_klass = rdx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1096
      BasicType elem_type       = T_OBJECT;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1097
      int       length_offset   = arrayOopDesc::length_offset_in_bytes();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1098
      int       elem0_offset    = arrayOopDesc::base_offset_in_bytes(elem_type);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1099
      __ movptr(rsi_array, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1100
      Label skip_array_check;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1101
      if (length_constant == 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1102
        __ testptr(rsi_array, rsi_array);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1103
        __ jcc(Assembler::zero, skip_array_check);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1104
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1105
      __ null_check(rsi_array, oopDesc::klass_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1106
      __ load_klass(rdx_array_klass, rsi_array);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1107
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1108
      // Check the array type.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1109
      Register rbx_klass = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1110
      __ load_heap_oop(rbx_klass, rcx_amh_argument); // this is a Class object!
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1111
      __ load_heap_oop(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes()));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1112
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1113
      Label ok_array_klass, bad_array_klass, bad_array_length;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1114
      __ check_klass_subtype(rdx_array_klass, rbx_klass, rdi, ok_array_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1115
      // If we get here, the type check failed!
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1116
      __ jmp(bad_array_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1117
      __ bind(ok_array_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1118
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1119
      // Check length.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1120
      if (length_constant >= 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1121
        __ cmpl(Address(rsi_array, length_offset), length_constant);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1122
      } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1123
        Register rbx_vminfo = rbx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1124
        __ movl(rbx_vminfo, rcx_amh_conversion);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1125
        assert(CONV_VMINFO_SHIFT == 0, "preshifted");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1126
        __ andl(rbx_vminfo, CONV_VMINFO_MASK);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1127
        __ cmpl(rbx_vminfo, Address(rsi_array, length_offset));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1128
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1129
      __ jcc(Assembler::notEqual, bad_array_length);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1130
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1131
      Register rdx_argslot_limit = rdx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1132
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1133
      // Array length checks out.  Now insert any required stack slots.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1134
      if (length_constant == -1) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1135
        // Form a pointer to the end of the affected region.
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  1136
        __ lea(rdx_argslot_limit, Address(rax_argslot, Interpreter::stackElementSize));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1137
        // 'stack_move' is negative number of words to insert
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1138
        Register rdi_stack_move = rdi;
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1139
        __ movl2ptr(rdi_stack_move, rcx_amh_conversion);
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1140
        __ sarptr(rdi_stack_move, CONV_STACK_MOVE_SHIFT);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1141
        Register rsi_temp = rsi_array;  // spill this
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1142
        insert_arg_slots(_masm, rdi_stack_move, -1,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1143
                         rax_argslot, rbx_temp, rsi_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1144
        // reload the array (since rsi was killed)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1145
        __ movptr(rsi_array, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1146
      } else if (length_constant > 1) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1147
        int arg_mask = 0;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1148
        int new_slots = (length_constant - 1);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1149
        for (int i = 0; i < new_slots; i++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1150
          arg_mask <<= 1;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1151
          arg_mask |= _INSERT_REF_MASK;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1152
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1153
        insert_arg_slots(_masm, new_slots * stack_move_unit(), arg_mask,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1154
                         rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1155
      } else if (length_constant == 1) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1156
        // no stack resizing required
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1157
      } else if (length_constant == 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1158
        remove_arg_slots(_masm, -stack_move_unit(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1159
                         rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1160
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1161
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1162
      // Copy from the array to the new slots.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1163
      // Note: Stack change code preserves integrity of rax_argslot pointer.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1164
      // So even after slot insertions, rax_argslot still points to first argument.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1165
      if (length_constant == -1) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1166
        // [rax_argslot, rdx_argslot_limit) is the area we are inserting into.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1167
        Register rsi_source = rsi_array;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1168
        __ lea(rsi_source, Address(rsi_array, elem0_offset));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1169
        Label loop;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1170
        __ bind(loop);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1171
        __ movptr(rbx_temp, Address(rsi_source, 0));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1172
        __ movptr(Address(rax_argslot, 0), rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1173
        __ addptr(rsi_source, type2aelembytes(elem_type));
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  1174
        __ addptr(rax_argslot, Interpreter::stackElementSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1175
        __ cmpptr(rax_argslot, rdx_argslot_limit);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
  1176
        __ jccb(Assembler::less, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1177
      } else if (length_constant == 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1178
        __ bind(skip_array_check);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1179
        // nothing to copy
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1180
      } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1181
        int elem_offset = elem0_offset;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1182
        int slot_offset = 0;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1183
        for (int index = 0; index < length_constant; index++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1184
          __ movptr(rbx_temp, Address(rsi_array, elem_offset));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1185
          __ movptr(Address(rax_argslot, slot_offset), rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1186
          elem_offset += type2aelembytes(elem_type);
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  1187
           slot_offset += Interpreter::stackElementSize;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1188
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1189
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1190
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1191
      // Arguments are spread.  Move to next method handle.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1192
      UNPUSH_RSI_RDI;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1193
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1194
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1195
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1196
      __ bind(bad_array_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1197
      UNPUSH_RSI_RDI;
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1198
      assert(!vmarg.uses(rarg2_required), "must be different registers");
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1199
      __ movptr(rarg2_required, Address(rdx_array_klass, java_mirror_offset));  // required type
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1200
      __ movptr(rarg1_actual,   vmarg);                                         // bad array
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1201
      __ movl(  rarg0_code,     (int) Bytecodes::_aaload);                      // who is complaining?
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1202
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1203
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1204
      __ bind(bad_array_length);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1205
      UNPUSH_RSI_RDI;
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1206
      assert(!vmarg.uses(rarg2_required), "must be different registers");
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1207
      __ mov   (rarg2_required, rcx_recv);                       // AMH requiring a certain length
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1208
      __ movptr(rarg1_actual,   vmarg);                          // bad array
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1209
      __ movl(  rarg0_code,     (int) Bytecodes::_arraylength);  // who is complaining?
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1210
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1211
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1212
#undef UNPUSH_RSI_RDI
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1213
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1214
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1215
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1216
  case _adapter_flyby:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1217
  case _adapter_ricochet:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1218
    __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1219
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1220
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1221
  default:  ShouldNotReachHere();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1222
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1223
  __ hlt();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1224
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1225
  address me_cookie = MethodHandleEntry::start_compiled_entry(_masm, interp_entry);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1226
  __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1227
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1228
  init_entry(ek, MethodHandleEntry::finish_compiled_entry(_masm, me_cookie));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1229
}