hotspot/src/share/vm/prims/methodHandleWalk.cpp
author never
Thu, 13 Oct 2011 14:08:15 -0700
changeset 10735 67a139f9f954
parent 10514 e229a19078cf
child 13282 9872915dd78d
permissions -rw-r--r--
7100165: JSR 292: leftover printing code in methodHandleWalk.cpp Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     1
/*
7888
1be03febacc2 7010913: JSR 292 ciMethodHandle does not handle MethodHandleCompiler exceptions properly
twisti
parents: 7426
diff changeset
     2
 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     4
 *
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     8
 *
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    13
 * accompanied this code).
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    14
 *
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
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.
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    22
 *
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    23
 */
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6463
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6463
diff changeset
    26
#include "interpreter/rewriter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6463
diff changeset
    27
#include "memory/oopFactory.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6463
diff changeset
    28
#include "prims/methodHandleWalk.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6463
diff changeset
    29
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    30
/*
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    31
 * JSR 292 reference implementation: method handle structure analysis
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    32
 */
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    33
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
    34
#ifdef PRODUCT
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
    35
#define print_method_handle(mh) {}
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
    36
#else //PRODUCT
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
    37
extern "C" void print_method_handle(oop mh);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
    38
#endif //PRODUCT
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    39
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    40
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    41
// MethodHandleChain
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    42
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    43
void MethodHandleChain::set_method_handle(Handle mh, TRAPS) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    44
  if (!java_lang_invoke_MethodHandle::is_instance(mh()))  lose("bad method handle", CHECK);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    45
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    46
  // set current method handle and unpack partially
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    47
  _method_handle = mh;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    48
  _is_last       = false;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    49
  _is_bound      = false;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    50
  _arg_slot      = -1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    51
  _arg_type      = T_VOID;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    52
  _conversion    = -1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    53
  _last_invoke   = Bytecodes::_nop;  //arbitrary non-garbage
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    54
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    55
  if (java_lang_invoke_DirectMethodHandle::is_instance(mh())) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    56
    set_last_method(mh(), THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    57
    return;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    58
  }
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    59
  if (java_lang_invoke_AdapterMethodHandle::is_instance(mh())) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    60
    _conversion = AdapterMethodHandle_conversion();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    61
    assert(_conversion != -1, "bad conv value");
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    62
    assert(java_lang_invoke_BoundMethodHandle::is_instance(mh()), "also BMH");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    63
  }
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    64
  if (java_lang_invoke_BoundMethodHandle::is_instance(mh())) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    65
    if (!is_adapter())          // keep AMH and BMH separate in this model
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    66
      _is_bound = true;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    67
    _arg_slot = BoundMethodHandle_vmargslot();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    68
    oop target = MethodHandle_vmtarget_oop();
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    69
    if (!is_bound() || java_lang_invoke_MethodHandle::is_instance(target)) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    70
      _arg_type = compute_bound_arg_type(target, NULL, _arg_slot, CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    71
    } else if (target != NULL && target->is_method()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    72
      methodOop m = (methodOop) target;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    73
      _arg_type = compute_bound_arg_type(NULL, m, _arg_slot, CHECK);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    74
      set_last_method(mh(), CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    75
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    76
      _is_bound = false;  // lose!
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    77
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    78
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    79
  if (is_bound() && _arg_type == T_VOID) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    80
    lose("bad vmargslot", CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    81
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    82
  if (!is_bound() && !is_adapter()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    83
    lose("unrecognized MH type", CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    84
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    85
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    86
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    87
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    88
void MethodHandleChain::set_last_method(oop target, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    89
  _is_last = true;
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9116
diff changeset
    90
  KlassHandle receiver_limit; int flags = 0;
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9116
diff changeset
    91
  _last_method = MethodHandles::decode_method(target, receiver_limit, flags);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    92
  if ((flags & MethodHandles::_dmf_has_receiver) == 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    93
    _last_invoke = Bytecodes::_invokestatic;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    94
  else if ((flags & MethodHandles::_dmf_does_dispatch) == 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    95
    _last_invoke = Bytecodes::_invokespecial;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    96
  else if ((flags & MethodHandles::_dmf_from_interface) != 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    97
    _last_invoke = Bytecodes::_invokeinterface;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    98
  else
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    99
    _last_invoke = Bytecodes::_invokevirtual;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   100
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   101
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   102
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   103
BasicType MethodHandleChain::compute_bound_arg_type(oop target, methodOop m, int arg_slot, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   104
  // There is no direct indication of whether the argument is primitive or not.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   105
  // It is implied by the _vmentry code, and by the MethodType of the target.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   106
  BasicType arg_type = T_VOID;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   107
  if (target != NULL) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   108
    oop mtype = java_lang_invoke_MethodHandle::type(target);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   109
    int arg_num = MethodHandles::argument_slot_to_argnum(mtype, arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   110
    if (arg_num >= 0) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   111
      oop ptype = java_lang_invoke_MethodType::ptype(mtype, arg_num);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   112
      arg_type = java_lang_Class::as_BasicType(ptype);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   113
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   114
  } else if (m != NULL) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   115
    // figure out the argument type from the slot
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   116
    // FIXME: make this explicit in the MH
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   117
    int cur_slot = m->size_of_parameters();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   118
    if (arg_slot >= cur_slot)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   119
      return T_VOID;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   120
    if (!m->is_static()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   121
      cur_slot -= type2size[T_OBJECT];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   122
      if (cur_slot == arg_slot)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   123
        return T_OBJECT;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   124
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
   125
    ResourceMark rm(THREAD);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   126
    for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   127
      BasicType bt = ss.type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   128
      cur_slot -= type2size[bt];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   129
      if (cur_slot <= arg_slot) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   130
        if (cur_slot == arg_slot)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   131
          arg_type = bt;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   132
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   133
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   134
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   135
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   136
  if (arg_type == T_ARRAY)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   137
    arg_type = T_OBJECT;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   138
  return arg_type;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   139
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   140
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   141
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   142
void MethodHandleChain::lose(const char* msg, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   143
  _lose_message = msg;
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   144
#ifdef ASSERT
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   145
  if (Verbose) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   146
    tty->print_cr(INTPTR_FORMAT " lose: %s", _method_handle(), msg);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   147
    print();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   148
  }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   149
#endif
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   150
  if (!THREAD->is_Java_thread() || ((JavaThread*)THREAD)->thread_state() != _thread_in_vm) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   151
    // throw a preallocated exception
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   152
    THROW_OOP(Universe::virtual_machine_error_instance());
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   153
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   154
  THROW_MSG(vmSymbols::java_lang_InternalError(), msg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   155
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   156
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   157
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   158
#ifdef ASSERT
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   159
static const char* adapter_ops[] = {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   160
  "retype_only"  ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   161
  "retype_raw"   ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   162
  "check_cast"   ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   163
  "prim_to_prim" ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   164
  "ref_to_prim"  ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   165
  "prim_to_ref"  ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   166
  "swap_args"    ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   167
  "rot_args"     ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   168
  "dup_args"     ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   169
  "drop_args"    ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   170
  "collect_args" ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   171
  "spread_args"  ,
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   172
  "fold_args"
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   173
};
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   174
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   175
static const char* adapter_op_to_string(int op) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   176
  if (op >= 0 && op < (int)ARRAY_SIZE(adapter_ops))
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   177
    return adapter_ops[op];
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   178
  return "unknown_op";
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   179
}
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   180
9976
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
   181
void MethodHandleChain::print(oopDesc* m) {
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
   182
  HandleMark hm;
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
   183
  ResourceMark rm;
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
   184
  Handle mh(m);
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   185
  EXCEPTION_MARK;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   186
  MethodHandleChain mhc(mh, THREAD);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   187
  if (HAS_PENDING_EXCEPTION) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   188
    oop ex = THREAD->pending_exception();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   189
    CLEAR_PENDING_EXCEPTION;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   190
    ex->print();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   191
    return;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   192
  }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   193
  mhc.print();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   194
}
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   195
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   196
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   197
void MethodHandleChain::print() {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   198
  EXCEPTION_MARK;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   199
  print_impl(THREAD);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   200
  if (HAS_PENDING_EXCEPTION) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   201
    oop ex = THREAD->pending_exception();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   202
    CLEAR_PENDING_EXCEPTION;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   203
    ex->print();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   204
  }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   205
}
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   206
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   207
void MethodHandleChain::print_impl(TRAPS) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   208
  ResourceMark rm;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   209
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   210
  MethodHandleChain chain(_root, CHECK);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   211
  for (;;) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   212
    tty->print(INTPTR_FORMAT ": ", chain.method_handle()());
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   213
    if (chain.is_bound()) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   214
      tty->print("bound: arg_type %s arg_slot %d",
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   215
                 type2name(chain.bound_arg_type()),
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   216
                 chain.bound_arg_slot());
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   217
      oop o = chain.bound_arg_oop();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   218
      if (o != NULL) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   219
        if (o->is_instance()) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   220
          tty->print(" instance %s", o->klass()->klass_part()->internal_name());
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   221
          if (java_lang_invoke_CountingMethodHandle::is_instance(o)) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   222
            tty->print(" vmcount: %d", java_lang_invoke_CountingMethodHandle::vmcount(o));
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   223
          }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   224
        } else {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   225
          o->print();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   226
        }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   227
      }
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   228
      oop vmt = chain.vmtarget_oop();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   229
      if (vmt != NULL) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   230
        if (vmt->is_method()) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   231
          tty->print(" ");
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   232
          methodOop(vmt)->print_short_name(tty);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   233
        } else if (java_lang_invoke_MethodHandle::is_instance(vmt)) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   234
          tty->print(" method handle " INTPTR_FORMAT, vmt);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   235
        } else {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   236
          ShouldNotReachHere();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   237
        }
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   238
      }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   239
    } else if (chain.is_adapter()) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   240
      tty->print("adapter: arg_slot %d conversion op %s",
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   241
                 chain.adapter_arg_slot(),
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   242
                 adapter_op_to_string(chain.adapter_conversion_op()));
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   243
      switch (chain.adapter_conversion_op()) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   244
        case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY:
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   245
          if (java_lang_invoke_CountingMethodHandle::is_instance(chain.method_handle_oop())) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   246
            tty->print(" vmcount: %d", java_lang_invoke_CountingMethodHandle::vmcount(chain.method_handle_oop()));
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   247
          }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   248
        case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   249
        case java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   250
        case java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   251
        case java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   252
          break;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   253
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   254
        case java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF: {
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   255
          tty->print(" src_type = %s", type2name(chain.adapter_conversion_src_type()));
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   256
          break;
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   257
        }
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   258
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   259
        case java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   260
        case java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS: {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   261
          int dest_arg_slot = chain.adapter_conversion_vminfo();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   262
          tty->print(" dest_arg_slot %d type %s", dest_arg_slot, type2name(chain.adapter_conversion_src_type()));
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   263
          break;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   264
        }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   265
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   266
        case java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   267
        case java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS: {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   268
          int dup_slots = chain.adapter_conversion_stack_pushes();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   269
          tty->print(" pushes %d", dup_slots);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   270
          break;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   271
        }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   272
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   273
        case java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   274
        case java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS: {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   275
          int coll_slots = chain.MethodHandle_vmslots();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   276
          tty->print(" coll_slots %d", coll_slots);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   277
          break;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   278
        }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   279
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   280
        case java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS: {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   281
          // Check the required length.
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   282
          int spread_slots = 1 + chain.adapter_conversion_stack_pushes();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   283
          tty->print(" spread_slots %d", spread_slots);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   284
          break;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   285
        }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   286
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   287
        default:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   288
          tty->print_cr("bad adapter conversion");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   289
          break;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   290
      }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   291
    } else {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   292
      // DMH
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   293
      tty->print("direct: ");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   294
      chain.last_method_oop()->print_short_name(tty);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   295
    }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   296
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   297
    tty->print(" (");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   298
    objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(chain.method_type_oop());
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   299
    for (int i = ptypes->length() - 1; i >= 0; i--) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   300
      BasicType t = java_lang_Class::as_BasicType(ptypes->obj_at(i));
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   301
      if (t == T_ARRAY) t = T_OBJECT;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   302
      tty->print("%c", type2char(t));
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   303
      if (t == T_LONG || t == T_DOUBLE) tty->print("_");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   304
    }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   305
    tty->print(")");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   306
    BasicType rtype = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(chain.method_type_oop()));
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   307
    if (rtype == T_ARRAY) rtype = T_OBJECT;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   308
    tty->print("%c", type2char(rtype));
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   309
    tty->cr();
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   310
    if (!chain.is_last()) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   311
      chain.next(CHECK);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   312
    } else {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   313
      break;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   314
    }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   315
  }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   316
}
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   317
#endif
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   318
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   319
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   320
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   321
// MethodHandleWalker
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   322
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   323
Bytecodes::Code MethodHandleWalker::conversion_code(BasicType src, BasicType dest) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   324
  if (is_subword_type(src)) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   325
    src = T_INT;          // all subword src types act like int
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   326
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   327
  if (src == dest) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   328
    return Bytecodes::_nop;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   329
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   330
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   331
#define SRC_DEST(s,d) (((int)(s) << 4) + (int)(d))
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   332
  switch (SRC_DEST(src, dest)) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   333
  case SRC_DEST(T_INT, T_LONG):           return Bytecodes::_i2l;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   334
  case SRC_DEST(T_INT, T_FLOAT):          return Bytecodes::_i2f;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   335
  case SRC_DEST(T_INT, T_DOUBLE):         return Bytecodes::_i2d;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   336
  case SRC_DEST(T_INT, T_BYTE):           return Bytecodes::_i2b;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   337
  case SRC_DEST(T_INT, T_CHAR):           return Bytecodes::_i2c;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   338
  case SRC_DEST(T_INT, T_SHORT):          return Bytecodes::_i2s;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   339
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   340
  case SRC_DEST(T_LONG, T_INT):           return Bytecodes::_l2i;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   341
  case SRC_DEST(T_LONG, T_FLOAT):         return Bytecodes::_l2f;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   342
  case SRC_DEST(T_LONG, T_DOUBLE):        return Bytecodes::_l2d;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   343
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   344
  case SRC_DEST(T_FLOAT, T_INT):          return Bytecodes::_f2i;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   345
  case SRC_DEST(T_FLOAT, T_LONG):         return Bytecodes::_f2l;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   346
  case SRC_DEST(T_FLOAT, T_DOUBLE):       return Bytecodes::_f2d;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   347
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   348
  case SRC_DEST(T_DOUBLE, T_INT):         return Bytecodes::_d2i;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   349
  case SRC_DEST(T_DOUBLE, T_LONG):        return Bytecodes::_d2l;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   350
  case SRC_DEST(T_DOUBLE, T_FLOAT):       return Bytecodes::_d2f;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   351
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   352
#undef SRC_DEST
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   353
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   354
  // cannot do it in one step, or at all
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   355
  return Bytecodes::_illegal;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   356
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   357
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   358
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   359
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   360
// MethodHandleWalker::walk
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   361
//
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   362
MethodHandleWalker::ArgToken
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   363
MethodHandleWalker::walk(TRAPS) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   364
  ArgToken empty = ArgToken();  // Empty return value.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   365
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   366
  walk_incoming_state(CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   367
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   368
  for (;;) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   369
    set_method_handle(chain().method_handle_oop());
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   370
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   371
    assert(_outgoing_argc == argument_count_slow(), "empty slots under control");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   372
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   373
    if (chain().is_adapter()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   374
      int conv_op = chain().adapter_conversion_op();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   375
      int arg_slot = chain().adapter_arg_slot();
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   376
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   377
      // Check that the arg_slot is valid.  In most cases it must be
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   378
      // within range of the current arguments but there are some
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   379
      // exceptions.  Those are sanity checked in their implemention
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   380
      // below.
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   381
      if ((arg_slot < 0 || arg_slot >= _outgoing.length()) &&
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   382
          conv_op > java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW &&
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   383
          conv_op != java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS &&
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   384
          conv_op != java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   385
        lose(err_msg("bad argument index %d", arg_slot), CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   386
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   387
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   388
      bool retain_original_args = false;  // used by fold/collect logic
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   389
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   390
      // perform the adapter action
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   391
      switch (conv_op) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   392
      case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY:
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   393
        // No changes to arguments; pass the bits through.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   394
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   395
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   396
      case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW: {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   397
        // To keep the verifier happy, emit bitwise ("raw") conversions as needed.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   398
        // See MethodHandles::same_basic_type_for_arguments for allowed conversions.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   399
        Handle incoming_mtype(THREAD, chain().method_type_oop());
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   400
        Handle outgoing_mtype;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   401
        {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   402
          oop outgoing_mh_oop = chain().vmtarget_oop();
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   403
          if (!java_lang_invoke_MethodHandle::is_instance(outgoing_mh_oop))
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   404
            lose("outgoing target not a MethodHandle", CHECK_(empty));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   405
          outgoing_mtype = Handle(THREAD, java_lang_invoke_MethodHandle::type(outgoing_mh_oop));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   406
        }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   407
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   408
        int nptypes = java_lang_invoke_MethodType::ptype_count(outgoing_mtype());
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   409
        if (nptypes != java_lang_invoke_MethodType::ptype_count(incoming_mtype()))
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   410
          lose("incoming and outgoing parameter count do not agree", CHECK_(empty));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   411
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   412
        // Argument types.
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   413
        for (int i = 0, slot = _outgoing.length() - 1; slot >= 0; slot--) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   414
          if (arg_type(slot) == T_VOID)  continue;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   415
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   416
          klassOop  src_klass = NULL;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   417
          klassOop  dst_klass = NULL;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   418
          BasicType src = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::ptype(incoming_mtype(), i), &src_klass);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   419
          BasicType dst = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::ptype(outgoing_mtype(), i), &dst_klass);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   420
          retype_raw_argument_type(src, dst, slot, CHECK_(empty));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   421
          i++;  // We need to skip void slots at the top of the loop.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   422
        }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   423
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   424
        // Return type.
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   425
        {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   426
          BasicType src = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(incoming_mtype()));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   427
          BasicType dst = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(outgoing_mtype()));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   428
          retype_raw_return_type(src, dst, CHECK_(empty));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   429
        }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   430
        break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   431
      }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   432
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   433
      case java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   434
        // checkcast the Nth outgoing argument in place
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   435
        klassOop dest_klass = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   436
        BasicType dest = java_lang_Class::as_BasicType(chain().adapter_arg_oop(), &dest_klass);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   437
        assert(dest == T_OBJECT, "");
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   438
        ArgToken arg = _outgoing.at(arg_slot);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   439
        assert(dest == arg.basic_type(), "");
9976
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
   440
        arg = make_conversion(T_OBJECT, dest_klass, Bytecodes::_checkcast, arg, CHECK_(empty));
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   441
        // replace the object by the result of the cast, to make the compiler happy:
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   442
        change_argument(T_OBJECT, arg_slot, T_OBJECT, arg);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   443
        debug_only(dest_klass = (klassOop)badOop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   444
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   445
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   446
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   447
      case java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   448
        // i2l, etc., on the Nth outgoing argument in place
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   449
        BasicType src = chain().adapter_conversion_src_type(),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   450
                  dest = chain().adapter_conversion_dest_type();
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   451
        ArgToken arg = _outgoing.at(arg_slot);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   452
        Bytecodes::Code bc = conversion_code(src, dest);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   453
        if (bc == Bytecodes::_nop) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   454
          break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   455
        } else if (bc != Bytecodes::_illegal) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   456
          arg = make_conversion(dest, NULL, bc, arg, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   457
        } else if (is_subword_type(dest)) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   458
          bc = conversion_code(src, T_INT);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   459
          if (bc != Bytecodes::_illegal) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   460
            arg = make_conversion(dest, NULL, bc, arg, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   461
            bc = conversion_code(T_INT, dest);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   462
            arg = make_conversion(dest, NULL, bc, arg, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   463
          }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   464
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   465
        if (bc == Bytecodes::_illegal) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   466
          lose(err_msg("bad primitive conversion for %s -> %s", type2name(src), type2name(dest)), CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   467
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   468
        change_argument(src, arg_slot, dest, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   469
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   470
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   471
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   472
      case java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   473
        // checkcast to wrapper type & call intValue, etc.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   474
        BasicType dest = chain().adapter_conversion_dest_type();
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   475
        ArgToken arg = _outgoing.at(arg_slot);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   476
        arg = make_conversion(T_OBJECT, SystemDictionary::box_klass(dest),
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   477
                              Bytecodes::_checkcast, arg, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   478
        vmIntrinsics::ID unboxer = vmIntrinsics::for_unboxing(dest);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   479
        if (unboxer == vmIntrinsics::_none) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   480
          lose("no unboxing method", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   481
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   482
        ArgToken arglist[2];
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   483
        arglist[0] = arg;         // outgoing 'this'
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   484
        arglist[1] = ArgToken();  // sentinel
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   485
        arg = make_invoke(methodHandle(), unboxer, Bytecodes::_invokevirtual, false, 1, &arglist[0], CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   486
        change_argument(T_OBJECT, arg_slot, dest, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   487
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   488
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   489
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   490
      case java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   491
        // call wrapper type.valueOf
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   492
        BasicType src = chain().adapter_conversion_src_type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   493
        vmIntrinsics::ID boxer = vmIntrinsics::for_boxing(src);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   494
        if (boxer == vmIntrinsics::_none) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   495
          lose("no boxing method", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   496
        }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   497
        ArgToken arg = _outgoing.at(arg_slot);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   498
        ArgToken arglist[2];
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   499
        arglist[0] = arg;         // outgoing value
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   500
        arglist[1] = ArgToken();  // sentinel
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   501
        arg = make_invoke(methodHandle(), boxer, Bytecodes::_invokestatic, false, 1, &arglist[0], CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   502
        change_argument(src, arg_slot, T_OBJECT, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   503
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   504
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   505
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   506
      case java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   507
        int dest_arg_slot = chain().adapter_conversion_vminfo();
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   508
        if (!has_argument(dest_arg_slot)) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   509
          lose("bad swap index", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   510
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   511
        // a simple swap between two arguments
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   512
        if (arg_slot > dest_arg_slot) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   513
          int tmp = arg_slot;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   514
          arg_slot = dest_arg_slot;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   515
          dest_arg_slot = tmp;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   516
        }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   517
        ArgToken a1 = _outgoing.at(arg_slot);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   518
        ArgToken a2 = _outgoing.at(dest_arg_slot);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   519
        change_argument(a2.basic_type(), dest_arg_slot, a1);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   520
        change_argument(a1.basic_type(), arg_slot, a2);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   521
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   522
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   523
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   524
      case java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS: {
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   525
        int limit_raw  = chain().adapter_conversion_vminfo();
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   526
        bool rot_down  = (arg_slot < limit_raw);
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   527
        int limit_bias = (rot_down ? MethodHandles::OP_ROT_ARGS_DOWN_LIMIT_BIAS : 0);
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   528
        int limit_slot = limit_raw - limit_bias;
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   529
        if ((uint)limit_slot > (uint)_outgoing.length()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   530
          lose("bad rotate index", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   531
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   532
        // Rotate the source argument (plus following N slots) into the
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   533
        // position occupied by the dest argument (plus following N slots).
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   534
        int rotate_count = type2size[chain().adapter_conversion_src_type()];
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   535
        // (no other rotate counts are currently supported)
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   536
        if (rot_down) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   537
          for (int i = 0; i < rotate_count; i++) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   538
            ArgToken temp = _outgoing.at(arg_slot);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   539
            _outgoing.remove_at(arg_slot);
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   540
            _outgoing.insert_before(limit_slot - 1, temp);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   541
          }
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   542
        } else { // arg_slot > limit_slot => rotate_up
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   543
          for (int i = 0; i < rotate_count; i++) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   544
            ArgToken temp = _outgoing.at(arg_slot + rotate_count - 1);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   545
            _outgoing.remove_at(arg_slot + rotate_count - 1);
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
   546
            _outgoing.insert_before(limit_slot, temp);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   547
          }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   548
        }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   549
        assert(_outgoing_argc == argument_count_slow(), "empty slots under control");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   550
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   551
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   552
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   553
      case java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   554
        int dup_slots = chain().adapter_conversion_stack_pushes();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   555
        if (dup_slots <= 0) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   556
          lose("bad dup count", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   557
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   558
        for (int i = 0; i < dup_slots; i++) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   559
          ArgToken dup = _outgoing.at(arg_slot + 2*i);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   560
          if (dup.basic_type() != T_VOID)     _outgoing_argc += 1;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   561
          _outgoing.insert_before(i, dup);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   562
        }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   563
        assert(_outgoing_argc == argument_count_slow(), "empty slots under control");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   564
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   565
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   566
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   567
      case java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   568
        int drop_slots = -chain().adapter_conversion_stack_pushes();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   569
        if (drop_slots <= 0) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   570
          lose("bad drop count", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   571
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   572
        for (int i = 0; i < drop_slots; i++) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   573
          ArgToken drop = _outgoing.at(arg_slot);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   574
          if (drop.basic_type() != T_VOID)    _outgoing_argc -= 1;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   575
          _outgoing.remove_at(arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   576
        }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   577
        assert(_outgoing_argc == argument_count_slow(), "empty slots under control");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   578
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   579
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   580
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   581
      case java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS:
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   582
        retain_original_args = true;   // and fall through:
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   583
      case java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS: {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   584
        // call argument MH recursively
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   585
        //{static int x; if (!x++) print_method_handle(chain().method_handle_oop()); --x;}
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   586
        Handle recursive_mh(THREAD, chain().adapter_arg_oop());
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   587
        if (!java_lang_invoke_MethodHandle::is_instance(recursive_mh())) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   588
          lose("recursive target not a MethodHandle", CHECK_(empty));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   589
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   590
        Handle recursive_mtype(THREAD, java_lang_invoke_MethodHandle::type(recursive_mh()));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   591
        int argc = java_lang_invoke_MethodType::ptype_count(recursive_mtype());
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   592
        int coll_slots = java_lang_invoke_MethodHandle::vmslots(recursive_mh());
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   593
        BasicType rtype = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(recursive_mtype()));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   594
        ArgToken* arglist = NEW_RESOURCE_ARRAY(ArgToken, 1 + argc + 1);  // 1+: mh, +1: sentinel
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   595
        arglist[0] = make_oop_constant(recursive_mh(), CHECK_(empty));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   596
        if (arg_slot < 0 || coll_slots < 0 || arg_slot + coll_slots > _outgoing.length()) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   597
          lose("bad fold/collect arg slot", CHECK_(empty));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   598
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   599
        for (int i = 0, slot = arg_slot + coll_slots - 1; slot >= arg_slot; slot--) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   600
          ArgToken arg_state = _outgoing.at(slot);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   601
          BasicType  arg_type  = arg_state.basic_type();
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   602
          if (arg_type == T_VOID)  continue;
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   603
          ArgToken arg = _outgoing.at(slot);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   604
          if (i >= argc) { lose("bad fold/collect arg", CHECK_(empty)); }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   605
          arglist[1+i] = arg;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   606
          if (!retain_original_args)
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   607
            change_argument(arg_type, slot, T_VOID, ArgToken(tt_void));
9943
a9aea2b8010f 7045515: ARM assembly code for JSR 292 ricochet frames
bdelsart
parents: 9638
diff changeset
   608
          i++;
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   609
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   610
        arglist[1+argc] = ArgToken();  // sentinel
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   611
        oop invoker = java_lang_invoke_MethodTypeForm::vmlayout(
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   612
                          java_lang_invoke_MethodType::form(recursive_mtype()) );
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   613
        if (invoker == NULL || !invoker->is_method()) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   614
          lose("bad vmlayout slot", CHECK_(empty));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   615
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   616
        // FIXME: consider inlining the invokee at the bytecode level
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   617
        ArgToken ret = make_invoke(methodHandle(THREAD, methodOop(invoker)), vmIntrinsics::_invokeGeneric,
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   618
                                   Bytecodes::_invokevirtual, false, 1+argc, &arglist[0], CHECK_(empty));
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   619
        // The iid = _invokeGeneric really means to adjust reference types as needed.
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   620
        DEBUG_ONLY(invoker = NULL);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   621
        if (rtype == T_OBJECT) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   622
          klassOop rklass = java_lang_Class::as_klassOop( java_lang_invoke_MethodType::rtype(recursive_mtype()) );
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   623
          if (rklass != SystemDictionary::Object_klass() &&
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   624
              !Klass::cast(rklass)->is_interface()) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   625
            // preserve type safety
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   626
            ret = make_conversion(T_OBJECT, rklass, Bytecodes::_checkcast, ret, CHECK_(empty));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   627
          }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   628
        }
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   629
        if (rtype != T_VOID) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   630
          int ret_slot = arg_slot + (retain_original_args ? coll_slots : 0);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   631
          change_argument(T_VOID, ret_slot, rtype, ret);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   632
        }
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   633
        break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   634
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   635
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   636
      case java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   637
        klassOop array_klass_oop = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   638
        BasicType array_type = java_lang_Class::as_BasicType(chain().adapter_arg_oop(),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   639
                                                             &array_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   640
        assert(array_type == T_OBJECT, "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   641
        assert(Klass::cast(array_klass_oop)->oop_is_array(), "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   642
        arrayKlassHandle array_klass(THREAD, array_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   643
        debug_only(array_klass_oop = (klassOop)badOop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   644
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   645
        klassOop element_klass_oop = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   646
        BasicType element_type = java_lang_Class::as_BasicType(array_klass->component_mirror(),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   647
                                                               &element_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   648
        KlassHandle element_klass(THREAD, element_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   649
        debug_only(element_klass_oop = (klassOop)badOop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   650
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   651
        // Fetch the argument, which we will cast to the required array type.
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   652
        ArgToken arg = _outgoing.at(arg_slot);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   653
        assert(arg.basic_type() == T_OBJECT, "");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   654
        ArgToken array_arg = arg;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   655
        array_arg = make_conversion(T_OBJECT, array_klass(), Bytecodes::_checkcast, array_arg, CHECK_(empty));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   656
        change_argument(T_OBJECT, arg_slot, T_VOID, ArgToken(tt_void));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   657
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   658
        // Check the required length.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   659
        int spread_slots = 1 + chain().adapter_conversion_stack_pushes();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   660
        int spread_length = spread_slots;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   661
        if (type2size[element_type] == 2) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   662
          if (spread_slots % 2 != 0)  spread_slots = -1;  // force error
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   663
          spread_length = spread_slots / 2;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   664
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   665
        if (spread_slots < 0) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   666
          lose("bad spread length", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   667
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   668
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   669
        jvalue   length_jvalue;  length_jvalue.i = spread_length;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   670
        ArgToken length_arg = make_prim_constant(T_INT, &length_jvalue, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   671
        // Call a built-in method known to the JVM to validate the length.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   672
        ArgToken arglist[3];
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   673
        arglist[0] = array_arg;   // value to check
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   674
        arglist[1] = length_arg;  // length to check
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   675
        arglist[2] = ArgToken();  // sentinel
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   676
        make_invoke(methodHandle(), vmIntrinsics::_checkSpreadArgument,
9943
a9aea2b8010f 7045515: ARM assembly code for JSR 292 ricochet frames
bdelsart
parents: 9638
diff changeset
   677
                    Bytecodes::_invokestatic, false, 2, &arglist[0], CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   678
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   679
        // Spread out the array elements.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   680
        Bytecodes::Code aload_op = Bytecodes::_nop;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   681
        switch (element_type) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   682
        case T_INT:       aload_op = Bytecodes::_iaload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   683
        case T_LONG:      aload_op = Bytecodes::_laload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   684
        case T_FLOAT:     aload_op = Bytecodes::_faload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   685
        case T_DOUBLE:    aload_op = Bytecodes::_daload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   686
        case T_OBJECT:    aload_op = Bytecodes::_aaload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   687
        case T_BOOLEAN:   // fall through:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   688
        case T_BYTE:      aload_op = Bytecodes::_baload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   689
        case T_CHAR:      aload_op = Bytecodes::_caload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   690
        case T_SHORT:     aload_op = Bytecodes::_saload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   691
        default:          lose("primitive array NYI", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   692
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   693
        int ap = arg_slot;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   694
        for (int i = 0; i < spread_length; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   695
          jvalue   offset_jvalue;  offset_jvalue.i = i;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   696
          ArgToken offset_arg = make_prim_constant(T_INT, &offset_jvalue, CHECK_(empty));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   697
          ArgToken element_arg = make_fetch(element_type, element_klass(), aload_op, array_arg, offset_arg, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   698
          change_argument(T_VOID, ap, element_type, element_arg);
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   699
          //ap += type2size[element_type];  // don't do this; insert next arg to *right* of previous
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   700
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   701
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   702
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   703
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   704
      default:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   705
        lose("bad adapter conversion", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   706
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   707
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   708
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   709
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   710
    if (chain().is_bound()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   711
      // push a new argument
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   712
      BasicType arg_type  = chain().bound_arg_type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   713
      jint      arg_slot  = chain().bound_arg_slot();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   714
      oop       arg_oop   = chain().bound_arg_oop();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   715
      ArgToken  arg;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   716
      if (arg_type == T_OBJECT) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   717
        arg = make_oop_constant(arg_oop, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   718
      } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   719
        jvalue arg_value;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   720
        BasicType bt = java_lang_boxing_object::get_value(arg_oop, &arg_value);
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   721
        if (bt == arg_type || (bt == T_INT && is_subword_type(arg_type))) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   722
          arg = make_prim_constant(arg_type, &arg_value, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   723
        } else {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   724
          lose(err_msg("bad bound value: arg_type %s boxing %s", type2name(arg_type), type2name(bt)), CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   725
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   726
      }
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   727
      DEBUG_ONLY(arg_oop = badOop);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   728
      change_argument(T_VOID, arg_slot, arg_type, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   729
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   730
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   731
    // this test must come after the body of the loop
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   732
    if (!chain().is_last()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   733
      chain().next(CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   734
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   735
      break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   736
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   737
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   738
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   739
  // finish the sequence with a tail-call to the ultimate target
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   740
  // parameters are passed in logical order (recv 1st), not slot order
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   741
  ArgToken* arglist = NEW_RESOURCE_ARRAY(ArgToken, _outgoing.length() + 1);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   742
  int ap = 0;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   743
  for (int i = _outgoing.length() - 1; i >= 0; i--) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   744
    ArgToken arg_state = _outgoing.at(i);
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   745
    if (arg_state.basic_type() == T_VOID)  continue;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   746
    arglist[ap++] = _outgoing.at(i);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   747
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   748
  assert(ap == _outgoing_argc, "");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   749
  arglist[ap] = ArgToken();  // add a sentinel, for the sake of asserts
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   750
  return make_invoke(chain().last_method(),
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   751
                     vmIntrinsics::_none,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   752
                     chain().last_invoke_code(), true,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   753
                     ap, arglist, THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   754
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   755
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   756
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   757
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   758
// MethodHandleWalker::walk_incoming_state
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   759
//
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   760
void MethodHandleWalker::walk_incoming_state(TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   761
  Handle mtype(THREAD, chain().method_type_oop());
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   762
  int nptypes = java_lang_invoke_MethodType::ptype_count(mtype());
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   763
  _outgoing_argc = nptypes;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   764
  int argp = nptypes - 1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   765
  if (argp >= 0) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   766
    _outgoing.at_grow(argp, ArgToken(tt_void)); // presize
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   767
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   768
  for (int i = 0; i < nptypes; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   769
    klassOop  arg_type_klass = NULL;
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   770
    BasicType arg_type = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::ptype(mtype(), i), &arg_type_klass);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   771
    int index = new_local_index(arg_type);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   772
    ArgToken arg = make_parameter(arg_type, arg_type_klass, index, CHECK);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   773
    DEBUG_ONLY(arg_type_klass = (klassOop) NULL);
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   774
    _outgoing.at_put(argp, arg);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   775
    if (type2size[arg_type] == 2) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   776
      // add the extra slot, so we can model the JVM stack
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   777
      _outgoing.insert_before(argp+1, ArgToken(tt_void));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   778
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   779
    --argp;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   780
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   781
  // call make_parameter at the end of the list for the return type
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   782
  klassOop  ret_type_klass = NULL;
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   783
  BasicType ret_type = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(mtype()), &ret_type_klass);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   784
  ArgToken  ret = make_parameter(ret_type, ret_type_klass, -1, CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   785
  // ignore ret; client can catch it if needed
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   786
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   787
  assert(_outgoing_argc == argument_count_slow(), "empty slots under control");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   788
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   789
  verify_args_and_signature(CHECK);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   790
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   791
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   792
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   793
#ifdef ASSERT
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   794
void MethodHandleWalker::verify_args_and_signature(TRAPS) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   795
  int index = _outgoing.length() - 1;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   796
  objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(chain().method_type_oop());
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   797
  for (int i = 0, limit = ptypes->length(); i < limit; i++) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   798
    BasicType t = java_lang_Class::as_BasicType(ptypes->obj_at(i));
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   799
    if (t == T_ARRAY) t = T_OBJECT;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   800
    if (t == T_LONG || t == T_DOUBLE) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   801
      assert(T_VOID == _outgoing.at(index).basic_type(), "types must match");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   802
      index--;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   803
    }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   804
    assert(t == _outgoing.at(index).basic_type(), "types must match");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   805
    index--;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   806
  }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   807
}
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   808
#endif
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   809
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   810
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   811
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   812
// MethodHandleWalker::change_argument
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   813
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   814
// This is messy because some kinds of arguments are paired with
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   815
// companion slots containing an empty value.
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   816
void MethodHandleWalker::change_argument(BasicType old_type, int slot, const ArgToken& new_arg) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   817
  BasicType new_type = new_arg.basic_type();
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   818
  int old_size = type2size[old_type];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   819
  int new_size = type2size[new_type];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   820
  if (old_size == new_size) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   821
    // simple case first
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   822
    _outgoing.at_put(slot, new_arg);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   823
  } else if (old_size > new_size) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   824
    for (int i = old_size - 1; i >= new_size; i--) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   825
      assert((i != 0) == (_outgoing.at(slot + i).basic_type() == T_VOID), "");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   826
      _outgoing.remove_at(slot + i);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   827
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   828
    if (new_size > 0)
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   829
      _outgoing.at_put(slot, new_arg);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   830
    else
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   831
      _outgoing_argc -= 1;      // deleted a real argument
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   832
  } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   833
    for (int i = old_size; i < new_size; i++) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   834
      _outgoing.insert_before(slot + i, ArgToken(tt_void));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   835
    }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   836
    _outgoing.at_put(slot, new_arg);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   837
    if (old_size == 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   838
      _outgoing_argc += 1;      // inserted a real argument
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   839
  }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   840
  assert(_outgoing_argc == argument_count_slow(), "empty slots under control");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   841
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   842
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   843
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   844
#ifdef ASSERT
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   845
int MethodHandleWalker::argument_count_slow() {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   846
  int args_seen = 0;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   847
  for (int i = _outgoing.length() - 1; i >= 0; i--) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   848
    if (_outgoing.at(i).basic_type() != T_VOID) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   849
      ++args_seen;
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   850
      if (_outgoing.at(i).basic_type() == T_LONG ||
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   851
          _outgoing.at(i).basic_type() == T_DOUBLE) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   852
        assert(_outgoing.at(i + 1).basic_type() == T_VOID, "should only follow two word");
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   853
      }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   854
    } else {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   855
      assert(_outgoing.at(i - 1).basic_type() == T_LONG ||
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   856
             _outgoing.at(i - 1).basic_type() == T_DOUBLE, "should only follow two word");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   857
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   858
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   859
  return args_seen;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   860
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   861
#endif
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   862
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   863
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   864
// -----------------------------------------------------------------------------
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   865
// MethodHandleWalker::retype_raw_conversion
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   866
//
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   867
// Do the raw retype conversions for OP_RETYPE_RAW.
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   868
void MethodHandleWalker::retype_raw_conversion(BasicType src, BasicType dst, bool for_return, int slot, TRAPS) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   869
  if (src != dst) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   870
    if (MethodHandles::same_basic_type_for_returns(src, dst, /*raw*/ true)) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   871
      if (MethodHandles::is_float_fixed_reinterpretation_cast(src, dst)) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   872
        vmIntrinsics::ID iid = vmIntrinsics::for_raw_conversion(src, dst);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   873
        if (iid == vmIntrinsics::_none) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   874
          lose("no raw conversion method", CHECK);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   875
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   876
        ArgToken arglist[2];
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   877
        if (!for_return) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   878
          // argument type conversion
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   879
          ArgToken arg = _outgoing.at(slot);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   880
          assert(arg.token_type() >= tt_symbolic || src == arg.basic_type(), "sanity");
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   881
          arglist[0] = arg;         // outgoing 'this'
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   882
          arglist[1] = ArgToken();  // sentinel
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   883
          arg = make_invoke(methodHandle(), iid, Bytecodes::_invokestatic, false, 1, &arglist[0], CHECK);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   884
          change_argument(src, slot, dst, arg);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   885
        } else {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   886
          // return type conversion
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   887
          if (_return_conv == vmIntrinsics::_none) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   888
            _return_conv = iid;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   889
          } else if (_return_conv == vmIntrinsics::for_raw_conversion(dst, src)) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   890
            _return_conv = vmIntrinsics::_none;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   891
          } else if (_return_conv != zero_return_conv()) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   892
            lose(err_msg("requested raw return conversion not allowed: %s -> %s (before %s)", type2name(src), type2name(dst), vmIntrinsics::name_at(_return_conv)), CHECK);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   893
          }
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   894
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   895
      } else {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   896
        // Nothing to do.
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   897
      }
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   898
    } else if (for_return && (!is_subword_type(src) || !is_subword_type(dst))) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   899
      // This can occur in exception-throwing MHs, which have a fictitious return value encoded as Void or Empty.
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   900
      _return_conv = zero_return_conv();
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   901
    } else if (src == T_OBJECT && is_java_primitive(dst)) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   902
      // ref-to-prim: discard ref, push zero
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   903
      lose("requested ref-to-prim conversion not expected", CHECK);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   904
    } else {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
   905
      lose(err_msg("requested raw conversion not allowed: %s -> %s", type2name(src), type2name(dst)), CHECK);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   906
    }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   907
  }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   908
}
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   909
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   910
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
   911
// -----------------------------------------------------------------------------
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   912
// MethodHandleCompiler
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   913
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   914
MethodHandleCompiler::MethodHandleCompiler(Handle root, Symbol* name, Symbol* signature, int invoke_count, bool is_invokedynamic, TRAPS)
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   915
  : MethodHandleWalker(root, is_invokedynamic, THREAD),
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
   916
    _invoke_count(invoke_count),
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   917
    _thread(THREAD),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   918
    _bytecode(THREAD, 50),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   919
    _constants(THREAD, 10),
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   920
    _non_bcp_klasses(THREAD, 5),
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   921
    _cur_stack(0),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   922
    _max_stack(0),
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   923
    _rtype(T_ILLEGAL),
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   924
    _selectAlternative_bci(-1),
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   925
    _taken_count(0),
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
   926
    _not_taken_count(0)
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   927
{
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   928
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   929
  // Element zero is always the null constant.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   930
  (void) _constants.append(NULL);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   931
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   932
  // Set name and signature index.
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   933
  _name_index      = cpool_symbol_put(name);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   934
  _signature_index = cpool_symbol_put(signature);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   935
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   936
  // To make the resulting methods more recognizable by
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   937
  // stack walkers and compiler heuristics,
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   938
  // we put them in holder class MethodHandle.
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   939
  // See klass_is_method_handle_adapter_holder
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   940
  // and methodOopDesc::is_method_handle_adapter.
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   941
  _target_klass = SystemDictionaryHandles::MethodHandle_klass();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   942
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   943
  check_non_bcp_klasses(java_lang_invoke_MethodHandle::type(root()), CHECK);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   944
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   945
  // Get return type klass.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   946
  Handle first_mtype(THREAD, chain().method_type_oop());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   947
  // _rklass is NULL for primitives.
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   948
  _rtype = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(first_mtype()), &_rklass);
4581
e89fbd1bcb3d 6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents: 4571
diff changeset
   949
  if (_rtype == T_ARRAY)  _rtype = T_OBJECT;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   950
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   951
  ArgumentSizeComputer args(signature);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   952
  int params = args.size() + 1;  // Incoming arguments plus receiver.
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   953
  _num_params = for_invokedynamic() ? params - 1 : params;  // XXX Check if callee is static?
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   954
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   955
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   956
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   957
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   958
// MethodHandleCompiler::compile
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   959
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   960
// Compile this MethodHandle into a bytecode adapter and return a
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   961
// methodOop.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   962
methodHandle MethodHandleCompiler::compile(TRAPS) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   963
  assert(_thread == THREAD, "must be same thread");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   964
  methodHandle nullHandle;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   965
  (void) walk(CHECK_(nullHandle));
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
   966
  record_non_bcp_klasses();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   967
  return get_method_oop(CHECK_(nullHandle));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   968
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   969
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   970
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
   971
void MethodHandleCompiler::emit_bc(Bytecodes::Code op, int index, int args_size) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   972
  Bytecodes::check(op);  // Are we legal?
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   973
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   974
  switch (op) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   975
  // b
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   976
  case Bytecodes::_aconst_null:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   977
  case Bytecodes::_iconst_m1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   978
  case Bytecodes::_iconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   979
  case Bytecodes::_iconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   980
  case Bytecodes::_iconst_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   981
  case Bytecodes::_iconst_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   982
  case Bytecodes::_iconst_4:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   983
  case Bytecodes::_iconst_5:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   984
  case Bytecodes::_lconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   985
  case Bytecodes::_lconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   986
  case Bytecodes::_fconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   987
  case Bytecodes::_fconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   988
  case Bytecodes::_fconst_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   989
  case Bytecodes::_dconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   990
  case Bytecodes::_dconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   991
  case Bytecodes::_iload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   992
  case Bytecodes::_iload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   993
  case Bytecodes::_iload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   994
  case Bytecodes::_iload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   995
  case Bytecodes::_lload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   996
  case Bytecodes::_lload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   997
  case Bytecodes::_lload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   998
  case Bytecodes::_lload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   999
  case Bytecodes::_fload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1000
  case Bytecodes::_fload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1001
  case Bytecodes::_fload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1002
  case Bytecodes::_fload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1003
  case Bytecodes::_dload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1004
  case Bytecodes::_dload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1005
  case Bytecodes::_dload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1006
  case Bytecodes::_dload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1007
  case Bytecodes::_aload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1008
  case Bytecodes::_aload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1009
  case Bytecodes::_aload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1010
  case Bytecodes::_aload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1011
  case Bytecodes::_istore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1012
  case Bytecodes::_istore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1013
  case Bytecodes::_istore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1014
  case Bytecodes::_istore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1015
  case Bytecodes::_lstore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1016
  case Bytecodes::_lstore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1017
  case Bytecodes::_lstore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1018
  case Bytecodes::_lstore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1019
  case Bytecodes::_fstore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1020
  case Bytecodes::_fstore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1021
  case Bytecodes::_fstore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1022
  case Bytecodes::_fstore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1023
  case Bytecodes::_dstore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1024
  case Bytecodes::_dstore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1025
  case Bytecodes::_dstore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1026
  case Bytecodes::_dstore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1027
  case Bytecodes::_astore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1028
  case Bytecodes::_astore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1029
  case Bytecodes::_astore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1030
  case Bytecodes::_astore_3:
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1031
  case Bytecodes::_iand:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1032
  case Bytecodes::_i2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1033
  case Bytecodes::_i2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1034
  case Bytecodes::_i2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1035
  case Bytecodes::_i2b:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1036
  case Bytecodes::_i2c:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1037
  case Bytecodes::_i2s:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1038
  case Bytecodes::_l2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1039
  case Bytecodes::_l2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1040
  case Bytecodes::_l2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1041
  case Bytecodes::_f2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1042
  case Bytecodes::_f2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1043
  case Bytecodes::_f2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1044
  case Bytecodes::_d2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1045
  case Bytecodes::_d2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1046
  case Bytecodes::_d2f:
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1047
  case Bytecodes::_iaload:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1048
  case Bytecodes::_laload:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1049
  case Bytecodes::_faload:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1050
  case Bytecodes::_daload:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1051
  case Bytecodes::_aaload:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1052
  case Bytecodes::_baload:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1053
  case Bytecodes::_caload:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1054
  case Bytecodes::_saload:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1055
  case Bytecodes::_ireturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1056
  case Bytecodes::_lreturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1057
  case Bytecodes::_freturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1058
  case Bytecodes::_dreturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1059
  case Bytecodes::_areturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1060
  case Bytecodes::_return:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
  1061
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_b, "wrong bytecode format");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1062
    _bytecode.push(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1063
    break;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1064
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1065
  // bi
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1066
  case Bytecodes::_ldc:
6064
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
  1067
    assert(Bytecodes::format_bits(op, false) == (Bytecodes::_fmt_b|Bytecodes::_fmt_has_k), "wrong bytecode format");
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1068
    if (index == (index & 0xff)) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1069
      _bytecode.push(op);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1070
      _bytecode.push(index);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1071
    } else {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1072
      _bytecode.push(Bytecodes::_ldc_w);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1073
      _bytecode.push(index >> 8);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1074
      _bytecode.push(index);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1075
    }
6064
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
  1076
    break;
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
  1077
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1078
  case Bytecodes::_iload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1079
  case Bytecodes::_lload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1080
  case Bytecodes::_fload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1081
  case Bytecodes::_dload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1082
  case Bytecodes::_aload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1083
  case Bytecodes::_istore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1084
  case Bytecodes::_lstore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1085
  case Bytecodes::_fstore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1086
  case Bytecodes::_dstore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1087
  case Bytecodes::_astore:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
  1088
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_bi, "wrong bytecode format");
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1089
    if (index == (index & 0xff)) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1090
      _bytecode.push(op);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1091
      _bytecode.push(index);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1092
    } else {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1093
      // doesn't fit in a u2
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1094
      _bytecode.push(Bytecodes::_wide);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1095
      _bytecode.push(op);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1096
      _bytecode.push(index >> 8);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1097
      _bytecode.push(index);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1098
    }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1099
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1100
6064
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
  1101
  // bkk
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
  1102
  case Bytecodes::_ldc_w:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1103
  case Bytecodes::_ldc2_w:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1104
  case Bytecodes::_checkcast:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
  1105
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_bkk, "wrong bytecode format");
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1106
    assert((unsigned short) index == index, "index does not fit in 16-bit");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1107
    _bytecode.push(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1108
    _bytecode.push(index >> 8);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1109
    _bytecode.push(index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1110
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1111
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
  1112
  // bJJ
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1113
  case Bytecodes::_invokestatic:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1114
  case Bytecodes::_invokespecial:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1115
  case Bytecodes::_invokevirtual:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
  1116
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_bJJ, "wrong bytecode format");
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1117
    assert((unsigned short) index == index, "index does not fit in 16-bit");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1118
    _bytecode.push(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1119
    _bytecode.push(index >> 8);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1120
    _bytecode.push(index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1121
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1122
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1123
  case Bytecodes::_invokeinterface:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1124
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_bJJ, "wrong bytecode format");
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1125
    assert((unsigned short) index == index, "index does not fit in 16-bit");
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1126
    assert(args_size > 0, "valid args_size");
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1127
    _bytecode.push(op);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1128
    _bytecode.push(index >> 8);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1129
    _bytecode.push(index);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1130
    _bytecode.push(args_size);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1131
    _bytecode.push(0);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1132
    break;
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1133
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1134
  case Bytecodes::_ifeq:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1135
    assert((unsigned short) index == index, "index does not fit in 16-bit");
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1136
    _bytecode.push(op);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1137
    _bytecode.push(index >> 8);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1138
    _bytecode.push(index);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1139
    break;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1140
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1141
  default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1142
    ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1143
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1144
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1145
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1146
void MethodHandleCompiler::update_branch_dest(int src, int dst) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1147
  switch (_bytecode.at(src)) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1148
    case Bytecodes::_ifeq:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1149
      dst -= src; // compute the offset
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1150
      assert((unsigned short) dst == dst, "index does not fit in 16-bit");
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1151
      _bytecode.at_put(src + 1, dst >> 8);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1152
      _bytecode.at_put(src + 2, dst);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1153
      break;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1154
    default:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1155
      ShouldNotReachHere();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1156
  }
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1157
}
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1158
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1159
void MethodHandleCompiler::emit_load(ArgToken arg) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1160
  TokenType tt = arg.token_type();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1161
  BasicType bt = arg.basic_type();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1162
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1163
  switch (tt) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1164
    case tt_parameter:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1165
    case tt_temporary:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1166
      emit_load(bt, arg.index());
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1167
      break;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1168
    case tt_constant:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1169
      emit_load_constant(arg);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1170
      break;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1171
    case tt_illegal:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1172
    case tt_void:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1173
    default:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1174
      ShouldNotReachHere();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1175
  }
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1176
}
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1177
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1178
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1179
void MethodHandleCompiler::emit_load(BasicType bt, int index) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1180
  if (index <= 3) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1181
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1182
    case T_BOOLEAN: case T_BYTE: case T_CHAR: case T_SHORT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1183
    case T_INT:    emit_bc(Bytecodes::cast(Bytecodes::_iload_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1184
    case T_LONG:   emit_bc(Bytecodes::cast(Bytecodes::_lload_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1185
    case T_FLOAT:  emit_bc(Bytecodes::cast(Bytecodes::_fload_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1186
    case T_DOUBLE: emit_bc(Bytecodes::cast(Bytecodes::_dload_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1187
    case T_OBJECT: emit_bc(Bytecodes::cast(Bytecodes::_aload_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1188
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1189
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1190
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1191
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1192
  else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1193
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1194
    case T_BOOLEAN: case T_BYTE: case T_CHAR: case T_SHORT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1195
    case T_INT:    emit_bc(Bytecodes::_iload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1196
    case T_LONG:   emit_bc(Bytecodes::_lload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1197
    case T_FLOAT:  emit_bc(Bytecodes::_fload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1198
    case T_DOUBLE: emit_bc(Bytecodes::_dload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1199
    case T_OBJECT: emit_bc(Bytecodes::_aload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1200
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1201
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1202
    }
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1203
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1204
  stack_push(bt);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1205
}
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1206
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1207
void MethodHandleCompiler::emit_store(BasicType bt, int index) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1208
  if (index <= 3) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1209
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1210
    case T_BOOLEAN: case T_BYTE: case T_CHAR: case T_SHORT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1211
    case T_INT:    emit_bc(Bytecodes::cast(Bytecodes::_istore_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1212
    case T_LONG:   emit_bc(Bytecodes::cast(Bytecodes::_lstore_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1213
    case T_FLOAT:  emit_bc(Bytecodes::cast(Bytecodes::_fstore_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1214
    case T_DOUBLE: emit_bc(Bytecodes::cast(Bytecodes::_dstore_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1215
    case T_OBJECT: emit_bc(Bytecodes::cast(Bytecodes::_astore_0 + index)); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1216
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1217
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1218
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1219
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1220
  else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1221
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1222
    case T_BOOLEAN: case T_BYTE: case T_CHAR: case T_SHORT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1223
    case T_INT:    emit_bc(Bytecodes::_istore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1224
    case T_LONG:   emit_bc(Bytecodes::_lstore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1225
    case T_FLOAT:  emit_bc(Bytecodes::_fstore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1226
    case T_DOUBLE: emit_bc(Bytecodes::_dstore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1227
    case T_OBJECT: emit_bc(Bytecodes::_astore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1228
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1229
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1230
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1231
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1232
  stack_pop(bt);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1233
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1234
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1235
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1236
void MethodHandleCompiler::emit_load_constant(ArgToken arg) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1237
  BasicType bt = arg.basic_type();
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1238
  if (is_subword_type(bt)) bt = T_INT;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1239
  switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1240
  case T_INT: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1241
    jint value = arg.get_jint();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1242
    if (-1 <= value && value <= 5)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1243
      emit_bc(Bytecodes::cast(Bytecodes::_iconst_0 + value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1244
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1245
      emit_bc(Bytecodes::_ldc, cpool_int_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1246
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1247
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1248
  case T_LONG: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1249
    jlong value = arg.get_jlong();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1250
    if (0 <= value && value <= 1)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1251
      emit_bc(Bytecodes::cast(Bytecodes::_lconst_0 + (int) value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1252
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1253
      emit_bc(Bytecodes::_ldc2_w, cpool_long_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1254
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1255
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1256
  case T_FLOAT: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1257
    jfloat value  = arg.get_jfloat();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1258
    if (value == 0.0 || value == 1.0 || value == 2.0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1259
      emit_bc(Bytecodes::cast(Bytecodes::_fconst_0 + (int) value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1260
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1261
      emit_bc(Bytecodes::_ldc, cpool_float_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1262
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1263
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1264
  case T_DOUBLE: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1265
    jdouble value = arg.get_jdouble();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1266
    if (value == 0.0 || value == 1.0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1267
      emit_bc(Bytecodes::cast(Bytecodes::_dconst_0 + (int) value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1268
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1269
      emit_bc(Bytecodes::_ldc2_w, cpool_double_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1270
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1271
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1272
  case T_OBJECT: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1273
    Handle value = arg.object();
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1274
    if (value.is_null()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1275
      emit_bc(Bytecodes::_aconst_null);
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1276
      break;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1277
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1278
    if (java_lang_Class::is_instance(value())) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1279
      klassOop k = java_lang_Class::as_klassOop(value());
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1280
      if (k != NULL) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1281
        emit_bc(Bytecodes::_ldc, cpool_klass_put(k));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1282
        break;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1283
      }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1284
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1285
    emit_bc(Bytecodes::_ldc, cpool_object_put(value));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1286
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1287
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1288
  default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1289
    ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1290
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1291
  stack_push(bt);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1292
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1293
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1294
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1295
MethodHandleWalker::ArgToken
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1296
MethodHandleCompiler::make_conversion(BasicType type, klassOop tk, Bytecodes::Code op,
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1297
                                      const ArgToken& src, TRAPS) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1298
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1299
  BasicType srctype = src.basic_type();
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1300
  TokenType tt = src.token_type();
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1301
  int index = -1;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1302
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1303
  switch (op) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1304
  case Bytecodes::_i2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1305
  case Bytecodes::_i2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1306
  case Bytecodes::_i2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1307
  case Bytecodes::_i2b:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1308
  case Bytecodes::_i2c:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1309
  case Bytecodes::_i2s:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1310
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1311
  case Bytecodes::_l2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1312
  case Bytecodes::_l2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1313
  case Bytecodes::_l2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1314
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1315
  case Bytecodes::_f2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1316
  case Bytecodes::_f2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1317
  case Bytecodes::_f2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1318
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1319
  case Bytecodes::_d2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1320
  case Bytecodes::_d2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1321
  case Bytecodes::_d2f:
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1322
    if (tt == tt_constant) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1323
      emit_load_constant(src);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1324
    } else {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1325
      emit_load(srctype, src.index());
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1326
    }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1327
    stack_pop(srctype);  // pop the src type
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1328
    emit_bc(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1329
    stack_push(type);    // push the dest value
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1330
    if (tt != tt_constant)
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1331
      index = src.index();
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1332
    if (srctype != type || index == -1)
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1333
      index = new_local_index(type);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1334
    emit_store(type, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1335
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1336
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1337
  case Bytecodes::_checkcast:
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1338
    if (tt == tt_constant) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1339
      emit_load_constant(src);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1340
    } else {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1341
      emit_load(srctype, src.index());
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1342
      index = src.index();
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1343
    }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1344
    emit_bc(op, cpool_klass_put(tk));
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1345
    check_non_bcp_klass(tk, CHECK_(src));
9976
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
  1346
    // Allocate a new local for the type so that we don't hide the
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
  1347
    // previous type from the verifier.
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9963
diff changeset
  1348
    index = new_local_index(type);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1349
    emit_store(srctype, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1350
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1351
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1352
  case Bytecodes::_nop:
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1353
    // nothing to do
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1354
    return src;
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1355
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1356
  default:
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1357
    if (op == Bytecodes::_illegal)
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1358
      lose(err_msg("no such primitive conversion: %s -> %s", type2name(src.basic_type()), type2name(type)), THREAD);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1359
    else
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1360
      lose(err_msg("bad primitive conversion op: %s", Bytecodes::name(op)), THREAD);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1361
    return make_prim_constant(type, &zero_jvalue, THREAD);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1362
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1363
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1364
  return make_parameter(type, tk, index, THREAD);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1365
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1366
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1367
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1368
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1369
// MethodHandleCompiler
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1370
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1371
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1372
// Values used by the compiler.
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1373
jvalue MethodHandleCompiler::zero_jvalue = { 0 };
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1374
jvalue MethodHandleCompiler::one_jvalue  = { 1 };
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1375
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1376
// Fetch any values from CountingMethodHandles and capture them for profiles
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1377
bool MethodHandleCompiler::fetch_counts(ArgToken arg1, ArgToken arg2) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1378
  int count1 = -1, count2 = -1;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1379
  if (arg1.token_type() == tt_constant && arg1.basic_type() == T_OBJECT &&
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1380
      java_lang_invoke_CountingMethodHandle::is_instance(arg1.object()())) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1381
    count1 = java_lang_invoke_CountingMethodHandle::vmcount(arg1.object()());
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1382
  }
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1383
  if (arg2.token_type() == tt_constant && arg2.basic_type() == T_OBJECT &&
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1384
      java_lang_invoke_CountingMethodHandle::is_instance(arg2.object()())) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1385
    count2 = java_lang_invoke_CountingMethodHandle::vmcount(arg2.object()());
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1386
  }
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1387
  int total = count1 + count2;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1388
  if (count1 != -1 && count2 != -1 && total != 0) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1389
    // Normalize the collect counts to the invoke_count
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1390
    if (count1 != 0) _not_taken_count = (int)(_invoke_count * count1 / (double)total);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1391
    if (count2 != 0) _taken_count = (int)(_invoke_count * count2 / (double)total);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1392
    return true;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1393
  }
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1394
  return false;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1395
}
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1396
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1397
// Emit bytecodes for the given invoke instruction.
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1398
MethodHandleWalker::ArgToken
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1399
MethodHandleCompiler::make_invoke(methodHandle m, vmIntrinsics::ID iid,
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1400
                                  Bytecodes::Code op, bool tailcall,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1401
                                  int argc, MethodHandleWalker::ArgToken* argv,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1402
                                  TRAPS) {
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1403
  ArgToken zero;
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1404
  if (m.is_null()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1405
    // Get the intrinsic methodOop.
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1406
    m = methodHandle(THREAD, vmIntrinsics::method_for(iid));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1407
    if (m.is_null()) {
8675
e9fef2a9bef7 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8296
diff changeset
  1408
      lose(vmIntrinsics::name_at(iid), CHECK_(zero));
e9fef2a9bef7 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8296
diff changeset
  1409
    }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1410
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1411
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1412
  klassOop klass     = m->method_holder();
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1413
  Symbol*  name      = m->name();
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1414
  Symbol*  signature = m->signature();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1415
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1416
  if (iid == vmIntrinsics::_invokeGeneric &&
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1417
      argc >= 1 && argv[0].token_type() == tt_constant) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1418
    assert(m->intrinsic_id() == vmIntrinsics::_invokeExact, "");
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1419
    Handle receiver = argv[0].object();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1420
    Handle rtype(THREAD, java_lang_invoke_MethodHandle::type(receiver()));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1421
    Handle mtype(THREAD, m->method_handle_type());
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1422
    if (rtype() != mtype()) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1423
      assert(java_lang_invoke_MethodType::form(rtype()) ==
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1424
             java_lang_invoke_MethodType::form(mtype()),
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1425
             "must be the same shape");
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1426
      // customize m to the exact required rtype
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1427
      bool has_non_bcp_klass = check_non_bcp_klasses(rtype(), CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1428
      TempNewSymbol sig2 = java_lang_invoke_MethodType::as_signature(rtype(), true, CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1429
      methodHandle m2;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1430
      if (!has_non_bcp_klass) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1431
        methodOop m2_oop = SystemDictionary::find_method_handle_invoke(m->name(), sig2,
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1432
                                                                       KlassHandle(), CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1433
        m2 = methodHandle(THREAD, m2_oop);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1434
      }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1435
      if (m2.is_null()) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1436
        // just build it fresh
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1437
        m2 = methodOopDesc::make_invoke_method(klass, m->name(), sig2, rtype, CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1438
        if (m2.is_null())
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1439
          lose(err_msg("no customized invoker %s", sig2->as_utf8()), CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1440
      }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1441
      m = m2;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1442
      signature = m->signature();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1443
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1444
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1445
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1446
  if (m->intrinsic_id() == vmIntrinsics::_selectAlternative &&
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1447
      fetch_counts(argv[1], argv[2])) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1448
    assert(argc == 3, "three arguments");
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1449
    assert(tailcall, "only");
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1450
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1451
    // do inline bytecodes so we can drop profile data into it,
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1452
    //   0:   iload_0
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1453
    emit_load(argv[0]);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1454
    //   1:   ifeq    8
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1455
    _selectAlternative_bci = _bytecode.length();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1456
    emit_bc(Bytecodes::_ifeq, 0); // emit placeholder offset
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1457
    //   4:   aload_1
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1458
    emit_load(argv[1]);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1459
    //   5:   areturn;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1460
    emit_bc(Bytecodes::_areturn);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1461
    //   8:   aload_2
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1462
    update_branch_dest(_selectAlternative_bci, cur_bci());
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1463
    emit_load(argv[2]);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1464
    //   9:   areturn
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1465
    emit_bc(Bytecodes::_areturn);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1466
    return ArgToken();  // Dummy return value.
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1467
  }
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1468
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1469
  check_non_bcp_klass(klass, CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1470
  if (m->is_method_handle_invoke()) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1471
    check_non_bcp_klasses(m->method_handle_type(), CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1472
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1473
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1474
  // Count the number of arguments, not the size
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1475
  ArgumentCount asc(signature);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1476
  assert(argc == asc.size() + ((op == Bytecodes::_invokestatic || op == Bytecodes::_invokedynamic) ? 0 : 1),
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1477
         "argc mismatch");
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1478
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1479
  for (int i = 0; i < argc; i++) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1480
    ArgToken arg = argv[i];
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1481
    TokenType tt = arg.token_type();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1482
    BasicType bt = arg.basic_type();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1483
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1484
    switch (tt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1485
    case tt_parameter:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1486
    case tt_temporary:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1487
      emit_load(bt, arg.index());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1488
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1489
    case tt_constant:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1490
      emit_load_constant(arg);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1491
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1492
    case tt_illegal:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1493
      // Sentinel.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1494
      assert(i == (argc - 1), "sentinel must be last entry");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1495
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1496
    case tt_void:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1497
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1498
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1499
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1500
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1501
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1502
  // Populate constant pool.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1503
  int name_index          = cpool_symbol_put(name);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1504
  int signature_index     = cpool_symbol_put(signature);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1505
  int name_and_type_index = cpool_name_and_type_put(name_index, signature_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1506
  int klass_index         = cpool_klass_put(klass);
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1507
  int methodref_index     = cpool_methodref_put(op, klass_index, name_and_type_index, m);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1508
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1509
  // Generate invoke.
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1510
  switch (op) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1511
  case Bytecodes::_invokestatic:
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1512
  case Bytecodes::_invokespecial:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1513
  case Bytecodes::_invokevirtual:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1514
    emit_bc(op, methodref_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1515
    break;
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1516
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1517
  case Bytecodes::_invokeinterface: {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1518
    ArgumentSizeComputer asc(signature);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1519
    emit_bc(op, methodref_index, asc.size() + 1);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1520
    break;
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1521
  }
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1522
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1523
  default:
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1524
    ShouldNotReachHere();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1525
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1526
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1527
  // If tailcall, we have walked all the way to a direct method handle.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1528
  // Otherwise, make a recursive call to some helper routine.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1529
  BasicType rbt = m->result_type();
4581
e89fbd1bcb3d 6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents: 4571
diff changeset
  1530
  if (rbt == T_ARRAY)  rbt = T_OBJECT;
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1531
  stack_push(rbt);  // The return value is already pushed onto the stack.
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1532
  ArgToken ret;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1533
  if (tailcall) {
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1534
    if (return_conv() == zero_return_conv()) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1535
      rbt = T_VOID;  // discard value
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1536
    } else if (return_conv() != vmIntrinsics::_none) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1537
      // return value conversion
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1538
      int index = new_local_index(rbt);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1539
      emit_store(rbt, index);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1540
      ArgToken arglist[2];
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1541
      arglist[0] = ArgToken(tt_temporary, rbt, index);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1542
      arglist[1] = ArgToken();  // sentinel
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1543
      ret = make_invoke(methodHandle(), return_conv(), Bytecodes::_invokestatic, false, 1, &arglist[0], CHECK_(zero));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1544
      set_return_conv(vmIntrinsics::_none);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1545
      rbt = ret.basic_type();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1546
      emit_load(rbt, ret.index());
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1547
    }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1548
    if (rbt != _rtype) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1549
      if (rbt == T_VOID) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1550
        // push a zero of the right sort
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1551
        if (_rtype == T_OBJECT) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1552
          zero = make_oop_constant(NULL, CHECK_(zero));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1553
        } else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1554
          zero = make_prim_constant(_rtype, &zero_jvalue, CHECK_(zero));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1555
        }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1556
        emit_load_constant(zero);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1557
      } else if (_rtype == T_VOID) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1558
        // We'll emit a _return with something on the stack.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1559
        // It's OK to ignore what's on the stack.
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1560
      } else if (rbt == T_INT && is_subword_type(_rtype)) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1561
        // Convert value to match return type.
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1562
        switch (_rtype) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1563
        case T_BOOLEAN: {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1564
          // boolean is treated as a one-bit unsigned integer.
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1565
          // Cf. API documentation: java/lang/invoke/MethodHandles.html#explicitCastArguments
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1566
          ArgToken one = make_prim_constant(T_INT, &one_jvalue, CHECK_(zero));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1567
          emit_load_constant(one);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1568
          emit_bc(Bytecodes::_iand);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1569
          break;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1570
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1571
        case T_BYTE:    emit_bc(Bytecodes::_i2b); break;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1572
        case T_CHAR:    emit_bc(Bytecodes::_i2c); break;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1573
        case T_SHORT:   emit_bc(Bytecodes::_i2s); break;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1574
        default: ShouldNotReachHere();
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1575
        }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1576
      } else if (is_subword_type(rbt) && (is_subword_type(_rtype) || (_rtype == T_INT))) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1577
        // The subword type was returned as an int and will be passed
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1578
        // on as an int.
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1579
      } else {
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1580
        lose("unknown conversion", CHECK_(zero));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1581
      }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1582
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1583
    switch (_rtype) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1584
    case T_BOOLEAN: case T_BYTE: case T_CHAR: case T_SHORT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1585
    case T_INT:    emit_bc(Bytecodes::_ireturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1586
    case T_LONG:   emit_bc(Bytecodes::_lreturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1587
    case T_FLOAT:  emit_bc(Bytecodes::_freturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1588
    case T_DOUBLE: emit_bc(Bytecodes::_dreturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1589
    case T_VOID:   emit_bc(Bytecodes::_return);  break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1590
    case T_OBJECT:
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
  1591
      if (_rklass.not_null() && _rklass() != SystemDictionary::Object_klass() && !Klass::cast(_rklass())->is_interface()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1592
        emit_bc(Bytecodes::_checkcast, cpool_klass_put(_rklass()));
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1593
        check_non_bcp_klass(_rklass(), CHECK_(zero));
9980
a330de5dea17 7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents: 9976
diff changeset
  1594
      }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1595
      emit_bc(Bytecodes::_areturn);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1596
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1597
    default: ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1598
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1599
    ret = ArgToken();  // Dummy return value.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1600
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1601
  else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1602
    int index = new_local_index(rbt);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1603
    switch (rbt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1604
    case T_BOOLEAN: case T_BYTE: case T_CHAR:  case T_SHORT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1605
    case T_INT:     case T_LONG: case T_FLOAT: case T_DOUBLE:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1606
    case T_OBJECT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1607
      emit_store(rbt, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1608
      ret = ArgToken(tt_temporary, rbt, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1609
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1610
    case T_VOID:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1611
      ret = ArgToken(tt_void);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1612
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1613
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1614
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1615
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1616
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1617
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1618
  return ret;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1619
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1620
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1621
MethodHandleWalker::ArgToken
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1622
MethodHandleCompiler::make_fetch(BasicType type, klassOop tk, Bytecodes::Code op,
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1623
                                 const MethodHandleWalker::ArgToken& base,
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1624
                                 const MethodHandleWalker::ArgToken& offset,
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1625
                                 TRAPS) {
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1626
  switch (base.token_type()) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1627
    case tt_parameter:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1628
    case tt_temporary:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1629
      emit_load(base.basic_type(), base.index());
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1630
      break;
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1631
    case tt_constant:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1632
      emit_load_constant(base);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1633
      break;
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1634
    default:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1635
      ShouldNotReachHere();
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1636
  }
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1637
  switch (offset.token_type()) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1638
    case tt_parameter:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1639
    case tt_temporary:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1640
      emit_load(offset.basic_type(), offset.index());
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1641
      break;
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1642
    case tt_constant:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1643
      emit_load_constant(offset);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1644
      break;
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1645
    default:
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1646
      ShouldNotReachHere();
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1647
  }
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1648
  emit_bc(op);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1649
  int index = new_local_index(type);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1650
  emit_store(type, index);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1651
  return ArgToken(tt_temporary, type, index);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1652
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1653
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1654
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1655
int MethodHandleCompiler::cpool_primitive_put(BasicType bt, jvalue* con) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1656
  jvalue con_copy;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1657
  assert(bt < T_OBJECT, "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1658
  if (type2aelembytes(bt) < jintSize) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1659
    // widen to int
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1660
    con_copy = (*con);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1661
    con = &con_copy;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1662
    switch (bt) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1663
    case T_BOOLEAN: con->i = (con->z ? 1 : 0); break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1664
    case T_BYTE:    con->i = con->b;           break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1665
    case T_CHAR:    con->i = con->c;           break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1666
    case T_SHORT:   con->i = con->s;           break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1667
    default: ShouldNotReachHere();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1668
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1669
    bt = T_INT;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1670
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1671
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1672
//   for (int i = 1, imax = _constants.length(); i < imax; i++) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1673
//     ConstantValue* con = _constants.at(i);
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1674
//     if (con != NULL && con->is_primitive() && con.basic_type() == bt) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1675
//       bool match = false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1676
//       switch (type2size[bt]) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1677
//       case 1:  if (pcon->_value.i == con->i)  match = true;  break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1678
//       case 2:  if (pcon->_value.j == con->j)  match = true;  break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1679
//       }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1680
//       if (match)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1681
//         return i;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1682
//     }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1683
//   }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1684
  ConstantValue* cv = new ConstantValue(bt, *con);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1685
  int index = _constants.append(cv);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1686
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1687
  // long and double entries take 2 slots, we add another empty entry.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1688
  if (type2size[bt] == 2)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1689
    (void) _constants.append(NULL);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1690
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1691
  return index;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1692
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1693
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1694
bool MethodHandleCompiler::check_non_bcp_klasses(Handle method_type, TRAPS) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1695
  bool res = false;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1696
  for (int i = -1, len = java_lang_invoke_MethodType::ptype_count(method_type()); i < len; i++) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1697
    oop ptype = (i == -1
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1698
                 ? java_lang_invoke_MethodType::rtype(method_type())
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1699
                 : java_lang_invoke_MethodType::ptype(method_type(), i));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1700
    res |= check_non_bcp_klass(java_lang_Class::as_klassOop(ptype), CHECK_(false));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1701
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1702
  return res;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1703
}
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1704
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1705
bool MethodHandleCompiler::check_non_bcp_klass(klassOop klass, TRAPS) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1706
  klass = methodOopDesc::check_non_bcp_klass(klass);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1707
  if (klass != NULL) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1708
    Symbol* name = Klass::cast(klass)->name();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1709
    for (int i = _non_bcp_klasses.length() - 1; i >= 0; i--) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1710
      klassOop k2 = _non_bcp_klasses.at(i)();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1711
      if (Klass::cast(k2)->name() == name) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1712
        if (k2 != klass) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1713
          lose(err_msg("unsupported klass name alias %s", name->as_utf8()), THREAD);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1714
        }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1715
        return true;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1716
      }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1717
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1718
    _non_bcp_klasses.append(KlassHandle(THREAD, klass));
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1719
    return true;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1720
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1721
  return false;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1722
}
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1723
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1724
void MethodHandleCompiler::record_non_bcp_klasses() {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1725
  // Append extra klasses to constant pool, to guide klass lookup.
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1726
  for (int k = 0; k < _non_bcp_klasses.length(); k++) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1727
    klassOop non_bcp_klass = _non_bcp_klasses.at(k)();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1728
    bool add_to_cp = true;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1729
    for (int j = 1; j < _constants.length(); j++) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1730
      ConstantValue* cv = _constants.at(j);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1731
      if (cv != NULL && cv->tag() == JVM_CONSTANT_Class
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1732
          && cv->klass_oop() == non_bcp_klass) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1733
        add_to_cp = false;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1734
        break;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1735
      }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1736
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1737
    if (add_to_cp)  cpool_klass_put(non_bcp_klass);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1738
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1739
}
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1740
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1741
constantPoolHandle MethodHandleCompiler::get_constant_pool(TRAPS) const {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1742
  constantPoolHandle nullHandle;
8296
b1c2163e4e59 6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents: 8076
diff changeset
  1743
  constantPoolOop cpool_oop = oopFactory::new_constantPool(_constants.length(),
b1c2163e4e59 6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents: 8076
diff changeset
  1744
                                                           oopDesc::IsSafeConc,
b1c2163e4e59 6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents: 8076
diff changeset
  1745
                                                           CHECK_(nullHandle));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1746
  constantPoolHandle cpool(THREAD, cpool_oop);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1747
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1748
  // Fill the real constant pool skipping the zero element.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1749
  for (int i = 1; i < _constants.length(); i++) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1750
    ConstantValue* cv = _constants.at(i);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1751
    switch (cv->tag()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
  1752
    case JVM_CONSTANT_Utf8:        cpool->symbol_at_put(       i, cv->symbol()                         ); break;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1753
    case JVM_CONSTANT_Integer:     cpool->int_at_put(          i, cv->get_jint()                       ); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1754
    case JVM_CONSTANT_Float:       cpool->float_at_put(        i, cv->get_jfloat()                     ); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1755
    case JVM_CONSTANT_Long:        cpool->long_at_put(         i, cv->get_jlong()                      ); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1756
    case JVM_CONSTANT_Double:      cpool->double_at_put(       i, cv->get_jdouble()                    ); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1757
    case JVM_CONSTANT_Class:       cpool->klass_at_put(        i, cv->klass_oop()                      ); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1758
    case JVM_CONSTANT_Methodref:   cpool->method_at_put(       i, cv->first_index(), cv->second_index()); break;
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1759
    case JVM_CONSTANT_InterfaceMethodref:
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1760
                                cpool->interface_method_at_put(i, cv->first_index(), cv->second_index()); break;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1761
    case JVM_CONSTANT_NameAndType: cpool->name_and_type_at_put(i, cv->first_index(), cv->second_index()); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1762
    case JVM_CONSTANT_Object:      cpool->object_at_put(       i, cv->object_oop()                     ); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1763
    default: ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1764
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1765
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1766
    switch (cv->tag()) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1767
    case JVM_CONSTANT_Long:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1768
    case JVM_CONSTANT_Double:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1769
      i++;  // Skip empty entry.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1770
      assert(_constants.at(i) == NULL, "empty entry");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1771
      break;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1772
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1773
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1774
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1775
  cpool->set_preresolution();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1776
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1777
  // Set the constant pool holder to the target method's class.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1778
  cpool->set_pool_holder(_target_klass());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1779
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1780
  return cpool;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1781
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1782
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1783
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1784
methodHandle MethodHandleCompiler::get_method_oop(TRAPS) {
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1785
  methodHandle empty;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1786
  // Create a method that holds the generated bytecode.  invokedynamic
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1787
  // has no receiver, normal MH calls do.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1788
  int flags_bits;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1789
  if (for_invokedynamic())
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4581
diff changeset
  1790
    flags_bits = (/*JVM_MH_INVOKE_BITS |*/ JVM_ACC_PUBLIC | JVM_ACC_FINAL | JVM_ACC_SYNTHETIC | JVM_ACC_STATIC);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1791
  else
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4581
diff changeset
  1792
    flags_bits = (/*JVM_MH_INVOKE_BITS |*/ JVM_ACC_PUBLIC | JVM_ACC_FINAL | JVM_ACC_SYNTHETIC);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1793
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1794
  // Create a new method
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1795
  methodHandle m;
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1796
  {
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1797
    methodOop m_oop = oopFactory::new_method(bytecode_length(),
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1798
                                             accessFlags_from(flags_bits),
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1799
                                             0, 0, 0, oopDesc::IsSafeConc, CHECK_(empty));
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1800
    m = methodHandle(THREAD, m_oop);
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1801
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1802
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1803
  constantPoolHandle cpool = get_constant_pool(CHECK_(empty));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1804
  m->set_constants(cpool());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1805
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1806
  m->set_name_index(_name_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1807
  m->set_signature_index(_signature_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1808
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1809
  m->set_code((address) bytecode());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1810
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1811
  m->set_max_stack(_max_stack);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1812
  m->set_max_locals(max_locals());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1813
  m->set_size_of_parameters(_num_params);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1814
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1815
  typeArrayHandle exception_handlers(THREAD, Universe::the_empty_int_array());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1816
  m->set_exception_table(exception_handlers());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1817
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1818
  // Rewrite the method and set up the constant pool cache.
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1819
  objArrayOop m_array = oopFactory::new_system_objArray(1, CHECK_(empty));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1820
  objArrayHandle methods(THREAD, m_array);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1821
  methods->obj_at_put(0, m());
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1822
  Rewriter::rewrite(_target_klass(), cpool, methods, CHECK_(empty));  // Use fake class.
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9946
diff changeset
  1823
  Rewriter::relocate_and_link(_target_klass(), methods, CHECK_(empty));  // Use fake class.
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1824
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1825
  // Pre-resolve selected CP cache entries, to avoid problems with class loader scoping.
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1826
  constantPoolCacheHandle cpc(THREAD, cpool->cache());
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1827
  for (int i = 0; i < cpc->length(); i++) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1828
    ConstantPoolCacheEntry* e = cpc->entry_at(i);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1829
    assert(!e->is_secondary_entry(), "no indy instructions in here, yet");
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1830
    int constant_pool_index = e->constant_pool_index();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1831
    ConstantValue* cv = _constants.at(constant_pool_index);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1832
    if (!cv->has_linkage())  continue;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1833
    methodHandle m = cv->linkage();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1834
    int index;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1835
    switch (cv->tag()) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1836
    case JVM_CONSTANT_Methodref:
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1837
      index = m->vtable_index();
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1838
      if (m->is_static()) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1839
        e->set_method(Bytecodes::_invokestatic, m, index);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1840
      } else {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1841
        e->set_method(Bytecodes::_invokespecial, m, index);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1842
        e->set_method(Bytecodes::_invokevirtual, m, index);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1843
      }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1844
      break;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1845
    case JVM_CONSTANT_InterfaceMethodref:
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1846
      index = klassItable::compute_itable_index(m());
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1847
      e->set_interface_call(m, index);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1848
      break;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1849
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1850
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1851
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1852
  // Set the invocation counter's count to the invoke count of the
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1853
  // original call site.
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1854
  InvocationCounter* ic = m->invocation_counter();
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1855
  ic->set(InvocationCounter::wait_for_compile, _invoke_count);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1856
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1857
  // Create a new MDO
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1858
  {
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1859
    methodDataOop mdo = oopFactory::new_methodData(m, CHECK_(empty));
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1860
    assert(m->method_data() == NULL, "there should not be an MDO yet");
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1861
    m->set_method_data(mdo);
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1862
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1863
    bool found_selectAlternative = false;
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1864
    // Iterate over all profile data and set the count of the counter
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1865
    // data entries to the original call site counter.
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1866
    for (ProfileData* profile_data = mdo->first_data();
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1867
         mdo->is_valid(profile_data);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1868
         profile_data = mdo->next_data(profile_data)) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1869
      if (profile_data->is_CounterData()) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1870
        CounterData* counter_data = profile_data->as_CounterData();
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1871
        counter_data->set_count(_invoke_count);
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1872
      }
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1873
      if (profile_data->is_BranchData() &&
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1874
          profile_data->bci() == _selectAlternative_bci) {
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1875
        BranchData* bd = profile_data->as_BranchData();
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1876
        bd->set_taken(_taken_count);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1877
        bd->set_not_taken(_not_taken_count);
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1878
        found_selectAlternative = true;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1879
      }
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1880
    }
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10008
diff changeset
  1881
    assert(_selectAlternative_bci == -1 || found_selectAlternative, "must have found profile entry");
9633
92a7a2841a16 7042122: JSR 292: adjust various inline thresholds for JSR 292 API methods and method handle adapters
twisti
parents: 9630
diff changeset
  1882
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1883
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1884
#ifndef PRODUCT
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1885
  if (TraceMethodHandles) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1886
    m->print();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1887
    m->print_codes();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1888
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1889
#endif //PRODUCT
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1890
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4581
diff changeset
  1891
  assert(m->is_method_handle_adapter(), "must be recognized as an adapter");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1892
  return m;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1893
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1894
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1895
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1896
#ifndef PRODUCT
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1897
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1898
// MH printer for debugging.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1899
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1900
class MethodHandlePrinter : public MethodHandleWalker {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1901
private:
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1902
  outputStream* _out;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1903
  bool          _verbose;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1904
  int           _temp_num;
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1905
  int           _param_state;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1906
  stringStream  _strbuf;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1907
  const char* strbuf() {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1908
    const char* s = _strbuf.as_string();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1909
    _strbuf.reset();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1910
    return s;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1911
  }
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1912
  ArgToken token(const char* str, BasicType type) {
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1913
    return ArgToken(str, type);
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1914
  }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1915
  const char* string(ArgToken token) {
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9943
diff changeset
  1916
    return token.str();
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1917
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1918
  void start_params() {
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1919
    _param_state <<= 1;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1920
    _out->print("(");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1921
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1922
  void end_params() {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1923
    if (_verbose)  _out->print("\n");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1924
    _out->print(") => {");
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1925
    _param_state >>= 1;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1926
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1927
  void put_type_name(BasicType type, klassOop tk, outputStream* s) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1928
    const char* kname = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1929
    if (tk != NULL)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1930
      kname = Klass::cast(tk)->external_name();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1931
    s->print("%s", (kname != NULL) ? kname : type2name(type));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1932
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1933
  ArgToken maybe_make_temp(const char* statement_op, BasicType type, const char* temp_name) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1934
    const char* value = strbuf();
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1935
    if (!_verbose)  return token(value, type);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1936
    // make an explicit binding for each separate value
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1937
    _strbuf.print("%s%d", temp_name, ++_temp_num);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1938
    const char* temp = strbuf();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1939
    _out->print("\n  %s %s %s = %s;", statement_op, type2name(type), temp, value);
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1940
    return token(temp, type);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1941
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1942
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1943
public:
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1944
  MethodHandlePrinter(Handle root, bool verbose, outputStream* out, TRAPS)
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1945
    : MethodHandleWalker(root, false, THREAD),
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1946
      _out(out),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1947
      _verbose(verbose),
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1948
      _param_state(0),
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1949
      _temp_num(0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1950
  {
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1951
    out->print("MethodHandle:");
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1952
    java_lang_invoke_MethodType::print_signature(java_lang_invoke_MethodHandle::type(root()), out);
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  1953
    out->print(" : #");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1954
    start_params();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1955
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1956
  virtual ArgToken make_parameter(BasicType type, klassOop tk, int argnum, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1957
    if (argnum < 0) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1958
      end_params();
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1959
      return token("return", type);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1960
    }
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1961
    if ((_param_state & 1) == 0) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1962
      _param_state |= 1;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1963
      _out->print(_verbose ? "\n  " : "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1964
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1965
      _out->print(_verbose ? ",\n  " : ", ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1966
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1967
    if (argnum >= _temp_num)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1968
      _temp_num = argnum;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1969
    // generate an argument name
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1970
    _strbuf.print("a%d", argnum);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1971
    const char* arg = strbuf();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1972
    put_type_name(type, tk, _out);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1973
    _out->print(" %s", arg);
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  1974
    return token(arg, type);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1975
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1976
  virtual ArgToken make_oop_constant(oop con, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1977
    if (con == NULL)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1978
      _strbuf.print("null");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1979
    else
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1980
      con->print_value_on(&_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1981
    if (_strbuf.size() == 0) {  // yuck
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1982
      _strbuf.print("(a ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1983
      put_type_name(T_OBJECT, con->klass(), &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1984
      _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1985
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1986
    return maybe_make_temp("constant", T_OBJECT, "k");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1987
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1988
  virtual ArgToken make_prim_constant(BasicType type, jvalue* con, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1989
    java_lang_boxing_object::print(type, con, &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1990
    return maybe_make_temp("constant", type, "k");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1991
  }
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1992
  void print_bytecode_name(Bytecodes::Code op) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1993
    if (Bytecodes::is_defined(op))
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1994
      _strbuf.print("%s", Bytecodes::name(op));
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1995
    else
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1996
      _strbuf.print("bytecode_%d", (int) op);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1997
  }
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1998
  virtual ArgToken make_conversion(BasicType type, klassOop tk, Bytecodes::Code op, const ArgToken& src, TRAPS) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  1999
    print_bytecode_name(op);
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2000
    _strbuf.print("(%s", string(src));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2001
    if (tk != NULL) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2002
      _strbuf.print(", ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2003
      put_type_name(type, tk, &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2004
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2005
    _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2006
    return maybe_make_temp("convert", type, "v");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2007
  }
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2008
  virtual ArgToken make_fetch(BasicType type, klassOop tk, Bytecodes::Code op, const ArgToken& base, const ArgToken& offset, TRAPS) {
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2009
    _strbuf.print("%s(%s, %s", Bytecodes::name(op), string(base), string(offset));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2010
    if (tk != NULL) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2011
      _strbuf.print(", ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2012
      put_type_name(type, tk, &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2013
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2014
    _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2015
    return maybe_make_temp("fetch", type, "x");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2016
  }
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  2017
  virtual ArgToken make_invoke(methodHandle m, vmIntrinsics::ID iid,
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2018
                               Bytecodes::Code op, bool tailcall,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2019
                               int argc, ArgToken* argv, TRAPS) {
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2020
    Symbol* name;
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2021
    Symbol* sig;
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9982
diff changeset
  2022
    if (m.not_null()) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2023
      name = m->name();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2024
      sig  = m->signature();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2025
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2026
      name = vmSymbols::symbol_at(vmIntrinsics::name_for(iid));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2027
      sig  = vmSymbols::symbol_at(vmIntrinsics::signature_for(iid));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2028
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2029
    _strbuf.print("%s %s%s(", Bytecodes::name(op), name->as_C_string(), sig->as_C_string());
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2030
    for (int i = 0; i < argc; i++) {
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2031
      _strbuf.print("%s%s", (i > 0 ? ", " : ""), string(argv[i]));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2032
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2033
    _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2034
    if (!tailcall) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2035
      BasicType rt = char2type(sig->byte_at(sig->utf8_length()-1));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2036
      if (rt == T_ILLEGAL)  rt = T_OBJECT;  // ';' at the end of '(...)L...;'
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2037
      return maybe_make_temp("invoke", rt, "x");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2038
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2039
      const char* ret = strbuf();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2040
      _out->print(_verbose ? "\n  return " : " ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2041
      _out->print("%s", ret);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2042
      _out->print(_verbose ? "\n}\n" : " }");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2043
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2044
    return ArgToken();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2045
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2046
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2047
  virtual void set_method_handle(oop mh) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2048
    if (WizardMode && Verbose) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2049
      tty->print("\n--- next target: ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2050
      mh->print();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2051
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2052
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2053
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2054
  static void print(Handle root, bool verbose, outputStream* out, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2055
    ResourceMark rm;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2056
    MethodHandlePrinter printer(root, verbose, out, CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2057
    printer.walk(CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2058
    out->print("\n");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2059
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2060
  static void print(Handle root, bool verbose = Verbose, outputStream* out = tty) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9946
diff changeset
  2061
    Thread* THREAD = Thread::current();
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2062
    ResourceMark rm;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2063
    MethodHandlePrinter printer(root, verbose, out, THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2064
    if (!HAS_PENDING_EXCEPTION)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2065
      printer.walk(THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2066
    if (HAS_PENDING_EXCEPTION) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2067
      oop ex = PENDING_EXCEPTION;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2068
      CLEAR_PENDING_EXCEPTION;
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2069
      out->print(" *** ");
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2070
      if (printer.lose_message() != NULL)  out->print("%s ", printer.lose_message());
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2071
      out->print("}");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2072
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2073
    out->print("\n");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2074
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2075
};
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2076
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2077
extern "C"
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2078
void print_method_handle(oop mh) {
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 6453
diff changeset
  2079
  if (!mh->is_oop()) {
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2080
    tty->print_cr("*** not a method handle: "PTR_FORMAT, (intptr_t)mh);
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  2081
  } else if (java_lang_invoke_MethodHandle::is_instance(mh)) {
9638
a9e79f5cd83b 6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents: 9633
diff changeset
  2082
    MethodHandlePrinter::print(mh);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2083
  } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2084
    tty->print("*** not a method handle: ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2085
    mh->print();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2086
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2087
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2088
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  2089
#endif // PRODUCT