hotspot/src/cpu/x86/vm/methodHandles_x86.cpp
author never
Fri, 06 May 2011 16:33:13 -0700
changeset 9630 d6419e4395e3
parent 9437 9981851b4b8c
child 9638 a9e79f5cd83b
permissions -rw-r--r--
6939861: JVM should handle more conversion operations Reviewed-by: twisti, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     1
/*
7887
7aa0354cbf25 7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents: 7712
diff changeset
     2
 * Copyright (c) 1997, 2011, 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
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    72
// stack walking support
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    73
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    74
frame MethodHandles::ricochet_frame_sender(const frame& fr, RegisterMap *map) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    75
  RicochetFrame* f = RicochetFrame::from_frame(fr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    76
  if (map->update_map())
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    77
    frame::update_map_with_saved_link(map, &f->_sender_link);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    78
  return frame(f->extended_sender_sp(), f->exact_sender_sp(), f->sender_link(), f->sender_pc());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    79
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    80
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    81
void MethodHandles::ricochet_frame_oops_do(const frame& fr, OopClosure* blk, const RegisterMap* reg_map) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    82
  RicochetFrame* f = RicochetFrame::from_frame(fr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    83
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    84
  // pick up the argument type descriptor:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    85
  Thread* thread = Thread::current();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    86
  Handle cookie(thread, f->compute_saved_args_layout(true, true));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    87
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    88
  // process fixed part
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    89
  blk->do_oop((oop*)f->saved_target_addr());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    90
  blk->do_oop((oop*)f->saved_args_layout_addr());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    91
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    92
  // process variable arguments:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    93
  if (cookie.is_null())  return;  // no arguments to describe
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    94
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    95
  // the cookie is actually the invokeExact method for my target
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    96
  // his argument signature is what I'm interested in
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    97
  assert(cookie->is_method(), "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    98
  methodHandle invoker(thread, methodOop(cookie()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
    99
  assert(invoker->name() == vmSymbols::invokeExact_name(), "must be this kind of method");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   100
  assert(!invoker->is_static(), "must have MH argument");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   101
  int slot_count = invoker->size_of_parameters();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   102
  assert(slot_count >= 1, "must include 'this'");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   103
  intptr_t* base = f->saved_args_base();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   104
  intptr_t* retval = NULL;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   105
  if (f->has_return_value_slot())
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   106
    retval = f->return_value_slot_addr();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   107
  int slot_num = slot_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   108
  intptr_t* loc = &base[slot_num -= 1];
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   109
  //blk->do_oop((oop*) loc);   // original target, which is irrelevant
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   110
  int arg_num = 0;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   111
  for (SignatureStream ss(invoker->signature()); !ss.is_done(); ss.next()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   112
    if (ss.at_return_type())  continue;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   113
    BasicType ptype = ss.type();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   114
    if (ptype == T_ARRAY)  ptype = T_OBJECT; // fold all refs to T_OBJECT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   115
    assert(ptype >= T_BOOLEAN && ptype <= T_OBJECT, "not array or void");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   116
    loc = &base[slot_num -= type2size[ptype]];
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   117
    bool is_oop = (ptype == T_OBJECT && loc != retval);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   118
    if (is_oop)  blk->do_oop((oop*)loc);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   119
    arg_num += 1;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   120
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   121
  assert(slot_num == 0, "must have processed all the arguments");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   122
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   123
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   124
oop MethodHandles::RicochetFrame::compute_saved_args_layout(bool read_cache, bool write_cache) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   125
  oop cookie = NULL;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   126
  if (read_cache) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   127
    cookie = saved_args_layout();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   128
    if (cookie != NULL)  return cookie;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   129
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   130
  oop target = saved_target();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   131
  oop mtype  = java_lang_invoke_MethodHandle::type(target);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   132
  oop mtform = java_lang_invoke_MethodType::form(mtype);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   133
  cookie = java_lang_invoke_MethodTypeForm::vmlayout(mtform);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   134
  if (write_cache)  {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   135
    (*saved_args_layout_addr()) = cookie;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   136
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   137
  return cookie;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   138
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   139
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   140
void MethodHandles::RicochetFrame::generate_ricochet_blob(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   141
                                                          // output params:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   142
                                                          int* frame_size_in_words,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   143
                                                          int* bounce_offset,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   144
                                                          int* exception_offset) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   145
  (*frame_size_in_words) = RicochetFrame::frame_size_in_bytes() / wordSize;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   146
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   147
  address start = __ pc();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   148
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   149
#ifdef ASSERT
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   150
  __ hlt(); __ hlt(); __ hlt();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   151
  // here's a hint of something special:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   152
  __ push(MAGIC_NUMBER_1);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   153
  __ push(MAGIC_NUMBER_2);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   154
#endif //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   155
  __ hlt();  // not reached
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   156
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   157
  // A return PC has just been popped from the stack.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   158
  // Return values are in registers.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   159
  // The ebp points into the RicochetFrame, which contains
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   160
  // a cleanup continuation we must return to.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   161
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   162
  (*bounce_offset) = __ pc() - start;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   163
  BLOCK_COMMENT("ricochet_blob.bounce");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   164
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   165
  if (VerifyMethodHandles)  RicochetFrame::verify_clean(_masm);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   166
  trace_method_handle(_masm, "ricochet_blob.bounce");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   167
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   168
  __ jmp(frame_address(continuation_offset_in_bytes()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   169
  __ hlt();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   170
  DEBUG_ONLY(__ push(MAGIC_NUMBER_2));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   171
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   172
  (*exception_offset) = __ pc() - start;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   173
  BLOCK_COMMENT("ricochet_blob.exception");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   174
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   175
  // compare this to Interpreter::rethrow_exception_entry, which is parallel code
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   176
  // for example, see TemplateInterpreterGenerator::generate_throw_exception
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   177
  // Live registers in:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   178
  //   rax: exception
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   179
  //   rdx: return address/pc that threw exception (ignored, always equal to bounce addr)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   180
  __ verify_oop(rax);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   181
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   182
  // no need to empty_FPU_stack or reinit_heapbase, since caller frame will do the same if needed
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   183
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   184
  // Take down the frame.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   185
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   186
  // Cf. InterpreterMacroAssembler::remove_activation.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   187
  leave_ricochet_frame(_masm, /*rcx_recv=*/ noreg,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   188
                       saved_last_sp_register(),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   189
                       /*sender_pc_reg=*/ rdx);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   190
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   191
  // In between activations - previous activation type unknown yet
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   192
  // compute continuation point - the continuation point expects the
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   193
  // following registers set up:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   194
  //
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   195
  // rax: exception
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   196
  // rdx: return address/pc that threw exception
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   197
  // rsp: expression stack of caller
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   198
  // rbp: ebp of caller
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   199
  __ push(rax);                                  // save exception
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   200
  __ push(rdx);                                  // save return address
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   201
  Register thread_reg = LP64_ONLY(r15_thread) NOT_LP64(rdi);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   202
  NOT_LP64(__ get_thread(thread_reg));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   203
  __ call_VM_leaf(CAST_FROM_FN_PTR(address,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   204
                                   SharedRuntime::exception_handler_for_return_address),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   205
                  thread_reg, rdx);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   206
  __ mov(rbx, rax);                              // save exception handler
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   207
  __ pop(rdx);                                   // restore return address
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   208
  __ pop(rax);                                   // restore exception
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   209
  __ jmp(rbx);                                   // jump to exception
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   210
                                                 // handler of caller
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   211
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   212
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   213
void MethodHandles::RicochetFrame::enter_ricochet_frame(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   214
                                                        Register rcx_recv,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   215
                                                        Register rax_argv,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   216
                                                        address return_handler,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   217
                                                        Register rbx_temp) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   218
  const Register saved_last_sp = saved_last_sp_register();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   219
  Address rcx_mh_vmtarget(    rcx_recv, java_lang_invoke_MethodHandle::vmtarget_offset_in_bytes() );
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   220
  Address rcx_amh_conversion( rcx_recv, java_lang_invoke_AdapterMethodHandle::conversion_offset_in_bytes() );
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   221
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   222
  // Push the RicochetFrame a word at a time.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   223
  // This creates something similar to an interpreter frame.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   224
  // Cf. TemplateInterpreterGenerator::generate_fixed_frame.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   225
  BLOCK_COMMENT("push RicochetFrame {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   226
  DEBUG_ONLY(int rfo = (int) sizeof(RicochetFrame));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   227
  assert((rfo -= wordSize) == RicochetFrame::sender_pc_offset_in_bytes(), "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   228
#define RF_FIELD(push_value, name)                                      \
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   229
  { push_value;                                                         \
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   230
    assert((rfo -= wordSize) == RicochetFrame::name##_offset_in_bytes(), ""); }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   231
  RF_FIELD(__ push(rbp),                   sender_link);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   232
  RF_FIELD(__ push(saved_last_sp),         exact_sender_sp);  // rsi/r13
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   233
  RF_FIELD(__ pushptr(rcx_amh_conversion), conversion);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   234
  RF_FIELD(__ push(rax_argv),              saved_args_base);   // can be updated if args are shifted
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   235
  RF_FIELD(__ push((int32_t) NULL_WORD),   saved_args_layout); // cache for GC layout cookie
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   236
  if (UseCompressedOops) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   237
    __ load_heap_oop(rbx_temp, rcx_mh_vmtarget);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   238
    RF_FIELD(__ push(rbx_temp),            saved_target);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   239
  } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   240
    RF_FIELD(__ pushptr(rcx_mh_vmtarget),  saved_target);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   241
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   242
  __ lea(rbx_temp, ExternalAddress(return_handler));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   243
  RF_FIELD(__ push(rbx_temp),              continuation);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   244
#undef RF_FIELD
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   245
  assert(rfo == 0, "fully initialized the RicochetFrame");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   246
  // compute new frame pointer:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   247
  __ lea(rbp, Address(rsp, RicochetFrame::sender_link_offset_in_bytes()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   248
  // Push guard word #1 in debug mode.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   249
  DEBUG_ONLY(__ push((int32_t) RicochetFrame::MAGIC_NUMBER_1));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   250
  // For debugging, leave behind an indication of which stub built this frame.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   251
  DEBUG_ONLY({ Label L; __ call(L, relocInfo::none); __ bind(L); });
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   252
  BLOCK_COMMENT("} RicochetFrame");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   253
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   254
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   255
void MethodHandles::RicochetFrame::leave_ricochet_frame(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   256
                                                        Register rcx_recv,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   257
                                                        Register new_sp_reg,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   258
                                                        Register sender_pc_reg) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   259
  assert_different_registers(rcx_recv, new_sp_reg, sender_pc_reg);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   260
  const Register saved_last_sp = saved_last_sp_register();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   261
  // Take down the frame.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   262
  // Cf. InterpreterMacroAssembler::remove_activation.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   263
  BLOCK_COMMENT("end_ricochet_frame {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   264
  // TO DO: If (exact_sender_sp - extended_sender_sp) > THRESH, compact the frame down.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   265
  // This will keep stack in bounds even with unlimited tailcalls, each with an adapter.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   266
  if (rcx_recv->is_valid())
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   267
    __ movptr(rcx_recv,    RicochetFrame::frame_address(RicochetFrame::saved_target_offset_in_bytes()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   268
  __ movptr(sender_pc_reg, RicochetFrame::frame_address(RicochetFrame::sender_pc_offset_in_bytes()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   269
  __ movptr(saved_last_sp, RicochetFrame::frame_address(RicochetFrame::exact_sender_sp_offset_in_bytes()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   270
  __ movptr(rbp,           RicochetFrame::frame_address(RicochetFrame::sender_link_offset_in_bytes()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   271
  __ mov(rsp, new_sp_reg);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   272
  BLOCK_COMMENT("} end_ricochet_frame");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   273
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   274
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   275
// Emit code to verify that RBP is pointing at a valid ricochet frame.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   276
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   277
enum {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   278
  ARG_LIMIT = 255, SLOP = 4,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   279
  // use this parameter for checking for garbage stack movements:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   280
  UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   281
  // the slop defends against false alarms due to fencepost errors
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   282
};
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   283
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   284
void MethodHandles::RicochetFrame::verify_clean(MacroAssembler* _masm) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   285
  // The stack should look like this:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   286
  //    ... keep1 | dest=42 | keep2 | RF | magic | handler | magic | recursive args |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   287
  // Check various invariants.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   288
  verify_offsets();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   289
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   290
  Register rdi_temp = rdi;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   291
  Register rcx_temp = rcx;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   292
  { __ push(rdi_temp); __ push(rcx_temp); }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   293
#define UNPUSH_TEMPS \
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   294
  { __ pop(rcx_temp);  __ pop(rdi_temp); }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   295
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   296
  Address magic_number_1_addr  = RicochetFrame::frame_address(RicochetFrame::magic_number_1_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   297
  Address magic_number_2_addr  = RicochetFrame::frame_address(RicochetFrame::magic_number_2_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   298
  Address continuation_addr    = RicochetFrame::frame_address(RicochetFrame::continuation_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   299
  Address conversion_addr      = RicochetFrame::frame_address(RicochetFrame::conversion_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   300
  Address saved_args_base_addr = RicochetFrame::frame_address(RicochetFrame::saved_args_base_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   301
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   302
  Label L_bad, L_ok;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   303
  BLOCK_COMMENT("verify_clean {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   304
  // Magic numbers must check out:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   305
  __ cmpptr(magic_number_1_addr, (int32_t) MAGIC_NUMBER_1);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   306
  __ jcc(Assembler::notEqual, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   307
  __ cmpptr(magic_number_2_addr, (int32_t) MAGIC_NUMBER_2);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   308
  __ jcc(Assembler::notEqual, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   309
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   310
  // Arguments pointer must look reasonable:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   311
  __ movptr(rcx_temp, saved_args_base_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   312
  __ cmpptr(rcx_temp, rbp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   313
  __ jcc(Assembler::below, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   314
  __ subptr(rcx_temp, UNREASONABLE_STACK_MOVE * Interpreter::stackElementSize);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   315
  __ cmpptr(rcx_temp, rbp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   316
  __ jcc(Assembler::above, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   317
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   318
  load_conversion_dest_type(_masm, rdi_temp, conversion_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   319
  __ cmpl(rdi_temp, T_VOID);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   320
  __ jcc(Assembler::equal, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   321
  __ movptr(rcx_temp, saved_args_base_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   322
  load_conversion_vminfo(_masm, rdi_temp, conversion_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   323
  __ cmpptr(Address(rcx_temp, rdi_temp, Interpreter::stackElementScale()),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   324
            (int32_t) RETURN_VALUE_PLACEHOLDER);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   325
  __ jcc(Assembler::equal, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   326
  __ BIND(L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   327
  UNPUSH_TEMPS;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   328
  __ stop("damaged ricochet frame");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   329
  __ BIND(L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   330
  UNPUSH_TEMPS;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   331
  BLOCK_COMMENT("} verify_clean");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   332
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   333
#undef UNPUSH_TEMPS
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   334
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   335
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   336
#endif //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   337
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   338
void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   339
  if (VerifyMethodHandles)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   340
    verify_klass(_masm, klass_reg, SystemDictionaryHandles::Class_klass(),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   341
                 "AMH argument is a Class");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   342
  __ load_heap_oop(klass_reg, Address(klass_reg, java_lang_Class::klass_offset_in_bytes()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   343
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   344
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   345
void MethodHandles::load_conversion_vminfo(MacroAssembler* _masm, Register reg, Address conversion_field_addr) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   346
  int bits   = BitsPerByte;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   347
  int offset = (CONV_VMINFO_SHIFT / bits);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   348
  int shift  = (CONV_VMINFO_SHIFT % bits);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   349
  __ load_unsigned_byte(reg, conversion_field_addr.plus_disp(offset));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   350
  assert(CONV_VMINFO_MASK == right_n_bits(bits - shift), "else change type of previous load");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   351
  assert(shift == 0, "no shift needed");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   352
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   353
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   354
void MethodHandles::load_conversion_dest_type(MacroAssembler* _masm, Register reg, Address conversion_field_addr) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   355
  int bits   = BitsPerByte;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   356
  int offset = (CONV_DEST_TYPE_SHIFT / bits);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   357
  int shift  = (CONV_DEST_TYPE_SHIFT % bits);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   358
  __ load_unsigned_byte(reg, conversion_field_addr.plus_disp(offset));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   359
  assert(CONV_TYPE_MASK == right_n_bits(bits - shift), "else change type of previous load");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   360
  __ shrl(reg, shift);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   361
  DEBUG_ONLY(int conv_type_bits = (int) exact_log2(CONV_TYPE_MASK+1));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   362
  assert((shift + conv_type_bits) == bits, "left justified in byte");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   363
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   364
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   365
void MethodHandles::load_stack_move(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   366
                                    Register rdi_stack_move,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   367
                                    Register rcx_amh,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   368
                                    bool might_be_negative) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   369
  BLOCK_COMMENT("load_stack_move");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   370
  Address rcx_amh_conversion(rcx_amh, java_lang_invoke_AdapterMethodHandle::conversion_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   371
  __ movl(rdi_stack_move, rcx_amh_conversion);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   372
  __ sarl(rdi_stack_move, CONV_STACK_MOVE_SHIFT);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   373
#ifdef _LP64
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   374
  if (might_be_negative) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   375
    // clean high bits of stack motion register (was loaded as an int)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   376
    __ movslq(rdi_stack_move, rdi_stack_move);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   377
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   378
#endif //_LP64
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   379
  if (VerifyMethodHandles) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   380
    Label L_ok, L_bad;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   381
    int32_t stack_move_limit = 0x4000;  // extra-large
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   382
    __ cmpptr(rdi_stack_move, stack_move_limit);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   383
    __ jcc(Assembler::greaterEqual, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   384
    __ cmpptr(rdi_stack_move, -stack_move_limit);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   385
    __ jcc(Assembler::greater, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   386
    __ bind(L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   387
    __ stop("load_stack_move of garbage value");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   388
    __ BIND(L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   389
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   390
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   391
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   392
#ifndef PRODUCT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   393
void MethodHandles::RicochetFrame::verify_offsets() {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   394
  // Check compatibility of this struct with the more generally used offsets of class frame:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   395
  int ebp_off = sender_link_offset_in_bytes();  // offset from struct base to local rbp value
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   396
  assert(ebp_off + wordSize*frame::interpreter_frame_method_offset      == saved_args_base_offset_in_bytes(), "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   397
  assert(ebp_off + wordSize*frame::interpreter_frame_last_sp_offset     == conversion_offset_in_bytes(), "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   398
  assert(ebp_off + wordSize*frame::interpreter_frame_sender_sp_offset   == exact_sender_sp_offset_in_bytes(), "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   399
  // These last two have to be exact:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   400
  assert(ebp_off + wordSize*frame::link_offset                          == sender_link_offset_in_bytes(), "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   401
  assert(ebp_off + wordSize*frame::return_addr_offset                   == sender_pc_offset_in_bytes(), "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   402
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   403
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   404
void MethodHandles::RicochetFrame::verify() const {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   405
  verify_offsets();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   406
  assert(magic_number_1() == MAGIC_NUMBER_1, "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   407
  assert(magic_number_2() == MAGIC_NUMBER_2, "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   408
  if (!Universe::heap()->is_gc_active()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   409
    if (saved_args_layout() != NULL) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   410
      assert(saved_args_layout()->is_method(), "must be valid oop");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   411
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   412
    if (saved_target() != NULL) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   413
      assert(java_lang_invoke_MethodHandle::is_instance(saved_target()), "checking frame value");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   414
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   415
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   416
  int conv_op = adapter_conversion_op(conversion());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   417
  assert(conv_op == java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS ||
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   418
         conv_op == java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS ||
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   419
         conv_op == java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   420
         "must be a sane conversion");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   421
  if (has_return_value_slot()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   422
    assert(*return_value_slot_addr() == RETURN_VALUE_PLACEHOLDER, "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   423
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   424
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   425
#endif //PRODUCT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   426
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   427
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   428
void MethodHandles::verify_argslot(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   429
                                   Register argslot_reg,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   430
                                   const char* error_message) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   431
  // Verify that argslot lies within (rsp, rbp].
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   432
  Label L_ok, L_bad;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   433
  BLOCK_COMMENT("verify_argslot {");
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   434
  __ cmpptr(argslot_reg, rbp);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   435
  __ jccb(Assembler::above, L_bad);
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
   436
  __ cmpptr(rsp, argslot_reg);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
   437
  __ jccb(Assembler::below, L_ok);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   438
  __ bind(L_bad);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   439
  __ stop(error_message);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   440
  __ BIND(L_ok);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   441
  BLOCK_COMMENT("} verify_argslot");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   442
}
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   443
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   444
void MethodHandles::verify_argslots(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   445
                                    RegisterOrConstant arg_slots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   446
                                    Register arg_slot_base_reg,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   447
                                    bool negate_argslots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   448
                                    const char* error_message) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   449
  // Verify that [argslot..argslot+size) lies within (rsp, rbp).
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   450
  Label L_ok, L_bad;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   451
  Register rdi_temp = rdi;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   452
  BLOCK_COMMENT("verify_argslots {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   453
  __ push(rdi_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   454
  if (negate_argslots) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   455
    if (arg_slots.is_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   456
      arg_slots = -1 * arg_slots.as_constant();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   457
    } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   458
      __ movptr(rdi_temp, arg_slots);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   459
      __ negptr(rdi_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   460
      arg_slots = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   461
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   462
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   463
  __ lea(rdi_temp, Address(arg_slot_base_reg, arg_slots, Interpreter::stackElementScale()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   464
  __ cmpptr(rdi_temp, rbp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   465
  __ pop(rdi_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   466
  __ jcc(Assembler::above, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   467
  __ cmpptr(rsp, arg_slot_base_reg);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   468
  __ jcc(Assembler::below, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   469
  __ bind(L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   470
  __ stop(error_message);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   471
  __ BIND(L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   472
  BLOCK_COMMENT("} verify_argslots");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   473
}
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   474
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   475
// Make sure that arg_slots has the same sign as the given direction.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   476
// If (and only if) arg_slots is a assembly-time constant, also allow it to be zero.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   477
void MethodHandles::verify_stack_move(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   478
                                      RegisterOrConstant arg_slots, int direction) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   479
  bool allow_zero = arg_slots.is_constant();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   480
  if (direction == 0) { direction = +1; allow_zero = true; }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   481
  assert(stack_move_unit() == -1, "else add extra checks here");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   482
  if (arg_slots.is_register()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   483
    Label L_ok, L_bad;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   484
    BLOCK_COMMENT("verify_stack_move {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   485
    // testl(arg_slots.as_register(), -stack_move_unit() - 1);  // no need
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   486
    // jcc(Assembler::notZero, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   487
    __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   488
    if (direction > 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   489
      __ jcc(allow_zero ? Assembler::less : Assembler::lessEqual, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   490
      __ cmpptr(arg_slots.as_register(), (int32_t) UNREASONABLE_STACK_MOVE);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   491
      __ jcc(Assembler::less, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   492
    } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   493
      __ jcc(allow_zero ? Assembler::greater : Assembler::greaterEqual, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   494
      __ cmpptr(arg_slots.as_register(), (int32_t) -UNREASONABLE_STACK_MOVE);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   495
      __ jcc(Assembler::greater, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   496
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   497
    __ bind(L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   498
    if (direction > 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   499
      __ stop("assert arg_slots > 0");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   500
    else
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   501
      __ stop("assert arg_slots < 0");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   502
    __ BIND(L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   503
    BLOCK_COMMENT("} verify_stack_move");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   504
  } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   505
    intptr_t size = arg_slots.as_constant();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   506
    if (direction < 0)  size = -size;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   507
    assert(size >= 0, "correct direction of constant move");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   508
    assert(size < UNREASONABLE_STACK_MOVE, "reasonable size of constant move");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   509
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   510
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   511
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   512
void MethodHandles::verify_klass(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   513
                                 Register obj, KlassHandle klass,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   514
                                 const char* error_message) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   515
  oop* klass_addr = klass.raw_value();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   516
  assert(klass_addr >= SystemDictionaryHandles::Object_klass().raw_value() &&
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   517
         klass_addr <= SystemDictionaryHandles::Long_klass().raw_value(),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   518
         "must be one of the SystemDictionaryHandles");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   519
  Register temp = rdi;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   520
  Label L_ok, L_bad;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   521
  BLOCK_COMMENT("verify_klass {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   522
  __ verify_oop(obj);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   523
  __ testptr(obj, obj);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   524
  __ jcc(Assembler::zero, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   525
  __ push(temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   526
  __ load_klass(temp, obj);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   527
  __ cmpptr(temp, ExternalAddress((address) klass_addr));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   528
  __ jcc(Assembler::equal, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   529
  intptr_t super_check_offset = klass->super_check_offset();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   530
  __ movptr(temp, Address(temp, super_check_offset));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   531
  __ cmpptr(temp, ExternalAddress((address) klass_addr));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   532
  __ jcc(Assembler::equal, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   533
  __ pop(temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   534
  __ bind(L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   535
  __ stop(error_message);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   536
  __ BIND(L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   537
  __ pop(temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   538
  BLOCK_COMMENT("} verify_klass");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   539
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   540
#endif //ASSERT
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   541
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   542
// Code generation
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   543
address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   544
  // rbx: methodOop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   545
  // rcx: receiver method handle (must load from sp[MethodTypeForm.vmslots])
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   546
  // 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
   547
  // rdx, rdi: garbage temp, blown away
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   548
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   549
  Register rbx_method = rbx;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   550
  Register rcx_recv   = rcx;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   551
  Register rax_mtype  = rax;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   552
  Register rdx_temp   = rdx;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   553
  Register rdi_temp   = rdi;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   554
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   555
  // emit WrongMethodType path first, to enable jccb back-branch from main path
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   556
  Label wrong_method_type;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   557
  __ bind(wrong_method_type);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   558
  Label invoke_generic_slow_path;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   559
  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
   560
  __ 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
   561
  __ jcc(Assembler::notEqual, invoke_generic_slow_path);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   562
  __ push(rax_mtype);       // required mtype
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   563
  __ push(rcx_recv);        // bad mh (1st stacked argument)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   564
  __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   565
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   566
  // here's where control starts out:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   567
  __ align(CodeEntryAlignment);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   568
  address entry_point = __ pc();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   569
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   570
  // fetch the MethodType from the method handle into rax (the 'check' register)
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   571
  // FIXME: Interpreter should transmit pre-popped stack pointer, to locate base of arg list.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   572
  // This would simplify several touchy bits of code.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   573
  // See 6984712: JSR 292 method handle calls need a clean argument base pointer
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   574
  {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   575
    Register tem = rbx_method;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   576
    for (jint* pchase = methodOopDesc::method_type_offsets_chain(); (*pchase) != -1; pchase++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   577
      __ movptr(rax_mtype, Address(tem, *pchase));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   578
      tem = rax_mtype;          // in case there is another indirection
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   579
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   580
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   581
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   582
  // given the MethodType, find out where the MH argument is buried
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
   583
  __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_lang_invoke_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
   584
  Register rdx_vmslots = rdx_temp;
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
   585
  __ movl(rdx_vmslots, Address(rdx_temp, __ delayed_value(java_lang_invoke_MethodTypeForm::vmslots_offset_in_bytes, rdi_temp)));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   586
  Address mh_receiver_slot_addr = __ argument_address(rdx_vmslots);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   587
  __ movptr(rcx_recv, mh_receiver_slot_addr);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   588
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   589
  trace_method_handle(_masm, "invokeExact");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   590
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   591
  __ check_method_handle_type(rax_mtype, rcx_recv, rdi_temp, wrong_method_type);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   592
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   593
  // Nobody uses the MH receiver slot after this.  Make sure.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   594
  DEBUG_ONLY(__ movptr(mh_receiver_slot_addr, (int32_t)0x999999));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   595
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   596
  __ 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
   597
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   598
  // 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
   599
  __ bind(invoke_generic_slow_path);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   600
#ifdef ASSERT
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   601
  if (VerifyMethodHandles) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   602
    Label L;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   603
    __ 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
   604
    __ jcc(Assembler::equal, L);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   605
    __ stop("bad methodOop::intrinsic_id");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   606
    __ bind(L);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   607
  }
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   608
#endif //ASSERT
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   609
  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
   610
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   611
  // 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
   612
  Register rcx_argslot = rcx_recv;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   613
  __ lea(rcx_argslot, __ argument_address(rdx_vmslots, 1));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   614
  insert_arg_slots(_masm, 2 * stack_move_unit(),
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   615
                   rcx_argslot, rbx_temp, rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   616
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   617
  // load up an adapter from the calling type (Java weaves this)
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
   618
  __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_lang_invoke_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
   619
  Register rdx_adapter = rdx_temp;
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
   620
  // __ load_heap_oop(rdx_adapter, Address(rdx_temp, java_lang_invoke_MethodTypeForm::genericInvoker_offset_in_bytes()));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   621
  // deal with old JDK versions:
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
   622
  __ lea(rdi_temp, Address(rdx_temp, __ delayed_value(java_lang_invoke_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
   623
  __ cmpptr(rdi_temp, rdx_temp);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   624
  Label sorry_no_invoke_generic;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   625
  __ 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
   626
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   627
  __ 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
   628
  __ testptr(rdx_adapter, rdx_adapter);
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
   629
  __ 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
   630
  __ 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
   631
  // 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
   632
  // 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
   633
  // (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
   634
  __ 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
   635
  // 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
   636
  __ mov(rcx, rdx_adapter);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   637
  trace_method_handle(_masm, "invokeGeneric");
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   638
  __ 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
   639
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   640
  __ 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
   641
  __ 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
   642
  __ push(rax_mtype);       // required mtype
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   643
  __ 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
   644
  __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   645
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   646
  return entry_point;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   647
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   648
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   649
// Workaround for C++ overloading nastiness on '0' for RegisterOrConstant.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   650
static RegisterOrConstant constant(int value) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   651
  return RegisterOrConstant(value);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   652
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   653
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   654
// Helper to insert argument slots into the stack.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   655
// arg_slots must be a multiple of stack_move_unit() and < 0
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   656
// rax_argslot is decremented to point to the new (shifted) location of the argslot
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   657
// But, rdx_temp ends up holding the original value of rax_argslot.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   658
void MethodHandles::insert_arg_slots(MacroAssembler* _masm,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   659
                                     RegisterOrConstant arg_slots,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   660
                                     Register rax_argslot,
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   661
                                     Register rbx_temp, Register rdx_temp) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   662
  // allow constant zero
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   663
  if (arg_slots.is_constant() && arg_slots.as_constant() == 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   664
    return;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   665
  assert_different_registers(rax_argslot, rbx_temp, rdx_temp,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   666
                             (!arg_slots.is_register() ? rsp : arg_slots.as_register()));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   667
  if (VerifyMethodHandles)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   668
    verify_argslot(_masm, rax_argslot, "insertion point must fall within current frame");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   669
  if (VerifyMethodHandles)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   670
    verify_stack_move(_masm, arg_slots, -1);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   671
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   672
  // Make space on the stack for the inserted argument(s).
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   673
  // Then pull down everything shallower than rax_argslot.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   674
  // The stacked return address gets pulled down with everything else.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   675
  // That is, copy [rsp, argslot) downward by -size words.  In pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   676
  //   rsp -= size;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   677
  //   for (rdx = rsp + size; rdx < argslot; rdx++)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   678
  //     rdx[-size] = rdx[0]
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   679
  //   argslot -= size;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   680
  BLOCK_COMMENT("insert_arg_slots {");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   681
  __ mov(rdx_temp, rsp);                        // source pointer for copy
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   682
  __ lea(rsp, Address(rsp, arg_slots, Interpreter::stackElementScale()));
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
    Label loop;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   685
    __ BIND(loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   686
    // pull one word down each time through the loop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   687
    __ movptr(rbx_temp, Address(rdx_temp, 0));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   688
    __ movptr(Address(rdx_temp, arg_slots, Interpreter::stackElementScale()), rbx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   689
    __ addptr(rdx_temp, wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   690
    __ cmpptr(rdx_temp, rax_argslot);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   691
    __ jcc(Assembler::less, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   692
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   693
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   694
  // Now move the argslot down, to point to the opened-up space.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   695
  __ lea(rax_argslot, Address(rax_argslot, arg_slots, Interpreter::stackElementScale()));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   696
  BLOCK_COMMENT("} insert_arg_slots");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   697
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   698
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   699
// Helper to remove argument slots from the stack.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   700
// arg_slots must be a multiple of stack_move_unit() and > 0
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   701
void MethodHandles::remove_arg_slots(MacroAssembler* _masm,
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   702
                                     RegisterOrConstant arg_slots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   703
                                     Register rax_argslot,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   704
                                     Register rbx_temp, Register rdx_temp) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   705
  // allow constant zero
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   706
  if (arg_slots.is_constant() && arg_slots.as_constant() == 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   707
    return;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   708
  assert_different_registers(rax_argslot, rbx_temp, rdx_temp,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   709
                             (!arg_slots.is_register() ? rsp : arg_slots.as_register()));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   710
  if (VerifyMethodHandles)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   711
    verify_argslots(_masm, arg_slots, rax_argslot, false,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   712
                    "deleted argument(s) must fall within current frame");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   713
  if (VerifyMethodHandles)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   714
    verify_stack_move(_masm, arg_slots, +1);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   715
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   716
  BLOCK_COMMENT("remove_arg_slots {");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   717
  // Pull up everything shallower than rax_argslot.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   718
  // Then remove the excess space on the stack.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   719
  // The stacked return address gets pulled up with everything else.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   720
  // That is, copy [rsp, argslot) upward by size words.  In pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   721
  //   for (rdx = argslot-1; rdx >= rsp; --rdx)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   722
  //     rdx[size] = rdx[0]
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   723
  //   argslot += size;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   724
  //   rsp += size;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   725
  __ lea(rdx_temp, Address(rax_argslot, -wordSize)); // source pointer for copy
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   726
  {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   727
    Label loop;
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   728
    __ BIND(loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   729
    // pull one word up each time through the loop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   730
    __ movptr(rbx_temp, Address(rdx_temp, 0));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   731
    __ movptr(Address(rdx_temp, arg_slots, Interpreter::stackElementScale()), rbx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   732
    __ addptr(rdx_temp, -wordSize);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   733
    __ cmpptr(rdx_temp, rsp);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   734
    __ jcc(Assembler::greaterEqual, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   735
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   736
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   737
  // Now move the argslot up, to point to the just-copied block.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   738
  __ lea(rsp, Address(rsp, arg_slots, Interpreter::stackElementScale()));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   739
  // And adjust the argslot address to point at the deletion point.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   740
  __ lea(rax_argslot, Address(rax_argslot, arg_slots, Interpreter::stackElementScale()));
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   741
  BLOCK_COMMENT("} remove_arg_slots");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   742
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   743
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   744
// Helper to copy argument slots to the top of the stack.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   745
// The sequence starts with rax_argslot and is counted by slot_count
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   746
// slot_count must be a multiple of stack_move_unit() and >= 0
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   747
// This function blows the temps but does not change rax_argslot.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   748
void MethodHandles::push_arg_slots(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   749
                                   Register rax_argslot,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   750
                                   RegisterOrConstant slot_count,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   751
                                   int skip_words_count,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   752
                                   Register rbx_temp, Register rdx_temp) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   753
  assert_different_registers(rax_argslot, rbx_temp, rdx_temp,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   754
                             (!slot_count.is_register() ? rbp : slot_count.as_register()),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   755
                             rsp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   756
  assert(Interpreter::stackElementSize == wordSize, "else change this code");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   757
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   758
  if (VerifyMethodHandles)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   759
    verify_stack_move(_masm, slot_count, 0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   760
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   761
  // allow constant zero
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   762
  if (slot_count.is_constant() && slot_count.as_constant() == 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   763
    return;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   764
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   765
  BLOCK_COMMENT("push_arg_slots {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   766
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   767
  Register rbx_top = rbx_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   768
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   769
  // There is at most 1 word to carry down with the TOS.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   770
  switch (skip_words_count) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   771
  case 1: __ pop(rdx_temp); break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   772
  case 0:                   break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   773
  default: ShouldNotReachHere();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   774
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   775
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   776
  if (slot_count.is_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   777
    for (int i = slot_count.as_constant() - 1; i >= 0; i--) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   778
      __ pushptr(Address(rax_argslot, i * wordSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   779
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   780
  } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   781
    Label L_plural, L_loop, L_break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   782
    // Emit code to dynamically check for the common cases, zero and one slot.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   783
    __ cmpl(slot_count.as_register(), (int32_t) 1);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   784
    __ jccb(Assembler::greater, L_plural);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   785
    __ jccb(Assembler::less, L_break);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   786
    __ pushptr(Address(rax_argslot, 0));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   787
    __ jmpb(L_break);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   788
    __ BIND(L_plural);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   789
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   790
    // Loop for 2 or more:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   791
    //   rbx = &rax[slot_count]
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   792
    //   while (rbx > rax)  *(--rsp) = *(--rbx)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   793
    __ lea(rbx_top, Address(rax_argslot, slot_count, Address::times_ptr));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   794
    __ BIND(L_loop);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   795
    __ subptr(rbx_top, wordSize);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   796
    __ pushptr(Address(rbx_top, 0));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   797
    __ cmpptr(rbx_top, rax_argslot);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   798
    __ jcc(Assembler::above, L_loop);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   799
    __ bind(L_break);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   800
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   801
  switch (skip_words_count) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   802
  case 1: __ push(rdx_temp); break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   803
  case 0:                    break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   804
  default: ShouldNotReachHere();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   805
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   806
  BLOCK_COMMENT("} push_arg_slots");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   807
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   808
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   809
// in-place movement; no change to rsp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   810
// blows rax_temp, rdx_temp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   811
void MethodHandles::move_arg_slots_up(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   812
                                      Register rbx_bottom,  // invariant
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   813
                                      Address  top_addr,     // can use rax_temp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   814
                                      RegisterOrConstant positive_distance_in_slots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   815
                                      Register rax_temp, Register rdx_temp) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   816
  BLOCK_COMMENT("move_arg_slots_up {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   817
  assert_different_registers(rbx_bottom,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   818
                             rax_temp, rdx_temp,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   819
                             positive_distance_in_slots.register_or_noreg());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   820
  Label L_loop, L_break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   821
  Register rax_top = rax_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   822
  if (!top_addr.is_same_address(Address(rax_top, 0)))
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   823
    __ lea(rax_top, top_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   824
  // Detect empty (or broken) loop:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   825
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   826
  if (VerifyMethodHandles) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   827
    // Verify that &bottom < &top (non-empty interval)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   828
    Label L_ok, L_bad;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   829
    if (positive_distance_in_slots.is_register()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   830
      __ cmpptr(positive_distance_in_slots.as_register(), (int32_t) 0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   831
      __ jcc(Assembler::lessEqual, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   832
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   833
    __ cmpptr(rbx_bottom, rax_top);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   834
    __ jcc(Assembler::below, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   835
    __ bind(L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   836
    __ stop("valid bounds (copy up)");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   837
    __ BIND(L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   838
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   839
#endif
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   840
  __ cmpptr(rbx_bottom, rax_top);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   841
  __ jccb(Assembler::aboveEqual, L_break);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   842
  // work rax down to rbx, copying contiguous data upwards
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   843
  // In pseudo-code:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   844
  //   [rbx, rax) = &[bottom, top)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   845
  //   while (--rax >= rbx) *(rax + distance) = *(rax + 0), rax--;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   846
  __ BIND(L_loop);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   847
  __ subptr(rax_top, wordSize);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   848
  __ movptr(rdx_temp, Address(rax_top, 0));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   849
  __ movptr(          Address(rax_top, positive_distance_in_slots, Address::times_ptr), rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   850
  __ cmpptr(rax_top, rbx_bottom);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   851
  __ jcc(Assembler::above, L_loop);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   852
  assert(Interpreter::stackElementSize == wordSize, "else change loop");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   853
  __ bind(L_break);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   854
  BLOCK_COMMENT("} move_arg_slots_up");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   855
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   856
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   857
// in-place movement; no change to rsp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   858
// blows rax_temp, rdx_temp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   859
void MethodHandles::move_arg_slots_down(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   860
                                        Address  bottom_addr,  // can use rax_temp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   861
                                        Register rbx_top,      // invariant
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   862
                                        RegisterOrConstant negative_distance_in_slots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   863
                                        Register rax_temp, Register rdx_temp) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   864
  BLOCK_COMMENT("move_arg_slots_down {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   865
  assert_different_registers(rbx_top,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   866
                             negative_distance_in_slots.register_or_noreg(),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   867
                             rax_temp, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   868
  Label L_loop, L_break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   869
  Register rax_bottom = rax_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   870
  if (!bottom_addr.is_same_address(Address(rax_bottom, 0)))
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   871
    __ lea(rax_bottom, bottom_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   872
  // Detect empty (or broken) loop:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   873
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   874
  assert(!negative_distance_in_slots.is_constant() || negative_distance_in_slots.as_constant() < 0, "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   875
  if (VerifyMethodHandles) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   876
    // Verify that &bottom < &top (non-empty interval)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   877
    Label L_ok, L_bad;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   878
    if (negative_distance_in_slots.is_register()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   879
      __ cmpptr(negative_distance_in_slots.as_register(), (int32_t) 0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   880
      __ jcc(Assembler::greaterEqual, L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   881
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   882
    __ cmpptr(rax_bottom, rbx_top);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   883
    __ jcc(Assembler::below, L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   884
    __ bind(L_bad);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   885
    __ stop("valid bounds (copy down)");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   886
    __ BIND(L_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   887
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   888
#endif
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   889
  __ cmpptr(rax_bottom, rbx_top);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   890
  __ jccb(Assembler::aboveEqual, L_break);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   891
  // work rax up to rbx, copying contiguous data downwards
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   892
  // In pseudo-code:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   893
  //   [rax, rbx) = &[bottom, top)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   894
  //   while (rax < rbx) *(rax - distance) = *(rax + 0), rax++;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   895
  __ BIND(L_loop);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   896
  __ movptr(rdx_temp, Address(rax_bottom, 0));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   897
  __ movptr(          Address(rax_bottom, negative_distance_in_slots, Address::times_ptr), rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   898
  __ addptr(rax_bottom, wordSize);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   899
  __ cmpptr(rax_bottom, rbx_top);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   900
  __ jcc(Assembler::below, L_loop);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   901
  assert(Interpreter::stackElementSize == wordSize, "else change loop");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   902
  __ bind(L_break);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   903
  BLOCK_COMMENT("} move_arg_slots_down");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   904
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   905
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   906
// Copy from a field or array element to a stacked argument slot.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   907
// is_element (ignored) says whether caller is loading an array element instead of an instance field.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   908
void MethodHandles::move_typed_arg(MacroAssembler* _masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   909
                                   BasicType type, bool is_element,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   910
                                   Address slot_dest, Address value_src,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   911
                                   Register rbx_temp, Register rdx_temp) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   912
  BLOCK_COMMENT(!is_element ? "move_typed_arg {" : "move_typed_arg { (array element)");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   913
  if (type == T_OBJECT || type == T_ARRAY) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   914
    __ load_heap_oop(rbx_temp, value_src);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   915
    __ movptr(slot_dest, rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   916
  } else if (type != T_VOID) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   917
    int  arg_size      = type2aelembytes(type);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   918
    bool arg_is_signed = is_signed_subword_type(type);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   919
    int  slot_size     = (arg_size > wordSize) ? arg_size : wordSize;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   920
    __ load_sized_value(  rdx_temp,  value_src, arg_size, arg_is_signed, rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   921
    __ store_sized_value( slot_dest, rdx_temp,  slot_size,               rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   922
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   923
  BLOCK_COMMENT("} move_typed_arg");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   924
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   925
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   926
void MethodHandles::move_return_value(MacroAssembler* _masm, BasicType type,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   927
                                      Address return_slot) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   928
  BLOCK_COMMENT("move_return_value {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   929
  // Old versions of the JVM must clean the FPU stack after every return.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   930
#ifndef _LP64
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   931
#ifdef COMPILER2
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   932
  // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   933
  if ((type == T_FLOAT && UseSSE < 1) || (type == T_DOUBLE && UseSSE < 2)) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   934
    for (int i = 1; i < 8; i++) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   935
        __ ffree(i);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   936
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   937
  } else if (UseSSE < 2) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   938
    __ empty_FPU_stack();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   939
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   940
#endif //COMPILER2
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   941
#endif //!_LP64
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   942
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   943
  // Look at the type and pull the value out of the corresponding register.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   944
  if (type == T_VOID) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   945
    // nothing to do
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   946
  } else if (type == T_OBJECT) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   947
    __ movptr(return_slot, rax);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   948
  } else if (type == T_INT || is_subword_type(type)) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   949
    // write the whole word, even if only 32 bits is significant
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   950
    __ movptr(return_slot, rax);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   951
  } else if (type == T_LONG) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   952
    // store the value by parts
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   953
    // Note: We assume longs are continguous (if misaligned) on the interpreter stack.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   954
    __ store_sized_value(return_slot, rax, BytesPerLong, rdx);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   955
  } else if (NOT_LP64((type == T_FLOAT  && UseSSE < 1) ||
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   956
                      (type == T_DOUBLE && UseSSE < 2) ||)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   957
             false) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   958
    // Use old x86 FPU registers:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   959
    if (type == T_FLOAT)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   960
      __ fstp_s(return_slot);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   961
    else
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   962
      __ fstp_d(return_slot);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   963
  } else if (type == T_FLOAT) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   964
    __ movflt(return_slot, xmm0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   965
  } else if (type == T_DOUBLE) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   966
    __ movdbl(return_slot, xmm0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   967
  } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   968
    ShouldNotReachHere();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   969
  }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   970
  BLOCK_COMMENT("} move_return_value");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   971
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   972
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   973
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   974
#ifndef PRODUCT
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents: 4478
diff changeset
   975
extern "C" void print_method_handle(oop mh);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   976
void trace_method_handle_stub(const char* adaptername,
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   977
                              oop mh,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   978
                              intptr_t* saved_regs,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   979
                              intptr_t* entry_sp,
9437
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 8676
diff changeset
   980
                              intptr_t* saved_sp,
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   981
                              intptr_t* saved_bp) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   982
  // called as a leaf from native code: do not block the JVM!
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   983
  intptr_t* last_sp = (intptr_t*) saved_bp[frame::interpreter_frame_last_sp_offset];
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   984
  intptr_t* base_sp = (intptr_t*) saved_bp[frame::interpreter_frame_monitor_block_top_offset];
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   985
  tty->print_cr("MH %s mh="INTPTR_FORMAT" sp=("INTPTR_FORMAT"+"INTX_FORMAT") stack_size="INTX_FORMAT" bp="INTPTR_FORMAT,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   986
                adaptername, (intptr_t)mh, (intptr_t)entry_sp, (intptr_t)(saved_sp - entry_sp), (intptr_t)(base_sp - last_sp), (intptr_t)saved_bp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   987
  if (last_sp != saved_sp && last_sp != NULL)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   988
    tty->print_cr("*** last_sp="INTPTR_FORMAT, (intptr_t)last_sp);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
   989
  if (Verbose) {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   990
    tty->print(" reg dump: ");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   991
    int saved_regs_count = (entry_sp-1) - saved_regs;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   992
    // 32 bit: rdi rsi rbp rsp; rbx rdx rcx (*) rax
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   993
    int i;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   994
    for (i = 0; i <= saved_regs_count; i++) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   995
      if (i > 0 && i % 4 == 0 && i != saved_regs_count) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   996
        tty->cr();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   997
        tty->print("   + dump: ");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   998
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
   999
      tty->print(" %d: "INTPTR_FORMAT, i, saved_regs[i]);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1000
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1001
    tty->cr();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1002
    int stack_dump_count = 16;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1003
    if (stack_dump_count < (int)(saved_bp + 2 - saved_sp))
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1004
      stack_dump_count = (int)(saved_bp + 2 - saved_sp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1005
    if (stack_dump_count > 64)  stack_dump_count = 48;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1006
    for (i = 0; i < stack_dump_count; i += 4) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1007
      tty->print_cr(" dump at SP[%d] "INTPTR_FORMAT": "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1008
                    i, (intptr_t) &entry_sp[i+0], entry_sp[i+0], entry_sp[i+1], entry_sp[i+2], entry_sp[i+3]);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1009
    }
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1010
    print_method_handle(mh);
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1011
  }
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1012
}
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1013
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1014
// The stub wraps the arguments in a struct on the stack to avoid
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1015
// dealing with the different calling conventions for passing 6
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1016
// arguments.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1017
struct MethodHandleStubArguments {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1018
  const char* adaptername;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1019
  oopDesc* mh;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1020
  intptr_t* saved_regs;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1021
  intptr_t* entry_sp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1022
  intptr_t* saved_sp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1023
  intptr_t* saved_bp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1024
};
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1025
void trace_method_handle_stub_wrapper(MethodHandleStubArguments* args) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1026
  trace_method_handle_stub(args->adaptername,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1027
                           args->mh,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1028
                           args->saved_regs,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1029
                           args->entry_sp,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1030
                           args->saved_sp,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1031
                           args->saved_bp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1032
}
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1033
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1034
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
  1035
  if (!TraceMethodHandles)  return;
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1036
  BLOCK_COMMENT("trace_method_handle {");
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1037
  __ push(rax);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1038
  __ lea(rax, Address(rsp, wordSize * NOT_LP64(6) LP64_ONLY(14))); // entry_sp  __ pusha();
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1039
  __ pusha();
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1040
  __ mov(rbx, rsp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1041
  __ enter();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1042
  // incoming state:
9437
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 8676
diff changeset
  1043
  // rcx: method handle
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1044
  // r13 or rsi: saved sp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1045
  // To avoid calling convention issues, build a record on the stack and pass the pointer to that instead.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1046
  __ push(rbp);               // saved_bp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1047
  __ push(rsi);               // saved_sp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1048
  __ push(rax);               // entry_sp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1049
  __ push(rbx);               // pusha saved_regs
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1050
  __ push(rcx);               // mh
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1051
  __ push(rcx);               // adaptername
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1052
  __ movptr(Address(rsp, 0), (intptr_t) adaptername);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1053
  __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub_wrapper), rsp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1054
  __ leave();
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1055
  __ popa();
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1056
  __ pop(rax);
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1057
  BLOCK_COMMENT("} trace_method_handle");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1058
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1059
#endif //PRODUCT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1060
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
  1061
// which conversion op types are implemented here?
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
  1062
int MethodHandles::adapter_conversion_ops_supported_mask() {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1063
  return ((1<<java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY)
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1064
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW)
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1065
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST)
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1066
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM)
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1067
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM)
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1068
          //OP_PRIM_TO_REF is below...
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1069
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS)
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1070
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS)
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1071
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS)
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1072
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS)
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1073
          //OP_COLLECT_ARGS is below...
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1074
         |(1<<java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1075
         |(!UseRicochetFrames ? 0 :
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1076
           LP64_ONLY(FLAG_IS_DEFAULT(UseRicochetFrames) ? 0 :)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1077
           java_lang_invoke_MethodTypeForm::vmlayout_offset_in_bytes() <= 0 ? 0 :
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1078
           ((1<<java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1079
           |(1<<java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1080
           |(1<<java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1081
            ))
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
  1082
         );
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
  1083
}
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5419
diff changeset
  1084
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1085
//------------------------------------------------------------------------------
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1086
// MethodHandles::generate_method_handle_stub
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1087
//
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1088
// Generate an "entry" field for a method handle.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1089
// This determines how the method handle will respond to calls.
7887
7aa0354cbf25 7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents: 7712
diff changeset
  1090
void MethodHandles::generate_method_handle_stub(MacroAssembler* _masm, MethodHandles::EntryKind ek) {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1091
  MethodHandles::EntryKind ek_orig = ek_original_kind(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1092
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1093
  // Here is the register state during an interpreted call,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1094
  // as set up by generate_method_handle_interpreter_entry():
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1095
  // - rbx: garbage temp (was MethodHandle.invoke methodOop, unused)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1096
  // - rcx: receiver method handle
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1097
  // - rax: method handle type (only used by the check_mtype entry point)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1098
  // - rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1099
  // - rdx: garbage temp, can blow away
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1100
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1101
  const Register rcx_recv    = rcx;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1102
  const Register rax_argslot = rax;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1103
  const Register rbx_temp    = rbx;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1104
  const Register rdx_temp    = rdx;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1105
  const Register rdi_temp    = rdi;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1106
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1107
  // 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
  1108
  // and gen_c2i_adapter (from compiled calls):
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1109
  const Register saved_last_sp = saved_last_sp_register();
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1110
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1111
  // Argument registers for _raise_exception.
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1112
  // 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
  1113
  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
  1114
  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
  1115
  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
  1116
  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
  1117
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1118
  guarantee(java_lang_invoke_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1119
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1120
  // some handy addresses
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1121
  Address rbx_method_fie(     rbx,      methodOopDesc::from_interpreted_offset() );
8495
a4959965eaa3 7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
twisti
parents: 8328
diff changeset
  1122
  Address rbx_method_fce(     rbx,      methodOopDesc::from_compiled_offset() );
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1123
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1124
  Address rcx_mh_vmtarget(    rcx_recv, java_lang_invoke_MethodHandle::vmtarget_offset_in_bytes() );
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1125
  Address rcx_dmh_vmindex(    rcx_recv, java_lang_invoke_DirectMethodHandle::vmindex_offset_in_bytes() );
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1126
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1127
  Address rcx_bmh_vmargslot(  rcx_recv, java_lang_invoke_BoundMethodHandle::vmargslot_offset_in_bytes() );
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1128
  Address rcx_bmh_argument(   rcx_recv, java_lang_invoke_BoundMethodHandle::argument_offset_in_bytes() );
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1129
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1130
  Address rcx_amh_vmargslot(  rcx_recv, java_lang_invoke_AdapterMethodHandle::vmargslot_offset_in_bytes() );
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1131
  Address rcx_amh_argument(   rcx_recv, java_lang_invoke_AdapterMethodHandle::argument_offset_in_bytes() );
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1132
  Address rcx_amh_conversion( rcx_recv, java_lang_invoke_AdapterMethodHandle::conversion_offset_in_bytes() );
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1133
  Address vmarg;                // __ argument_address(vmargslot)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1134
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1135
  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
  1136
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1137
  if (have_entry(ek)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1138
    __ nop();                   // empty stubs make SG sick
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1139
    return;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1140
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1141
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1142
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1143
  __ push((int32_t) 0xEEEEEEEE);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1144
  __ push((int32_t) (intptr_t) entry_name(ek));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1145
  LP64_ONLY(__ push((int32_t) high((intptr_t) entry_name(ek))));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1146
  __ push((int32_t) 0x33333333);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1147
#endif //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1148
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1149
  address interp_entry = __ pc();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1150
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1151
  trace_method_handle(_masm, entry_name(ek));
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1152
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 5547
diff changeset
  1153
  BLOCK_COMMENT(entry_name(ek));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1154
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1155
  switch ((int) ek) {
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1156
  case _raise_exception:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1157
    {
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1158
      // Not a real MH entry, but rather shared code for raising an
8495
a4959965eaa3 7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
twisti
parents: 8328
diff changeset
  1159
      // exception.  Since we use the compiled entry, arguments are
a4959965eaa3 7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
twisti
parents: 8328
diff changeset
  1160
      // expected in compiler argument registers.
7887
7aa0354cbf25 7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents: 7712
diff changeset
  1161
      assert(raise_exception_method(), "must be set");
8495
a4959965eaa3 7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
twisti
parents: 8328
diff changeset
  1162
      assert(raise_exception_method()->from_compiled_entry(), "method must be linked");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1163
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1164
      const Register rdi_pc = rax;
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1165
      __ pop(rdi_pc);  // caller PC
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1166
      __ 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
  1167
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1168
      Register rbx_method = rbx_temp;
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1169
      Label L_no_method;
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8495
diff changeset
  1170
      // FIXME: fill in _raise_exception_method with a suitable java.lang.invoke method
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1171
      __ movptr(rbx_method, ExternalAddress((address) &_raise_exception_method));
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1172
      __ testptr(rbx_method, rbx_method);
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1173
      __ jccb(Assembler::zero, L_no_method);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1174
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1175
      const int jobject_oop_offset = 0;
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1176
      __ 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
  1177
      __ testptr(rbx_method, rbx_method);
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1178
      __ jccb(Assembler::zero, L_no_method);
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1179
      __ verify_oop(rbx_method);
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1180
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1181
      NOT_LP64(__ push(rarg2_required));
8495
a4959965eaa3 7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
twisti
parents: 8328
diff changeset
  1182
      __ push(rdi_pc);         // restore caller PC
a4959965eaa3 7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
twisti
parents: 8328
diff changeset
  1183
      __ jmp(rbx_method_fce);  // jump to compiled entry
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1184
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1185
      // 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
  1186
      __ bind(L_no_method);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1187
      __ push(rarg2_required);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1188
      __ push(rarg1_actual);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1189
      __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1190
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1191
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1192
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1193
  case _invokestatic_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1194
  case _invokespecial_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1195
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1196
      Register rbx_method = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1197
      __ load_heap_oop(rbx_method, rcx_mh_vmtarget); // target is a methodOop
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1198
      __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1199
      // same as TemplateTable::invokestatic or invokespecial,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1200
      // minus the CP setup and profiling:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1201
      if (ek == _invokespecial_mh) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1202
        // Must load & check the first argument before entering the target method.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1203
        __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1204
        __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1205
        __ null_check(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1206
        __ verify_oop(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1207
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1208
      __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1209
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1210
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1211
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1212
  case _invokevirtual_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1213
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1214
      // same as TemplateTable::invokevirtual,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1215
      // minus the CP setup and profiling:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1216
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1217
      // pick out the vtable index and receiver offset from the MH,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1218
      // and then we can discard it:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1219
      __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1220
      Register rbx_index = rbx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1221
      __ movl(rbx_index, rcx_dmh_vmindex);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1222
      // Note:  The verifier allows us to ignore rcx_mh_vmtarget.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1223
      __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1224
      __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1225
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1226
      // get receiver klass
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1227
      Register rax_klass = rax_argslot;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1228
      __ load_klass(rax_klass, rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1229
      __ verify_oop(rax_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1230
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1231
      // get target methodOop & entry point
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1232
      const int base = instanceKlass::vtable_start_offset() * wordSize;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1233
      assert(vtableEntry::size() * wordSize == wordSize, "adjust the scaling in the code below");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1234
      Address vtable_entry_addr(rax_klass,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1235
                                rbx_index, Address::times_ptr,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1236
                                base + vtableEntry::method_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1237
      Register rbx_method = rbx_temp;
4478
c3a8af0fc6b0 6829192: JSR 292 needs to support 64-bit x86
twisti
parents: 4094
diff changeset
  1238
      __ movptr(rbx_method, vtable_entry_addr);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1239
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1240
      __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1241
      __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1242
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1243
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1244
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1245
  case _invokeinterface_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1246
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1247
      // same as TemplateTable::invokeinterface,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1248
      // minus the CP setup and profiling:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1249
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1250
      // pick out the interface and itable index from the MH.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1251
      __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1252
      Register rdx_intf  = rdx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1253
      Register rbx_index = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1254
      __ load_heap_oop(rdx_intf, rcx_mh_vmtarget);
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1255
      __ movl(rbx_index, rcx_dmh_vmindex);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1256
      __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1257
      __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1258
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1259
      // get receiver klass
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1260
      Register rax_klass = rax_argslot;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1261
      __ load_klass(rax_klass, rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1262
      __ verify_oop(rax_klass);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1263
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1264
      Register rbx_method = rbx_index;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1265
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1266
      // get interface klass
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1267
      Label no_such_interface;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1268
      __ verify_oop(rdx_intf);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1269
      __ lookup_interface_method(rax_klass, rdx_intf,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1270
                                 // note: next two args must be the same:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1271
                                 rbx_index, rbx_method,
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1272
                                 rdi_temp,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1273
                                 no_such_interface);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1274
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1275
      __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1276
      __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1277
      __ hlt();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1278
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1279
      __ bind(no_such_interface);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1280
      // Throw an exception.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1281
      // 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
  1282
      __ 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
  1283
      assert_different_registers(rarg2_required, rbx_temp);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1284
      __ 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
  1285
      __ mov(   rarg1_actual,   rbx_temp);                               // bad receiver
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1286
      __ 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
  1287
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1288
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1289
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1290
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1291
  case _bound_ref_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1292
  case _bound_int_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1293
  case _bound_long_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1294
  case _bound_ref_direct_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1295
  case _bound_int_direct_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1296
  case _bound_long_direct_mh:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1297
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1298
      bool direct_to_method = (ek >= _bound_ref_direct_mh);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1299
      BasicType arg_type  = ek_bound_mh_arg_type(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1300
      int       arg_slots = type2size[arg_type];
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1301
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1302
      // make room for the new argument:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1303
      __ movl(rax_argslot, rcx_bmh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1304
      __ lea(rax_argslot, __ argument_address(rax_argslot));
8328
478a1d29e5a3 7018378: JSR 292: _bound_int_mh produces wrong result on 64-bit SPARC
twisti
parents: 7887
diff changeset
  1305
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1306
      insert_arg_slots(_masm, arg_slots * stack_move_unit(), rax_argslot, rbx_temp, rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1307
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1308
      // store bound argument into the new stack slot:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1309
      __ load_heap_oop(rbx_temp, rcx_bmh_argument);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1310
      if (arg_type == T_OBJECT) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1311
        __ movptr(Address(rax_argslot, 0), rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1312
      } else {
8328
478a1d29e5a3 7018378: JSR 292: _bound_int_mh produces wrong result on 64-bit SPARC
twisti
parents: 7887
diff changeset
  1313
        Address prim_value_addr(rbx_temp, java_lang_boxing_object::value_offset_in_bytes(arg_type));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1314
        move_typed_arg(_masm, arg_type, false,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1315
                       Address(rax_argslot, 0),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1316
                       prim_value_addr,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1317
                       rbx_temp, rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1318
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1319
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1320
      if (direct_to_method) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1321
        Register rbx_method = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1322
        __ load_heap_oop(rbx_method, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1323
        __ verify_oop(rbx_method);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1324
        __ jmp(rbx_method_fie);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1325
      } else {
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1326
        __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1327
        __ verify_oop(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1328
        __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1329
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1330
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1331
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1332
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1333
  case _adapter_retype_only:
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1334
  case _adapter_retype_raw:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1335
    // immediately jump to the next MH layer:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1336
    __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1337
    __ verify_oop(rcx_recv);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1338
    __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1339
    // This is OK when all parameter types widen.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1340
    // It is also OK when a return type narrows.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1341
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1342
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1343
  case _adapter_check_cast:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1344
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1345
      // temps:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1346
      Register rbx_klass = rbx_temp; // interesting AMH data
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1347
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1348
      // check a reference argument before jumping to the next layer of MH:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1349
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1350
      vmarg = __ argument_address(rax_argslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1351
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1352
      // What class are we casting to?
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1353
      __ load_heap_oop(rbx_klass, rcx_amh_argument); // this is a Class object!
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1354
      load_klass_from_Class(_masm, rbx_klass);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1355
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1356
      Label done;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1357
      __ movptr(rdx_temp, vmarg);
5028
5a7f933d81c1 6928839: JSR 292 typo in x86 _adapter_check_cast
twisti
parents: 4564
diff changeset
  1358
      __ testptr(rdx_temp, rdx_temp);
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1359
      __ jcc(Assembler::zero, done);         // no cast if null
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1360
      __ load_klass(rdx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1361
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1362
      // live at this point:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1363
      // - rbx_klass:  klass required by the target method
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1364
      // - rdx_temp:   argument klass to test
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1365
      // - rcx_recv:   adapter method handle
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1366
      __ check_klass_subtype(rdx_temp, rbx_klass, rax_argslot, done);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1367
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1368
      // If we get here, the type check failed!
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1369
      // Call the wrong_method_type stub, passing the failing argument type in rax.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1370
      Register rax_mtype = rax_argslot;
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1371
      __ movl(rax_argslot, rcx_amh_vmargslot);  // reload argslot field
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1372
      __ movptr(rdx_temp, vmarg);
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1373
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1374
      assert_different_registers(rarg2_required, rdx_temp);
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1375
      __ 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
  1376
      __ mov(          rarg1_actual,   rdx_temp);                     // bad object
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  1377
      __ 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
  1378
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1379
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1380
      __ bind(done);
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 3262
diff changeset
  1381
      // get the new MH:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1382
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1383
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1384
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1385
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1386
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1387
  case _adapter_prim_to_prim:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1388
  case _adapter_ref_to_prim:
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1389
  case _adapter_prim_to_ref:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1390
    // handled completely by optimized cases
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1391
    __ stop("init_AdapterMethodHandle should not issue this");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1392
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1393
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1394
  case _adapter_opt_i2i:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1395
//case _adapter_opt_f2i:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1396
  case _adapter_opt_l2i:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1397
  case _adapter_opt_unboxi:     // optimized subcase of adapt_ref_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1398
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1399
      // perform an in-place conversion to int or an int subword
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1400
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1401
      vmarg = __ argument_address(rax_argslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1402
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1403
      switch (ek) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1404
      case _adapter_opt_i2i:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1405
        __ movl(rdx_temp, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1406
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1407
      case _adapter_opt_l2i:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1408
        {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1409
          // 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
  1410
          __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1411
          remove_arg_slots(_masm, -stack_move_unit(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1412
                           rax_argslot, rbx_temp, rdx_temp);
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  1413
          vmarg = Address(rax_argslot, -Interpreter::stackElementSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1414
          __ movl(rdx_temp, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1415
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1416
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1417
      case _adapter_opt_unboxi:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1418
        {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1419
          // Load the value up from the heap.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1420
          __ movptr(rdx_temp, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1421
          int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_INT);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1422
#ifdef ASSERT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1423
          for (int bt = T_BOOLEAN; bt < T_INT; bt++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1424
            if (is_subword_type(BasicType(bt)))
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1425
              assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(BasicType(bt)), "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1426
          }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1427
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1428
          __ null_check(rdx_temp, value_offset);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1429
          __ movl(rdx_temp, Address(rdx_temp, value_offset));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1430
          // We load this as a word.  Because we are little-endian,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1431
          // the low bits will be correct, but the high bits may need cleaning.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1432
          // The vminfo will guide us to clean those bits.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1433
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1434
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1435
      default:
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
  1436
        ShouldNotReachHere();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1437
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1438
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
  1439
      // Do the requested conversion and store the value.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1440
      Register rbx_vminfo = rbx_temp;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1441
      load_conversion_vminfo(_masm, rbx_vminfo, rcx_amh_conversion);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1442
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1443
      // get the new MH:
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1444
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1445
      // (now we are done with the old MH)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1446
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1447
      // 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
  1448
      //    | 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
  1449
      __ xchgptr(rcx, rbx_vminfo);                // free rcx for shifts
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1450
      __ shll(rdx_temp /*, rcx*/);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1451
      Label zero_extend, done;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1452
      __ testl(rcx, CONV_VMINFO_SIGN_FLAG);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
  1453
      __ jccb(Assembler::zero, zero_extend);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1454
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1455
      // this path is taken for int->byte, int->short
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1456
      __ sarl(rdx_temp /*, rcx*/);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4562
diff changeset
  1457
      __ jmpb(done);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1458
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1459
      __ bind(zero_extend);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1460
      // this is taken for int->char
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1461
      __ shrl(rdx_temp /*, rcx*/);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1462
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1463
      __ bind(done);
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
  1464
      __ 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
  1465
      __ xchgptr(rcx, rbx_vminfo);                // restore rcx_recv
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1466
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1467
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1468
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1469
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1470
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1471
  case _adapter_opt_i2l:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1472
  case _adapter_opt_unboxl:     // optimized subcase of adapt_ref_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1473
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1474
      // perform an in-place int-to-long or ref-to-long conversion
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1475
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1476
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1477
      // 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
  1478
      __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1479
      insert_arg_slots(_masm, stack_move_unit(),
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1480
                       rax_argslot, rbx_temp, rdx_temp);
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  1481
      Address vmarg1(rax_argslot, -Interpreter::stackElementSize);
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  1482
      Address vmarg2 = vmarg1.plus_disp(Interpreter::stackElementSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1483
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1484
      switch (ek) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1485
      case _adapter_opt_i2l:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1486
        {
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1487
#ifdef _LP64
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1488
          __ movslq(rdx_temp, vmarg1);  // Load sign-extended
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1489
          __ movq(vmarg1, rdx_temp);    // Store into first slot
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1490
#else
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1491
          __ movl(rdx_temp, vmarg1);
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1492
          __ sarl(rdx_temp, BitsPerInt - 1);  // __ extend_sign()
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1493
          __ movl(vmarg2, rdx_temp); // store second word
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1494
#endif
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1495
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1496
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1497
      case _adapter_opt_unboxl:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1498
        {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1499
          // Load the value up from the heap.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1500
          __ movptr(rdx_temp, vmarg1);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1501
          int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_LONG);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1502
          assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE), "");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1503
          __ null_check(rdx_temp, value_offset);
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1504
#ifdef _LP64
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1505
          __ movq(rbx_temp, Address(rdx_temp, value_offset));
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1506
          __ movq(vmarg1, rbx_temp);
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1507
#else
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1508
          __ movl(rbx_temp, Address(rdx_temp, value_offset + 0*BytesPerInt));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1509
          __ movl(rdx_temp, Address(rdx_temp, value_offset + 1*BytesPerInt));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1510
          __ movl(vmarg1, rbx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1511
          __ movl(vmarg2, rdx_temp);
5044
7e40acdf2163 6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents: 5028
diff changeset
  1512
#endif
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1513
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1514
        break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1515
      default:
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
  1516
        ShouldNotReachHere();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1517
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1518
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1519
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1520
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1521
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1522
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1523
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1524
  case _adapter_opt_f2d:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1525
  case _adapter_opt_d2f:        // optimized subcase of adapt_prim_to_prim
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1526
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1527
      // perform an in-place floating primitive conversion
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1528
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1529
      __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1530
      if (ek == _adapter_opt_f2d) {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1531
        insert_arg_slots(_masm, stack_move_unit(),
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1532
                         rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1533
      }
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  1534
      Address vmarg(rax_argslot, -Interpreter::stackElementSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1535
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1536
#ifdef _LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1537
      if (ek == _adapter_opt_f2d) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1538
        __ movflt(xmm0, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1539
        __ cvtss2sd(xmm0, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1540
        __ movdbl(vmarg, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1541
      } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1542
        __ movdbl(xmm0, vmarg);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1543
        __ cvtsd2ss(xmm0, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1544
        __ movflt(vmarg, xmm0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1545
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1546
#else //_LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1547
      if (ek == _adapter_opt_f2d) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1548
        __ fld_s(vmarg);        // load float to ST0
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1549
        __ fstp_s(vmarg);       // store single
5055
743f38c6e179 6932091: JSR 292 x86 code cleanup
twisti
parents: 5044
diff changeset
  1550
      } else {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1551
        __ fld_d(vmarg);        // load double to ST0
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1552
        __ fstp_s(vmarg);       // store single
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1553
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1554
#endif //_LP64
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1555
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1556
      if (ek == _adapter_opt_d2f) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1557
        remove_arg_slots(_masm, -stack_move_unit(),
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1558
                         rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1559
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1560
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1561
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1562
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1563
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1564
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1565
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1566
  case _adapter_swap_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1567
  case _adapter_rot_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1568
    // handled completely by optimized cases
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1569
    __ stop("init_AdapterMethodHandle should not issue this");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1570
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1571
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1572
  case _adapter_opt_swap_1:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1573
  case _adapter_opt_swap_2:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1574
  case _adapter_opt_rot_1_up:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1575
  case _adapter_opt_rot_1_down:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1576
  case _adapter_opt_rot_2_up:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1577
  case _adapter_opt_rot_2_down:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1578
    {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1579
      int swap_slots = ek_adapter_opt_swap_slots(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1580
      int rotate     = ek_adapter_opt_swap_mode(ek);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1581
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1582
      // 'argslot' is the position of the first argument to swap
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1583
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1584
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1585
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1586
      // 'vminfo' is the second
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1587
      Register rbx_destslot = rbx_temp;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1588
      load_conversion_vminfo(_masm, rbx_destslot, rcx_amh_conversion);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1589
      __ lea(rbx_destslot, __ argument_address(rbx_destslot));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1590
      if (VerifyMethodHandles)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1591
        verify_argslot(_masm, rbx_destslot, "swap point must fall within current frame");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1592
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1593
      assert(Interpreter::stackElementSize == wordSize, "else rethink use of wordSize here");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1594
      if (!rotate) {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1595
        // simple swap
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1596
        for (int i = 0; i < swap_slots; i++) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1597
          __ movptr(rdi_temp, Address(rax_argslot,  i * wordSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1598
          __ movptr(rdx_temp, Address(rbx_destslot, i * wordSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1599
          __ movptr(Address(rax_argslot,  i * wordSize), rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1600
          __ movptr(Address(rbx_destslot, i * wordSize), rdi_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1601
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1602
      } else {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1603
        // A rotate is actually pair of moves, with an "odd slot" (or pair)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1604
        // changing place with a series of other slots.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1605
        // First, push the "odd slot", which is going to get overwritten
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1606
        for (int i = swap_slots - 1; i >= 0; i--) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1607
          // handle one with rdi_temp instead of a push:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1608
          if (i == 0)  __ movptr(rdi_temp, Address(rax_argslot, i * wordSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1609
          else         __ pushptr(         Address(rax_argslot, i * wordSize));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1610
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1611
        if (rotate > 0) {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1612
          // Here is rotate > 0:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1613
          // (low mem)                                          (high mem)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1614
          //     | dest:     more_slots...     | arg: odd_slot :arg+1 |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1615
          // =>
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1616
          //     | dest: odd_slot | dest+1: more_slots...      :arg+1 |
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1617
          // work argslot down to destslot, copying contiguous data upwards
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1618
          // pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1619
          //   rax = src_addr - swap_bytes
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1620
          //   rbx = dest_addr
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1621
          //   while (rax >= rbx) *(rax + swap_bytes) = *(rax + 0), rax--;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1622
          move_arg_slots_up(_masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1623
                            rbx_destslot,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1624
                            Address(rax_argslot, 0),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1625
                            swap_slots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1626
                            rax_argslot, rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1627
        } else {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1628
          // Here is the other direction, rotate < 0:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1629
          // (low mem)                                          (high mem)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1630
          //     | arg: odd_slot | arg+1: more_slots...       :dest+1 |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1631
          // =>
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1632
          //     | arg:    more_slots...     | dest: odd_slot :dest+1 |
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1633
          // work argslot up to destslot, copying contiguous data downwards
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1634
          // pseudo-code:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1635
          //   rax = src_addr + swap_bytes
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1636
          //   rbx = dest_addr
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1637
          //   while (rax <= rbx) *(rax - swap_bytes) = *(rax + 0), rax++;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1638
          __ addptr(rbx_destslot, wordSize);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1639
          move_arg_slots_down(_masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1640
                              Address(rax_argslot, swap_slots * wordSize),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1641
                              rbx_destslot,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1642
                              -swap_slots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1643
                              rax_argslot, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1644
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1645
          __ subptr(rbx_destslot, wordSize);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1646
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1647
        // pop the original first chunk into the destination slot, now free
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1648
        for (int i = 0; i < swap_slots; i++) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1649
          if (i == 0)  __ movptr(Address(rbx_destslot, i * wordSize), rdi_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1650
          else         __ popptr(Address(rbx_destslot, i * wordSize));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1651
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1652
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1653
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1654
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1655
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1656
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1657
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1658
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1659
  case _adapter_dup_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1660
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1661
      // 'argslot' is the position of the first argument to duplicate
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1662
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1663
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1664
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1665
      // 'stack_move' is negative number of words to duplicate
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1666
      Register rdi_stack_move = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1667
      load_stack_move(_masm, rdi_stack_move, rcx_recv, true);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1668
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1669
      if (VerifyMethodHandles) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1670
        verify_argslots(_masm, rdi_stack_move, rax_argslot, true,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1671
                        "copied argument(s) must fall within current frame");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1672
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1673
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1674
      // insert location is always the bottom of the argument list:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1675
      Address insert_location = __ argument_address(constant(0));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1676
      int pre_arg_words = insert_location.disp() / wordSize;   // return PC is pushed
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1677
      assert(insert_location.base() == rsp, "");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1678
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1679
      __ negl(rdi_stack_move);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1680
      push_arg_slots(_masm, rax_argslot, rdi_stack_move,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1681
                     pre_arg_words, rbx_temp, rdx_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1682
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1683
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1684
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1685
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1686
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1687
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1688
  case _adapter_drop_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1689
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1690
      // 'argslot' is the position of the first argument to nuke
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1691
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1692
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1693
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1694
      // (must do previous push after argslot address is taken)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1695
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1696
      // 'stack_move' is number of words to drop
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1697
      Register rdi_stack_move = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1698
      load_stack_move(_masm, rdi_stack_move, rcx_recv, false);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1699
      remove_arg_slots(_masm, rdi_stack_move,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1700
                       rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1701
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  1702
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1703
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1704
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1705
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1706
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1707
  case _adapter_collect_args:
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1708
  case _adapter_fold_args:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1709
  case _adapter_spread_args:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1710
    // handled completely by optimized cases
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1711
    __ stop("init_AdapterMethodHandle should not issue this");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1712
    break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1713
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1714
  case _adapter_opt_collect_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1715
  case _adapter_opt_collect_int:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1716
  case _adapter_opt_collect_long:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1717
  case _adapter_opt_collect_float:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1718
  case _adapter_opt_collect_double:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1719
  case _adapter_opt_collect_void:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1720
  case _adapter_opt_collect_0_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1721
  case _adapter_opt_collect_1_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1722
  case _adapter_opt_collect_2_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1723
  case _adapter_opt_collect_3_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1724
  case _adapter_opt_collect_4_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1725
  case _adapter_opt_collect_5_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1726
  case _adapter_opt_filter_S0_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1727
  case _adapter_opt_filter_S1_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1728
  case _adapter_opt_filter_S2_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1729
  case _adapter_opt_filter_S3_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1730
  case _adapter_opt_filter_S4_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1731
  case _adapter_opt_filter_S5_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1732
  case _adapter_opt_collect_2_S0_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1733
  case _adapter_opt_collect_2_S1_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1734
  case _adapter_opt_collect_2_S2_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1735
  case _adapter_opt_collect_2_S3_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1736
  case _adapter_opt_collect_2_S4_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1737
  case _adapter_opt_collect_2_S5_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1738
  case _adapter_opt_fold_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1739
  case _adapter_opt_fold_int:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1740
  case _adapter_opt_fold_long:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1741
  case _adapter_opt_fold_float:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1742
  case _adapter_opt_fold_double:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1743
  case _adapter_opt_fold_void:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1744
  case _adapter_opt_fold_1_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1745
  case _adapter_opt_fold_2_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1746
  case _adapter_opt_fold_3_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1747
  case _adapter_opt_fold_4_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1748
  case _adapter_opt_fold_5_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1749
    {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1750
      // Given a fresh incoming stack frame, build a new ricochet frame.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1751
      // On entry, TOS points at a return PC, and RBP is the callers frame ptr.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1752
      // RSI/R13 has the caller's exact stack pointer, which we must also preserve.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1753
      // RCX contains an AdapterMethodHandle of the indicated kind.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1754
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1755
      // Relevant AMH fields:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1756
      // amh.vmargslot:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1757
      //   points to the trailing edge of the arguments
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1758
      //   to filter, collect, or fold.  For a boxing operation,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1759
      //   it points just after the single primitive value.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1760
      // amh.argument:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1761
      //   recursively called MH, on |collect| arguments
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1762
      // amh.vmtarget:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1763
      //   final destination MH, on return value, etc.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1764
      // amh.conversion.dest:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1765
      //   tells what is the type of the return value
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1766
      //   (not needed here, since dest is also derived from ek)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1767
      // amh.conversion.vminfo:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1768
      //   points to the trailing edge of the return value
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1769
      //   when the vmtarget is to be called; this is
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1770
      //   equal to vmargslot + (retained ? |collect| : 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1771
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1772
      // Pass 0 or more argument slots to the recursive target.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1773
      int collect_count_constant = ek_adapter_opt_collect_count(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1774
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1775
      // The collected arguments are copied from the saved argument list:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1776
      int collect_slot_constant = ek_adapter_opt_collect_slot(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1777
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1778
      assert(ek_orig == _adapter_collect_args ||
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1779
             ek_orig == _adapter_fold_args, "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1780
      bool retain_original_args = (ek_orig == _adapter_fold_args);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1781
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1782
      // The return value is replaced (or inserted) at the 'vminfo' argslot.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1783
      // Sometimes we can compute this statically.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1784
      int dest_slot_constant = -1;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1785
      if (!retain_original_args)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1786
        dest_slot_constant = collect_slot_constant;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1787
      else if (collect_slot_constant >= 0 && collect_count_constant >= 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1788
        // We are preserving all the arguments, and the return value is prepended,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1789
        // so the return slot is to the left (above) the |collect| sequence.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1790
        dest_slot_constant = collect_slot_constant + collect_count_constant;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1791
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1792
      // Replace all those slots by the result of the recursive call.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1793
      // The result type can be one of ref, int, long, float, double, void.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1794
      // In the case of void, nothing is pushed on the stack after return.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1795
      BasicType dest = ek_adapter_opt_collect_type(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1796
      assert(dest == type2wfield[dest], "dest is a stack slot type");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1797
      int dest_count = type2size[dest];
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1798
      assert(dest_count == 1 || dest_count == 2 || (dest_count == 0 && dest == T_VOID), "dest has a size");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1799
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1800
      // Choose a return continuation.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1801
      EntryKind ek_ret = _adapter_opt_return_any;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1802
      if (dest != T_CONFLICT && OptimizeMethodHandles) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1803
        switch (dest) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1804
        case T_INT    : ek_ret = _adapter_opt_return_int;     break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1805
        case T_LONG   : ek_ret = _adapter_opt_return_long;    break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1806
        case T_FLOAT  : ek_ret = _adapter_opt_return_float;   break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1807
        case T_DOUBLE : ek_ret = _adapter_opt_return_double;  break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1808
        case T_OBJECT : ek_ret = _adapter_opt_return_ref;     break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1809
        case T_VOID   : ek_ret = _adapter_opt_return_void;    break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1810
        default       : ShouldNotReachHere();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1811
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1812
        if (dest == T_OBJECT && dest_slot_constant >= 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1813
          EntryKind ek_try = EntryKind(_adapter_opt_return_S0_ref + dest_slot_constant);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1814
          if (ek_try <= _adapter_opt_return_LAST &&
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1815
              ek_adapter_opt_return_slot(ek_try) == dest_slot_constant) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1816
            ek_ret = ek_try;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1817
          }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1818
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1819
        assert(ek_adapter_opt_return_type(ek_ret) == dest, "");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1820
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1821
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1822
      // Already pushed:  ... keep1 | collect | keep2 | sender_pc |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1823
      // push(sender_pc);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1824
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1825
      // Compute argument base:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1826
      Register rax_argv = rax_argslot;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1827
      __ lea(rax_argv, __ argument_address(constant(0)));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1828
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1829
      // Push a few extra argument words, if we need them to store the return value.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1830
      {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1831
        int extra_slots = 0;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1832
        if (retain_original_args) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1833
          extra_slots = dest_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1834
        } else if (collect_count_constant == -1) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1835
          extra_slots = dest_count;  // collect_count might be zero; be generous
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1836
        } else if (dest_count > collect_count_constant) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1837
          extra_slots = (dest_count - collect_count_constant);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1838
        } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1839
          // else we know we have enough dead space in |collect| to repurpose for return values
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1840
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1841
        DEBUG_ONLY(extra_slots += 1);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1842
        if (extra_slots > 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1843
          __ pop(rbx_temp);   // return value
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1844
          __ subptr(rsp, (extra_slots * Interpreter::stackElementSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1845
          // Push guard word #2 in debug mode.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1846
          DEBUG_ONLY(__ movptr(Address(rsp, 0), (int32_t) RicochetFrame::MAGIC_NUMBER_2));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1847
          __ push(rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1848
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1849
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1850
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1851
      RicochetFrame::enter_ricochet_frame(_masm, rcx_recv, rax_argv,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1852
                                          entry(ek_ret)->from_interpreted_entry(), rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1853
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1854
      // Now pushed:  ... keep1 | collect | keep2 | RF |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1855
      // some handy frame slots:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1856
      Address exact_sender_sp_addr = RicochetFrame::frame_address(RicochetFrame::exact_sender_sp_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1857
      Address conversion_addr      = RicochetFrame::frame_address(RicochetFrame::conversion_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1858
      Address saved_args_base_addr = RicochetFrame::frame_address(RicochetFrame::saved_args_base_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1859
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1860
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1861
      if (VerifyMethodHandles && dest != T_CONFLICT) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1862
        BLOCK_COMMENT("verify AMH.conv.dest");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1863
        load_conversion_dest_type(_masm, rbx_temp, conversion_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1864
        Label L_dest_ok;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1865
        __ cmpl(rbx_temp, (int) dest);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1866
        __ jcc(Assembler::equal, L_dest_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1867
        if (dest == T_INT) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1868
          for (int bt = T_BOOLEAN; bt < T_INT; bt++) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1869
            if (is_subword_type(BasicType(bt))) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1870
              __ cmpl(rbx_temp, (int) bt);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1871
              __ jcc(Assembler::equal, L_dest_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1872
            }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1873
          }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1874
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1875
        __ stop("bad dest in AMH.conv");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1876
        __ BIND(L_dest_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1877
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1878
#endif //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1879
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1880
      // Find out where the original copy of the recursive argument sequence begins.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1881
      Register rax_coll = rax_argv;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1882
      {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1883
        RegisterOrConstant collect_slot = collect_slot_constant;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1884
        if (collect_slot_constant == -1) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1885
          __ movl(rdi_temp, rcx_amh_vmargslot);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1886
          collect_slot = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1887
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1888
        if (collect_slot_constant != 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1889
          __ lea(rax_coll, Address(rax_argv, collect_slot, Interpreter::stackElementScale()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1890
        // rax_coll now points at the trailing edge of |collect| and leading edge of |keep2|
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1891
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1892
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1893
      // Replace the old AMH with the recursive MH.  (No going back now.)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1894
      // In the case of a boxing call, the recursive call is to a 'boxer' method,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1895
      // such as Integer.valueOf or Long.valueOf.  In the case of a filter
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1896
      // or collect call, it will take one or more arguments, transform them,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1897
      // and return some result, to store back into argument_base[vminfo].
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1898
      __ load_heap_oop(rcx_recv, rcx_amh_argument);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1899
      if (VerifyMethodHandles)  verify_method_handle(_masm, rcx_recv);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1900
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1901
      // Push a space for the recursively called MH first:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1902
      __ push((int32_t)NULL_WORD);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1903
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1904
      // Calculate |collect|, the number of arguments we are collecting.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1905
      Register rdi_collect_count = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1906
      RegisterOrConstant collect_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1907
      if (collect_count_constant >= 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1908
        collect_count = collect_count_constant;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1909
      } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1910
        __ load_method_handle_vmslots(rdi_collect_count, rcx_recv, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1911
        collect_count = rdi_collect_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1912
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1913
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1914
      if (VerifyMethodHandles && collect_count_constant >= 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1915
        __ load_method_handle_vmslots(rbx_temp, rcx_recv, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1916
        Label L_count_ok;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1917
        __ cmpl(rbx_temp, collect_count_constant);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1918
        __ jcc(Assembler::equal, L_count_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1919
        __ stop("bad vminfo in AMH.conv");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1920
        __ BIND(L_count_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1921
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1922
#endif //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1923
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1924
      // copy |collect| slots directly to TOS:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1925
      push_arg_slots(_masm, rax_coll, collect_count, 0, rbx_temp, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1926
      // Now pushed:  ... keep1 | collect | keep2 | RF... | collect |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1927
      // rax_coll still points at the trailing edge of |collect| and leading edge of |keep2|
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1928
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1929
      // If necessary, adjust the saved arguments to make room for the eventual return value.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1930
      // Normal adjustment:  ... keep1 | +dest+ | -collect- | keep2 | RF... | collect |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1931
      // If retaining args:  ... keep1 | +dest+ |  collect  | keep2 | RF... | collect |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1932
      // In the non-retaining case, this might move keep2 either up or down.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1933
      // We don't have to copy the whole | RF... collect | complex,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1934
      // but we must adjust RF.saved_args_base.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1935
      // Also, from now on, we will forget about the origial copy of |collect|.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1936
      // If we are retaining it, we will treat it as part of |keep2|.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1937
      // For clarity we will define |keep3| = |collect|keep2| or |keep2|.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1938
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1939
      BLOCK_COMMENT("adjust trailing arguments {");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1940
      // Compare the sizes of |+dest+| and |-collect-|, which are opposed opening and closing movements.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1941
      int                open_count  = dest_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1942
      RegisterOrConstant close_count = collect_count_constant;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1943
      Register rdi_close_count = rdi_collect_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1944
      if (retain_original_args) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1945
        close_count = constant(0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1946
      } else if (collect_count_constant == -1) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1947
        close_count = rdi_collect_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1948
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1949
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1950
      // How many slots need moving?  This is simply dest_slot (0 => no |keep3|).
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1951
      RegisterOrConstant keep3_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1952
      Register rsi_keep3_count = rsi;  // can repair from RF.exact_sender_sp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1953
      if (dest_slot_constant >= 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1954
        keep3_count = dest_slot_constant;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1955
      } else  {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1956
        load_conversion_vminfo(_masm, rsi_keep3_count, conversion_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1957
        keep3_count = rsi_keep3_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1958
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1959
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1960
      if (VerifyMethodHandles && dest_slot_constant >= 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1961
        load_conversion_vminfo(_masm, rbx_temp, conversion_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1962
        Label L_vminfo_ok;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1963
        __ cmpl(rbx_temp, dest_slot_constant);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1964
        __ jcc(Assembler::equal, L_vminfo_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1965
        __ stop("bad vminfo in AMH.conv");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1966
        __ BIND(L_vminfo_ok);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1967
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1968
#endif //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1969
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1970
      // tasks remaining:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1971
      bool move_keep3 = (!keep3_count.is_constant() || keep3_count.as_constant() != 0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1972
      bool stomp_dest = (NOT_DEBUG(dest == T_OBJECT) DEBUG_ONLY(dest_count != 0));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1973
      bool fix_arg_base = (!close_count.is_constant() || open_count != close_count.as_constant());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1974
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1975
      if (stomp_dest | fix_arg_base) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1976
        // we will probably need an updated rax_argv value
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1977
        if (collect_slot_constant >= 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1978
          // rax_coll already holds the leading edge of |keep2|, so tweak it
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1979
          assert(rax_coll == rax_argv, "elided a move");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1980
          if (collect_slot_constant != 0)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1981
            __ subptr(rax_argv, collect_slot_constant * Interpreter::stackElementSize);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1982
        } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1983
          // Just reload from RF.saved_args_base.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1984
          __ movptr(rax_argv, saved_args_base_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1985
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1986
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1987
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1988
      // Old and new argument locations (based at slot 0).
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1989
      // Net shift (&new_argv - &old_argv) is (close_count - open_count).
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1990
      bool zero_open_count = (open_count == 0);  // remember this bit of info
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1991
      if (move_keep3 && fix_arg_base) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1992
        // It will be easier t have everything in one register:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1993
        if (close_count.is_register()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1994
          // Deduct open_count from close_count register to get a clean +/- value.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1995
          __ subptr(close_count.as_register(), open_count);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1996
        } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1997
          close_count = close_count.as_constant() - open_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1998
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  1999
        open_count = 0;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2000
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2001
      Address old_argv(rax_argv, 0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2002
      Address new_argv(rax_argv, close_count,  Interpreter::stackElementScale(),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2003
                                - open_count * Interpreter::stackElementSize);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2004
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2005
      // First decide if any actual data are to be moved.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2006
      // We can skip if (a) |keep3| is empty, or (b) the argument list size didn't change.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2007
      // (As it happens, all movements involve an argument list size change.)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2008
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2009
      // If there are variable parameters, use dynamic checks to skip around the whole mess.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2010
      Label L_done;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2011
      if (!keep3_count.is_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2012
        __ testl(keep3_count.as_register(), keep3_count.as_register());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2013
        __ jcc(Assembler::zero, L_done);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2014
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2015
      if (!close_count.is_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2016
        __ cmpl(close_count.as_register(), open_count);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2017
        __ jcc(Assembler::equal, L_done);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2018
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2019
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2020
      if (move_keep3 && fix_arg_base) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2021
        bool emit_move_down = false, emit_move_up = false, emit_guard = false;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2022
        if (!close_count.is_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2023
          emit_move_down = emit_guard = !zero_open_count;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2024
          emit_move_up   = true;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2025
        } else if (open_count != close_count.as_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2026
          emit_move_down = (open_count > close_count.as_constant());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2027
          emit_move_up   = !emit_move_down;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2028
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2029
        Label L_move_up;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2030
        if (emit_guard) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2031
          __ cmpl(close_count.as_register(), open_count);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2032
          __ jcc(Assembler::greater, L_move_up);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2033
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2034
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2035
        if (emit_move_down) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2036
          // Move arguments down if |+dest+| > |-collect-|
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2037
          // (This is rare, except when arguments are retained.)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2038
          // This opens space for the return value.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2039
          if (keep3_count.is_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2040
            for (int i = 0; i < keep3_count.as_constant(); i++) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2041
              __ movptr(rdx_temp, old_argv.plus_disp(i * Interpreter::stackElementSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2042
              __ movptr(          new_argv.plus_disp(i * Interpreter::stackElementSize), rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2043
            }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2044
          } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2045
            Register rbx_argv_top = rbx_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2046
            __ lea(rbx_argv_top, old_argv.plus_disp(keep3_count, Interpreter::stackElementScale()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2047
            move_arg_slots_down(_masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2048
                                old_argv,     // beginning of old argv
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2049
                                rbx_argv_top, // end of old argv
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2050
                                close_count,  // distance to move down (must be negative)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2051
                                rax_argv, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2052
            // Used argv as an iteration variable; reload from RF.saved_args_base.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2053
            __ movptr(rax_argv, saved_args_base_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2054
          }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2055
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2056
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2057
        if (emit_guard) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2058
          __ jmp(L_done);  // assumes emit_move_up is true also
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2059
          __ BIND(L_move_up);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2060
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2061
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2062
        if (emit_move_up) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2063
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2064
          // Move arguments up if |+dest+| < |-collect-|
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2065
          // (This is usual, except when |keep3| is empty.)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2066
          // This closes up the space occupied by the now-deleted collect values.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2067
          if (keep3_count.is_constant()) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2068
            for (int i = keep3_count.as_constant() - 1; i >= 0; i--) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2069
              __ movptr(rdx_temp, old_argv.plus_disp(i * Interpreter::stackElementSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2070
              __ movptr(          new_argv.plus_disp(i * Interpreter::stackElementSize), rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2071
            }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2072
          } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2073
            Address argv_top = old_argv.plus_disp(keep3_count, Interpreter::stackElementScale());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2074
            move_arg_slots_up(_masm,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2075
                              rax_argv,     // beginning of old argv
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2076
                              argv_top,     // end of old argv
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2077
                              close_count,  // distance to move up (must be positive)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2078
                              rbx_temp, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2079
          }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2080
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2081
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2082
      __ BIND(L_done);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2083
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2084
      if (fix_arg_base) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2085
        // adjust RF.saved_args_base by adding (close_count - open_count)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2086
        if (!new_argv.is_same_address(Address(rax_argv, 0)))
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2087
          __ lea(rax_argv, new_argv);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2088
        __ movptr(saved_args_base_addr, rax_argv);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2089
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2090
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2091
      if (stomp_dest) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2092
        // Stomp the return slot, so it doesn't hold garbage.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2093
        // This isn't strictly necessary, but it may help detect bugs.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2094
        int forty_two = RicochetFrame::RETURN_VALUE_PLACEHOLDER;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2095
        __ movptr(Address(rax_argv, keep3_count, Address::times_ptr),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2096
                  (int32_t) forty_two);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2097
        // uses rsi_keep3_count
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2098
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2099
      BLOCK_COMMENT("} adjust trailing arguments");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2100
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2101
      BLOCK_COMMENT("do_recursive_call");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2102
      __ mov(saved_last_sp, rsp);    // set rsi/r13 for callee
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2103
      __ pushptr(ExternalAddress(SharedRuntime::ricochet_blob()->bounce_addr()).addr());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2104
      // The globally unique bounce address has two purposes:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2105
      // 1. It helps the JVM recognize this frame (frame::is_ricochet_frame).
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2106
      // 2. When returned to, it cuts back the stack and redirects control flow
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2107
      //    to the return handler.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2108
      // The return handler will further cut back the stack when it takes
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2109
      // down the RF.  Perhaps there is a way to streamline this further.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2110
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2111
      // State during recursive call:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2112
      // ... keep1 | dest | dest=42 | keep3 | RF... | collect | bounce_pc |
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2113
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2114
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2115
      break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2116
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2117
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2118
  case _adapter_opt_return_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2119
  case _adapter_opt_return_int:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2120
  case _adapter_opt_return_long:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2121
  case _adapter_opt_return_float:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2122
  case _adapter_opt_return_double:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2123
  case _adapter_opt_return_void:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2124
  case _adapter_opt_return_S0_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2125
  case _adapter_opt_return_S1_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2126
  case _adapter_opt_return_S2_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2127
  case _adapter_opt_return_S3_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2128
  case _adapter_opt_return_S4_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2129
  case _adapter_opt_return_S5_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2130
    {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2131
      BasicType dest_type_constant = ek_adapter_opt_return_type(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2132
      int       dest_slot_constant = ek_adapter_opt_return_slot(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2133
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2134
      if (VerifyMethodHandles)  RicochetFrame::verify_clean(_masm);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2135
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2136
      if (dest_slot_constant == -1) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2137
        // The current stub is a general handler for this dest_type.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2138
        // It can be called from _adapter_opt_return_any below.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2139
        // Stash the address in a little table.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2140
        assert((dest_type_constant & CONV_TYPE_MASK) == dest_type_constant, "oob");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2141
        address return_handler = __ pc();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2142
        _adapter_return_handlers[dest_type_constant] = return_handler;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2143
        if (dest_type_constant == T_INT) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2144
          // do the subword types too
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2145
          for (int bt = T_BOOLEAN; bt < T_INT; bt++) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2146
            if (is_subword_type(BasicType(bt)) &&
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2147
                _adapter_return_handlers[bt] == NULL) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2148
              _adapter_return_handlers[bt] = return_handler;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2149
            }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2150
          }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2151
        }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2152
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2153
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2154
      Register rbx_arg_base = rbx_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2155
      assert_different_registers(rax, rdx,  // possibly live return value registers
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2156
                                 rdi_temp, rbx_arg_base);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2157
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2158
      Address conversion_addr      = RicochetFrame::frame_address(RicochetFrame::conversion_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2159
      Address saved_args_base_addr = RicochetFrame::frame_address(RicochetFrame::saved_args_base_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2160
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2161
      __ movptr(rbx_arg_base, saved_args_base_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2162
      RegisterOrConstant dest_slot = dest_slot_constant;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2163
      if (dest_slot_constant == -1) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2164
        load_conversion_vminfo(_masm, rdi_temp, conversion_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2165
        dest_slot = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2166
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2167
      // Store the result back into the argslot.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2168
      // This code uses the interpreter calling sequence, in which the return value
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2169
      // is usually left in the TOS register, as defined by InterpreterMacroAssembler::pop.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2170
      // There are certain irregularities with floating point values, which can be seen
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2171
      // in TemplateInterpreterGenerator::generate_return_entry_for.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2172
      move_return_value(_masm, dest_type_constant, Address(rbx_arg_base, dest_slot, Interpreter::stackElementScale()));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2173
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2174
      RicochetFrame::leave_ricochet_frame(_masm, rcx_recv, rbx_arg_base, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2175
      __ push(rdx_temp);  // repush the return PC
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2176
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2177
      // Load the final target and go.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2178
      if (VerifyMethodHandles)  verify_method_handle(_masm, rcx_recv);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2179
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2180
      __ hlt(); // --------------------
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2181
      break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2182
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2183
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2184
  case _adapter_opt_return_any:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2185
    {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2186
      if (VerifyMethodHandles)  RicochetFrame::verify_clean(_masm);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2187
      Register rdi_conv = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2188
      assert_different_registers(rax, rdx,  // possibly live return value registers
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2189
                                 rdi_conv, rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2190
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2191
      Address conversion_addr = RicochetFrame::frame_address(RicochetFrame::conversion_offset_in_bytes());
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2192
      load_conversion_dest_type(_masm, rdi_conv, conversion_addr);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2193
      __ lea(rbx_temp, ExternalAddress((address) &_adapter_return_handlers[0]));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2194
      __ movptr(rbx_temp, Address(rbx_temp, rdi_conv, Address::times_ptr));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2195
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2196
#ifdef ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2197
      { Label L_badconv;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2198
        __ testptr(rbx_temp, rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2199
        __ jccb(Assembler::zero, L_badconv);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2200
        __ jmp(rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2201
        __ bind(L_badconv);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2202
        __ stop("bad method handle return");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2203
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2204
#else //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2205
      __ jmp(rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2206
#endif //ASSERT
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2207
      break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2208
    }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2209
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2210
  case _adapter_opt_spread_0:
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2211
  case _adapter_opt_spread_1_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2212
  case _adapter_opt_spread_2_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2213
  case _adapter_opt_spread_3_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2214
  case _adapter_opt_spread_4_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2215
  case _adapter_opt_spread_5_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2216
  case _adapter_opt_spread_ref:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2217
  case _adapter_opt_spread_byte:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2218
  case _adapter_opt_spread_char:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2219
  case _adapter_opt_spread_short:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2220
  case _adapter_opt_spread_int:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2221
  case _adapter_opt_spread_long:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2222
  case _adapter_opt_spread_float:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2223
  case _adapter_opt_spread_double:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2224
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2225
      // spread an array out into a group of arguments
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2226
      int length_constant = ek_adapter_opt_spread_count(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2227
      bool length_can_be_zero = (length_constant == 0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2228
      if (length_constant < 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2229
        // some adapters with variable length must handle the zero case
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2230
        if (!OptimizeMethodHandles ||
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2231
            ek_adapter_opt_spread_type(ek) != T_OBJECT)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2232
          length_can_be_zero = true;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2233
      }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2234
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2235
      // find the address of the array argument
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2236
      __ movl(rax_argslot, rcx_amh_vmargslot);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2237
      __ lea(rax_argslot, __ argument_address(rax_argslot));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2238
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2239
      // grab another temp
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2240
      Register rsi_temp = rsi;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2241
      { if (rsi_temp == saved_last_sp)  __ push(saved_last_sp); }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2242
      // (preceding push must be done after argslot address is taken!)
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2243
#define UNPUSH_RSI \
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2244
      { if (rsi_temp == saved_last_sp)  __ pop(saved_last_sp); }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2245
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2246
      // arx_argslot points both to the array and to the first output arg
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2247
      vmarg = Address(rax_argslot, 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2248
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2249
      // Get the array value.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2250
      Register  rsi_array       = rsi_temp;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2251
      Register  rdx_array_klass = rdx_temp;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2252
      BasicType elem_type = ek_adapter_opt_spread_type(ek);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2253
      int       elem_slots = type2size[elem_type];  // 1 or 2
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2254
      int       array_slots = 1;  // array is always a T_OBJECT
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2255
      int       length_offset   = arrayOopDesc::length_offset_in_bytes();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2256
      int       elem0_offset    = arrayOopDesc::base_offset_in_bytes(elem_type);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2257
      __ movptr(rsi_array, vmarg);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2258
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2259
      Label L_array_is_empty, L_insert_arg_space, L_copy_args, L_args_done;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2260
      if (length_can_be_zero) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2261
        // handle the null pointer case, if zero is allowed
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2262
        Label L_skip;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2263
        if (length_constant < 0) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2264
          load_conversion_vminfo(_masm, rbx_temp, rcx_amh_conversion);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2265
          __ testl(rbx_temp, rbx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2266
          __ jcc(Assembler::notZero, L_skip);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2267
        }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2268
        __ testptr(rsi_array, rsi_array);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2269
        __ jcc(Assembler::zero, L_array_is_empty);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2270
        __ bind(L_skip);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2271
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2272
      __ null_check(rsi_array, oopDesc::klass_offset_in_bytes());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2273
      __ load_klass(rdx_array_klass, rsi_array);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2274
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2275
      // Check the array type.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2276
      Register rbx_klass = rbx_temp;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  2277
      __ load_heap_oop(rbx_klass, rcx_amh_argument); // this is a Class object!
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2278
      load_klass_from_Class(_masm, rbx_klass);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2279
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2280
      Label ok_array_klass, bad_array_klass, bad_array_length;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2281
      __ check_klass_subtype(rdx_array_klass, rbx_klass, rdi_temp, ok_array_klass);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2282
      // If we get here, the type check failed!
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2283
      __ jmp(bad_array_klass);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2284
      __ BIND(ok_array_klass);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2285
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2286
      // Check length.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2287
      if (length_constant >= 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2288
        __ cmpl(Address(rsi_array, length_offset), length_constant);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2289
      } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2290
        Register rbx_vminfo = rbx_temp;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2291
        load_conversion_vminfo(_masm, rbx_vminfo, rcx_amh_conversion);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2292
        __ cmpl(rbx_vminfo, Address(rsi_array, length_offset));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2293
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2294
      __ jcc(Assembler::notEqual, bad_array_length);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2295
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2296
      Register rdx_argslot_limit = rdx_temp;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2297
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2298
      // Array length checks out.  Now insert any required stack slots.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2299
      if (length_constant == -1) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2300
        // Form a pointer to the end of the affected region.
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5416
diff changeset
  2301
        __ lea(rdx_argslot_limit, Address(rax_argslot, Interpreter::stackElementSize));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2302
        // 'stack_move' is negative number of words to insert
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2303
        // This number already accounts for elem_slots.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2304
        Register rdi_stack_move = rdi_temp;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2305
        load_stack_move(_masm, rdi_stack_move, rcx_recv, true);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2306
        __ cmpptr(rdi_stack_move, 0);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2307
        assert(stack_move_unit() < 0, "else change this comparison");
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2308
        __ jcc(Assembler::less, L_insert_arg_space);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2309
        __ jcc(Assembler::equal, L_copy_args);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2310
        // single argument case, with no array movement
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2311
        __ BIND(L_array_is_empty);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2312
        remove_arg_slots(_masm, -stack_move_unit() * array_slots,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2313
                         rax_argslot, rbx_temp, rdx_temp);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2314
        __ jmp(L_args_done);  // no spreading to do
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2315
        __ BIND(L_insert_arg_space);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2316
        // come here in the usual case, stack_move < 0 (2 or more spread arguments)
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2317
        Register rsi_temp = rsi_array;  // spill this
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2318
        insert_arg_slots(_masm, rdi_stack_move,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2319
                         rax_argslot, rbx_temp, rsi_temp);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2320
        // reload the array since rsi was killed
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2321
        // reload from rdx_argslot_limit since rax_argslot is now decremented
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2322
        __ movptr(rsi_array, Address(rdx_argslot_limit, -Interpreter::stackElementSize));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2323
      } else if (length_constant >= 1) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2324
        int new_slots = (length_constant * elem_slots) - array_slots;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2325
        insert_arg_slots(_masm, new_slots * stack_move_unit(),
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2326
                         rax_argslot, rbx_temp, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2327
      } else if (length_constant == 0) {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2328
        __ BIND(L_array_is_empty);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2329
        remove_arg_slots(_masm, -stack_move_unit() * array_slots,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2330
                         rax_argslot, rbx_temp, rdx_temp);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2331
      } else {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2332
        ShouldNotReachHere();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2333
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2334
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2335
      // Copy from the array to the new slots.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2336
      // Note: Stack change code preserves integrity of rax_argslot pointer.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2337
      // So even after slot insertions, rax_argslot still points to first argument.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2338
      // Beware:  Arguments that are shallow on the stack are deep in the array,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2339
      // and vice versa.  So a downward-growing stack (the usual) has to be copied
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2340
      // elementwise in reverse order from the source array.
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2341
      __ BIND(L_copy_args);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2342
      if (length_constant == -1) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2343
        // [rax_argslot, rdx_argslot_limit) is the area we are inserting into.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2344
        // Array element [0] goes at rdx_argslot_limit[-wordSize].
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2345
        Register rsi_source = rsi_array;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2346
        __ lea(rsi_source, Address(rsi_array, elem0_offset));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2347
        Register rdx_fill_ptr = rdx_argslot_limit;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2348
        Label loop;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2349
        __ BIND(loop);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2350
        __ addptr(rdx_fill_ptr, -Interpreter::stackElementSize * elem_slots);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2351
        move_typed_arg(_masm, elem_type, true,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2352
                       Address(rdx_fill_ptr, 0), Address(rsi_source, 0),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2353
                       rbx_temp, rdi_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2354
        __ addptr(rsi_source, type2aelembytes(elem_type));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2355
        __ cmpptr(rdx_fill_ptr, rax_argslot);
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2356
        __ jcc(Assembler::greater, loop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2357
      } else if (length_constant == 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2358
        // nothing to copy
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2359
      } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2360
        int elem_offset = elem0_offset;
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2361
        int slot_offset = length_constant * Interpreter::stackElementSize;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2362
        for (int index = 0; index < length_constant; index++) {
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2363
          slot_offset -= Interpreter::stackElementSize * elem_slots;  // fill backward
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2364
          move_typed_arg(_masm, elem_type, true,
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2365
                         Address(rax_argslot, slot_offset), Address(rsi_array, elem_offset),
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2366
                         rbx_temp, rdi_temp);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2367
          elem_offset += type2aelembytes(elem_type);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2368
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2369
      }
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2370
      __ BIND(L_args_done);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2371
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2372
      // Arguments are spread.  Move to next method handle.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2373
      UNPUSH_RSI;
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6744
diff changeset
  2374
      __ load_heap_oop(rcx_recv, rcx_mh_vmtarget);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2375
      __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2376
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2377
      __ bind(bad_array_klass);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2378
      UNPUSH_RSI;
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  2379
      assert(!vmarg.uses(rarg2_required), "must be different registers");
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2380
      __ load_heap_oop( rarg2_required, Address(rdx_array_klass, java_mirror_offset));  // required type
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2381
      __ movptr(        rarg1_actual,   vmarg);                                         // bad array
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2382
      __ 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
  2383
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2384
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2385
      __ bind(bad_array_length);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2386
      UNPUSH_RSI;
7712
cee30a0f4315 7007377: JSR 292 MethodHandlesTest.testCastFailure fails on SPARC with -Xcomp +DeoptimizeALot
twisti
parents: 7397
diff changeset
  2387
      assert(!vmarg.uses(rarg2_required), "must be different registers");
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2388
      __ mov(    rarg2_required, rcx_recv);                       // AMH requiring a certain length
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2389
      __ movptr( rarg1_actual,   vmarg);                          // bad array
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2390
      __ 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
  2391
      __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2392
#undef UNPUSH_RSI
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2393
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2394
      break;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2395
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2396
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2397
  default:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2398
    // do not require all platforms to recognize all adapter types
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2399
    __ nop();
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9437
diff changeset
  2400
    return;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2401
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2402
  __ hlt();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2403
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2404
  address me_cookie = MethodHandleEntry::start_compiled_entry(_masm, interp_entry);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2405
  __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2406
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2407
  init_entry(ek, MethodHandleEntry::finish_compiled_entry(_masm, me_cookie));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  2408
}