hotspot/src/share/vm/prims/methodHandleWalk.cpp
author never
Fri, 06 May 2011 16:33:13 -0700
changeset 9630 d6419e4395e3
parent 9323 20cc2230dc8a
child 9633 92a7a2841a16
permissions -rw-r--r--
6939861: JVM should handle more conversion operations Reviewed-by: twisti, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    34
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    35
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    36
// MethodHandleChain
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    37
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    38
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
    39
  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
    40
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    41
  // set current method handle and unpack partially
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    42
  _method_handle = mh;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    43
  _is_last       = false;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    44
  _is_bound      = false;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    45
  _arg_slot      = -1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    46
  _arg_type      = T_VOID;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    47
  _conversion    = -1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    48
  _last_invoke   = Bytecodes::_nop;  //arbitrary non-garbage
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    49
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    50
  if (java_lang_invoke_DirectMethodHandle::is_instance(mh())) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    51
    set_last_method(mh(), THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    52
    return;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    53
  }
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    54
  if (java_lang_invoke_AdapterMethodHandle::is_instance(mh())) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    55
    _conversion = AdapterMethodHandle_conversion();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    56
    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
    57
    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
    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_BoundMethodHandle::is_instance(mh())) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    60
    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
    61
      _is_bound = true;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    62
    _arg_slot = BoundMethodHandle_vmargslot();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    63
    oop target = MethodHandle_vmtarget_oop();
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
    64
    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
    65
      _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
    66
    } else if (target != NULL && target->is_method()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    67
      methodOop m = (methodOop) target;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    68
      _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
    69
      set_last_method(mh(), CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    70
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    71
      _is_bound = false;  // lose!
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    72
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    73
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    74
  if (is_bound() && _arg_type == T_VOID) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    75
    lose("bad vmargslot", CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    76
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    77
  if (!is_bound() && !is_adapter()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    78
    lose("unrecognized MH type", CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    79
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    80
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    81
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    82
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    83
void MethodHandleChain::set_last_method(oop target, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    84
  _is_last = true;
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9116
diff changeset
    85
  KlassHandle receiver_limit; int flags = 0;
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9116
diff changeset
    86
  _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
    87
  if ((flags & MethodHandles::_dmf_has_receiver) == 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    88
    _last_invoke = Bytecodes::_invokestatic;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    89
  else if ((flags & MethodHandles::_dmf_does_dispatch) == 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    90
    _last_invoke = Bytecodes::_invokespecial;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    91
  else if ((flags & MethodHandles::_dmf_from_interface) != 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    92
    _last_invoke = Bytecodes::_invokeinterface;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    93
  else
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    94
    _last_invoke = Bytecodes::_invokevirtual;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    95
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    96
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
    97
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
    98
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
    99
  // 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
   100
  // 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
   101
  BasicType arg_type = T_VOID;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   102
  if (target != NULL) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   103
    oop mtype = java_lang_invoke_MethodHandle::type(target);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   104
    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
   105
    if (arg_num >= 0) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   106
      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
   107
      arg_type = java_lang_Class::as_BasicType(ptype);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   108
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   109
  } else if (m != NULL) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   110
    // figure out the argument type from the slot
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   111
    // FIXME: make this explicit in the MH
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   112
    int cur_slot = m->size_of_parameters();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   113
    if (arg_slot >= cur_slot)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   114
      return T_VOID;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   115
    if (!m->is_static()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   116
      cur_slot -= type2size[T_OBJECT];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   117
      if (cur_slot == arg_slot)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   118
        return T_OBJECT;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   119
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
   120
    ResourceMark rm(THREAD);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   121
    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
   122
      BasicType bt = ss.type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   123
      cur_slot -= type2size[bt];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   124
      if (cur_slot <= arg_slot) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   125
        if (cur_slot == arg_slot)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   126
          arg_type = bt;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   127
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   128
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   129
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   130
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   131
  if (arg_type == T_ARRAY)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   132
    arg_type = T_OBJECT;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   133
  return arg_type;
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
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   136
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   137
void MethodHandleChain::lose(const char* msg, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   138
  _lose_message = msg;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   139
  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
   140
    // throw a preallocated exception
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   141
    THROW_OOP(Universe::virtual_machine_error_instance());
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   142
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   143
  THROW_MSG(vmSymbols::java_lang_InternalError(), msg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   144
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   145
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   146
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   147
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   148
// MethodHandleWalker
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   149
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   150
Bytecodes::Code MethodHandleWalker::conversion_code(BasicType src, BasicType dest) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   151
  if (is_subword_type(src)) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   152
    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
   153
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   154
  if (src == dest) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   155
    return Bytecodes::_nop;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   156
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   157
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   158
#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
   159
  switch (SRC_DEST(src, dest)) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   160
  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
   161
  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
   162
  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
   163
  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
   164
  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
   165
  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
   166
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   167
  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
   168
  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
   169
  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
   170
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   171
  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
   172
  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
   173
  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
   174
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   175
  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
   176
  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
   177
  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
   178
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   179
#undef SRC_DEST
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   180
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   181
  // cannot do it in one step, or at all
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   182
  return Bytecodes::_illegal;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   183
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   184
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   185
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   186
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   187
// MethodHandleWalker::walk
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   188
//
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   189
MethodHandleWalker::ArgToken
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   190
MethodHandleWalker::walk(TRAPS) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   191
  ArgToken empty = ArgToken();  // Empty return value.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   192
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   193
  walk_incoming_state(CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   194
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   195
  for (;;) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   196
    set_method_handle(chain().method_handle_oop());
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   197
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   198
    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
   199
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   200
    if (chain().is_adapter()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   201
      int conv_op = chain().adapter_conversion_op();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   202
      int arg_slot = chain().adapter_arg_slot();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   203
      SlotState* arg_state = slot_state(arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   204
      if (arg_state == NULL
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   205
          && conv_op > java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   206
        lose("bad argument index", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   207
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   208
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   209
      // perform the adapter action
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   210
      switch (chain().adapter_conversion_op()) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   211
      case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY:
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   212
        // No changes to arguments; pass the bits through.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   213
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   214
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   215
      case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW: {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   216
        // 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
   217
        // See MethodHandles::same_basic_type_for_arguments for allowed conversions.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   218
        Handle incoming_mtype(THREAD, chain().method_type_oop());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   219
        oop outgoing_mh_oop = chain().vmtarget_oop();
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   220
        if (!java_lang_invoke_MethodHandle::is_instance(outgoing_mh_oop))
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   221
          lose("outgoing target not a MethodHandle", CHECK_(empty));
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   222
        Handle outgoing_mtype(THREAD, java_lang_invoke_MethodHandle::type(outgoing_mh_oop));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   223
        outgoing_mh_oop = NULL;  // GC safety
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   224
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   225
        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
   226
        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
   227
          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
   228
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   229
        for (int i = 0, slot = _outgoing.length() - 1; slot >= 0; slot--) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   230
          SlotState* arg_state = slot_state(slot);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   231
          if (arg_state->_type == T_VOID)  continue;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   232
          ArgToken arg = _outgoing.at(slot)._arg;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   233
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   234
          klassOop  in_klass  = NULL;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   235
          klassOop  out_klass = NULL;
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   236
          BasicType inpbt  = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::ptype(incoming_mtype(), i), &in_klass);
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   237
          BasicType outpbt = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::ptype(outgoing_mtype(), i), &out_klass);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   238
          assert(inpbt == arg.basic_type(), "sanity");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   239
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   240
          if (inpbt != outpbt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   241
            vmIntrinsics::ID iid = vmIntrinsics::for_raw_conversion(inpbt, outpbt);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   242
            if (iid == vmIntrinsics::_none) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   243
              lose("no raw conversion method", CHECK_(empty));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   244
            }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   245
            ArgToken arglist[2];
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   246
            arglist[0] = arg;         // outgoing 'this'
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   247
            arglist[1] = ArgToken();  // sentinel
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   248
            arg = make_invoke(NULL, iid, Bytecodes::_invokestatic, false, 1, &arglist[0], CHECK_(empty));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   249
            change_argument(inpbt, slot, outpbt, arg);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   250
          }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   251
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   252
          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
   253
        }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   254
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   255
        BasicType inrbt  = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(incoming_mtype()));
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   256
        BasicType outrbt = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(outgoing_mtype()));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   257
        if (inrbt != outrbt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   258
          if (inrbt == T_INT && outrbt == T_VOID) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   259
            // See comments in MethodHandles::same_basic_type_for_arguments.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   260
          } else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   261
            assert(false, "IMPLEMENT ME");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   262
            lose("no raw conversion method", CHECK_(empty));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   263
          }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   264
        }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   265
        break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   266
      }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   267
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   268
      case java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   269
        // checkcast the Nth outgoing argument in place
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   270
        klassOop dest_klass = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   271
        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
   272
        assert(dest == T_OBJECT, "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   273
        assert(dest == arg_state->_type, "");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   274
        ArgToken arg = arg_state->_arg;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   275
        ArgToken new_arg = make_conversion(T_OBJECT, dest_klass, Bytecodes::_checkcast, arg, CHECK_(empty));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   276
        assert(arg.index() == new_arg.index(), "should be the same index");
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   277
        debug_only(dest_klass = (klassOop)badOop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   278
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   279
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   280
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   281
      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
   282
        // i2l, etc., on the Nth outgoing argument in place
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   283
        BasicType src = chain().adapter_conversion_src_type(),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   284
                  dest = chain().adapter_conversion_dest_type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   285
        Bytecodes::Code bc = conversion_code(src, dest);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   286
        ArgToken arg = arg_state->_arg;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   287
        if (bc == Bytecodes::_nop) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   288
          break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   289
        } else if (bc != Bytecodes::_illegal) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   290
          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
   291
        } else if (is_subword_type(dest)) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   292
          bc = conversion_code(src, T_INT);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   293
          if (bc != Bytecodes::_illegal) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   294
            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
   295
            bc = conversion_code(T_INT, dest);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   296
            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
   297
          }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   298
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   299
        if (bc == Bytecodes::_illegal) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   300
          lose("bad primitive conversion", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   301
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   302
        change_argument(src, arg_slot, dest, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   303
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   304
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   305
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   306
      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
   307
        // checkcast to wrapper type & call intValue, etc.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   308
        BasicType dest = chain().adapter_conversion_dest_type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   309
        ArgToken arg = arg_state->_arg;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   310
        arg = make_conversion(T_OBJECT, SystemDictionary::box_klass(dest),
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   311
                              Bytecodes::_checkcast, arg, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   312
        vmIntrinsics::ID unboxer = vmIntrinsics::for_unboxing(dest);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   313
        if (unboxer == vmIntrinsics::_none) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   314
          lose("no unboxing method", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   315
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   316
        ArgToken arglist[2];
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   317
        arglist[0] = arg;         // outgoing 'this'
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   318
        arglist[1] = ArgToken();  // sentinel
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   319
        arg = make_invoke(NULL, 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
   320
        change_argument(T_OBJECT, arg_slot, dest, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   321
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   322
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   323
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   324
      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
   325
        // call wrapper type.valueOf
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   326
        BasicType src = chain().adapter_conversion_src_type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   327
        ArgToken arg = arg_state->_arg;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   328
        vmIntrinsics::ID boxer = vmIntrinsics::for_boxing(src);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   329
        if (boxer == vmIntrinsics::_none) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   330
          lose("no boxing method", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   331
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   332
        ArgToken arglist[2];
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   333
        arglist[0] = arg;         // outgoing value
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   334
        arglist[1] = ArgToken();  // sentinel
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 6453
diff changeset
   335
        arg = make_invoke(NULL, boxer, Bytecodes::_invokevirtual, false, 1, &arglist[0], CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   336
        change_argument(src, arg_slot, T_OBJECT, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   337
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   338
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   339
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   340
      case java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   341
        int dest_arg_slot = chain().adapter_conversion_vminfo();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   342
        if (!slot_has_argument(dest_arg_slot)) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   343
          lose("bad swap index", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   344
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   345
        // a simple swap between two arguments
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   346
        SlotState* dest_arg_state = slot_state(dest_arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   347
        SlotState temp = (*dest_arg_state);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   348
        (*dest_arg_state) = (*arg_state);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   349
        (*arg_state) = temp;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   350
        break;
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
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   353
      case java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   354
        int dest_arg_slot = chain().adapter_conversion_vminfo();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   355
        if (!slot_has_argument(dest_arg_slot) || arg_slot == dest_arg_slot) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   356
          lose("bad rotate index", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   357
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   358
        SlotState* dest_arg_state = slot_state(dest_arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   359
        // 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
   360
        // position occupied by the dest argument (plus following N slots).
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   361
        int rotate_count = type2size[dest_arg_state->_type];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   362
        // (no other rotate counts are currently supported)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   363
        if (arg_slot < dest_arg_slot) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   364
          for (int i = 0; i < rotate_count; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   365
            SlotState temp = _outgoing.at(arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   366
            _outgoing.remove_at(arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   367
            _outgoing.insert_before(dest_arg_slot + rotate_count - 1, temp);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   368
          }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   369
        } else { // arg_slot > dest_arg_slot
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   370
          for (int i = 0; i < rotate_count; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   371
            SlotState temp = _outgoing.at(arg_slot + rotate_count - 1);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   372
            _outgoing.remove_at(arg_slot + rotate_count - 1);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   373
            _outgoing.insert_before(dest_arg_slot, temp);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   374
          }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   375
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   376
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   377
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   378
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   379
      case java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   380
        int dup_slots = chain().adapter_conversion_stack_pushes();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   381
        if (dup_slots <= 0) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   382
          lose("bad dup count", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   383
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   384
        for (int i = 0; i < dup_slots; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   385
          SlotState* dup = slot_state(arg_slot + 2*i);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   386
          if (dup == NULL)              break;  // safety net
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   387
          if (dup->_type != T_VOID)     _outgoing_argc += 1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   388
          _outgoing.insert_before(i, (*dup));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   389
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   390
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   391
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   392
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   393
      case java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   394
        int drop_slots = -chain().adapter_conversion_stack_pushes();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   395
        if (drop_slots <= 0) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   396
          lose("bad drop count", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   397
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   398
        for (int i = 0; i < drop_slots; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   399
          SlotState* drop = slot_state(arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   400
          if (drop == NULL)             break;  // safety net
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   401
          if (drop->_type != T_VOID)    _outgoing_argc -= 1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   402
          _outgoing.remove_at(arg_slot);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   403
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   404
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   405
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   406
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   407
      case java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS: { //NYI, may GC
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   408
        lose("unimplemented", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   409
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   410
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   411
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   412
      case java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS: { //NYI, may GC
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   413
        lose("unimplemented", CHECK_(empty));
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   414
        break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   415
      }
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   416
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   417
      case java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS: {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   418
        klassOop array_klass_oop = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   419
        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
   420
                                                             &array_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   421
        assert(array_type == T_OBJECT, "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   422
        assert(Klass::cast(array_klass_oop)->oop_is_array(), "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   423
        arrayKlassHandle array_klass(THREAD, array_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   424
        debug_only(array_klass_oop = (klassOop)badOop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   425
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   426
        klassOop element_klass_oop = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   427
        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
   428
                                                               &element_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   429
        KlassHandle element_klass(THREAD, element_klass_oop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   430
        debug_only(element_klass_oop = (klassOop)badOop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   431
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   432
        // Fetch the argument, which we will cast to the required array type.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   433
        assert(arg_state->_type == T_OBJECT, "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   434
        ArgToken array_arg = arg_state->_arg;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   435
        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
   436
        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
   437
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   438
        // Check the required length.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   439
        int spread_slots = 1 + chain().adapter_conversion_stack_pushes();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   440
        int spread_length = spread_slots;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   441
        if (type2size[element_type] == 2) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   442
          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
   443
          spread_length = spread_slots / 2;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   444
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   445
        if (spread_slots < 0) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   446
          lose("bad spread length", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   447
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   448
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   449
        jvalue   length_jvalue;  length_jvalue.i = spread_length;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   450
        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
   451
        // 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
   452
        ArgToken arglist[3];
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   453
        arglist[0] = array_arg;   // value to check
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   454
        arglist[1] = length_arg;  // length to check
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   455
        arglist[2] = ArgToken();  // sentinel
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   456
        make_invoke(NULL, vmIntrinsics::_checkSpreadArgument,
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   457
                    Bytecodes::_invokestatic, false, 3, &arglist[0], CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   458
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   459
        // Spread out the array elements.
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   460
        Bytecodes::Code aload_op = Bytecodes::_nop;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   461
        switch (element_type) {
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   462
        case T_INT:       aload_op = Bytecodes::_iaload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   463
        case T_LONG:      aload_op = Bytecodes::_laload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   464
        case T_FLOAT:     aload_op = Bytecodes::_faload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   465
        case T_DOUBLE:    aload_op = Bytecodes::_daload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   466
        case T_OBJECT:    aload_op = Bytecodes::_aaload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   467
        case T_BOOLEAN:   // fall through:
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   468
        case T_BYTE:      aload_op = Bytecodes::_baload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   469
        case T_CHAR:      aload_op = Bytecodes::_caload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   470
        case T_SHORT:     aload_op = Bytecodes::_saload; break;
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   471
        default:          lose("primitive array NYI", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   472
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   473
        int ap = arg_slot;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   474
        for (int i = 0; i < spread_length; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   475
          jvalue   offset_jvalue;  offset_jvalue.i = i;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   476
          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
   477
          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
   478
          change_argument(T_VOID, ap, element_type, element_arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   479
          ap += type2size[element_type];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   480
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   481
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   482
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   483
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   484
      default:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   485
        lose("bad adapter conversion", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   486
        break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   487
      }
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
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   490
    if (chain().is_bound()) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   491
      // push a new argument
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   492
      BasicType arg_type  = chain().bound_arg_type();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   493
      jint      arg_slot  = chain().bound_arg_slot();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   494
      oop       arg_oop   = chain().bound_arg_oop();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   495
      ArgToken  arg;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   496
      if (arg_type == T_OBJECT) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   497
        arg = make_oop_constant(arg_oop, CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   498
      } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   499
        jvalue arg_value;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   500
        BasicType bt = java_lang_boxing_object::get_value(arg_oop, &arg_value);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   501
        if (bt == arg_type) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   502
          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
   503
        } else {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   504
          lose("bad bound value", CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   505
        }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   506
      }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   507
      debug_only(arg_oop = badOop);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   508
      change_argument(T_VOID, arg_slot, arg_type, arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   509
    }
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
    // 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
   512
    if (!chain().is_last()) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   513
      chain().next(CHECK_(empty));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   514
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   515
      break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   516
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   517
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   518
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   519
  // 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
   520
  // 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
   521
  ArgToken* arglist = NEW_RESOURCE_ARRAY(ArgToken, _outgoing.length() + 1);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   522
  int ap = 0;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   523
  for (int i = _outgoing.length() - 1; i >= 0; i--) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   524
    SlotState* arg_state = slot_state(i);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   525
    if (arg_state->_type == T_VOID)  continue;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   526
    arglist[ap++] = _outgoing.at(i)._arg;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   527
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   528
  assert(ap == _outgoing_argc, "");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   529
  arglist[ap] = ArgToken();  // add a sentinel, for the sake of asserts
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   530
  return make_invoke(chain().last_method_oop(),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   531
                     vmIntrinsics::_none,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   532
                     chain().last_invoke_code(), true,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   533
                     ap, arglist, THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   534
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   535
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   536
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   537
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   538
// MethodHandleWalker::walk_incoming_state
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   539
//
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   540
void MethodHandleWalker::walk_incoming_state(TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   541
  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
   542
  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
   543
  _outgoing_argc = nptypes;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   544
  int argp = nptypes - 1;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   545
  if (argp >= 0) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   546
    _outgoing.at_grow(argp, make_state(T_VOID, ArgToken(tt_void))); // presize
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
  for (int i = 0; i < nptypes; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   549
    klassOop  arg_type_klass = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   550
    BasicType arg_type = java_lang_Class::as_BasicType(
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   551
                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
   552
    int index = new_local_index(arg_type);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   553
    ArgToken arg = make_parameter(arg_type, arg_type_klass, index, CHECK);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   554
    debug_only(arg_type_klass = (klassOop) NULL);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   555
    _outgoing.at_put(argp, make_state(arg_type, arg));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   556
    if (type2size[arg_type] == 2) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   557
      // add the extra slot, so we can model the JVM stack
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   558
      _outgoing.insert_before(argp+1, make_state(T_VOID, ArgToken(tt_void)));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   559
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   560
    --argp;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   561
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   562
  // 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
   563
  klassOop  ret_type_klass = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   564
  BasicType ret_type = java_lang_Class::as_BasicType(
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   565
              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
   566
  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
   567
  // ignore ret; client can catch it if needed
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   568
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   569
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   570
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   571
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   572
// MethodHandleWalker::change_argument
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   573
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   574
// 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
   575
// companion slots containing an empty value.
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   576
void MethodHandleWalker::change_argument(BasicType old_type, int slot, BasicType new_type,
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   577
                                         const ArgToken& new_arg) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   578
  int old_size = type2size[old_type];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   579
  int new_size = type2size[new_type];
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   580
  if (old_size == new_size) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   581
    // simple case first
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   582
    _outgoing.at_put(slot, make_state(new_type, new_arg));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   583
  } else if (old_size > new_size) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   584
    for (int i = old_size - 1; i >= new_size; i--) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   585
      assert((i != 0) == (_outgoing.at(slot + i)._type == T_VOID), "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   586
      _outgoing.remove_at(slot + i);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   587
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   588
    if (new_size > 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   589
      _outgoing.at_put(slot, make_state(new_type, new_arg));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   590
    else
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   591
      _outgoing_argc -= 1;      // deleted a real argument
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   592
  } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   593
    for (int i = old_size; i < new_size; i++) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   594
      _outgoing.insert_before(slot + i, make_state(T_VOID, ArgToken(tt_void)));
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   595
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   596
    _outgoing.at_put(slot, make_state(new_type, new_arg));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   597
    if (old_size == 0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   598
      _outgoing_argc += 1;      // inserted a real argument
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   599
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   600
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   601
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   602
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   603
#ifdef ASSERT
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   604
int MethodHandleWalker::argument_count_slow() {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   605
  int args_seen = 0;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   606
  for (int i = _outgoing.length() - 1; i >= 0; i--) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   607
    if (_outgoing.at(i)._type != T_VOID) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   608
      ++args_seen;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   609
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   610
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   611
  return args_seen;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   612
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   613
#endif
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   614
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   615
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   616
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   617
// MethodHandleCompiler
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   618
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   619
MethodHandleCompiler::MethodHandleCompiler(Handle root, methodHandle callee, bool is_invokedynamic, TRAPS)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   620
  : MethodHandleWalker(root, is_invokedynamic, THREAD),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   621
    _callee(callee),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   622
    _thread(THREAD),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   623
    _bytecode(THREAD, 50),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   624
    _constants(THREAD, 10),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   625
    _cur_stack(0),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   626
    _max_stack(0),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   627
    _rtype(T_ILLEGAL)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   628
{
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   629
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   630
  // Element zero is always the null constant.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   631
  (void) _constants.append(NULL);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   632
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   633
  // Set name and signature index.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   634
  _name_index      = cpool_symbol_put(_callee->name());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   635
  _signature_index = cpool_symbol_put(_callee->signature());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   636
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   637
  // Get return type klass.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   638
  Handle first_mtype(THREAD, chain().method_type_oop());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   639
  // _rklass is NULL for primitives.
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   640
  _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
   641
  if (_rtype == T_ARRAY)  _rtype = T_OBJECT;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   642
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   643
  int params = _callee->size_of_parameters();  // Incoming arguments plus receiver.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   644
  _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
   645
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   646
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   647
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   648
// -----------------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   649
// MethodHandleCompiler::compile
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   650
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   651
// Compile this MethodHandle into a bytecode adapter and return a
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   652
// methodOop.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   653
methodHandle MethodHandleCompiler::compile(TRAPS) {
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   654
  assert(_thread == THREAD, "must be same thread");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   655
  methodHandle nullHandle;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   656
  (void) walk(CHECK_(nullHandle));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   657
  return get_method_oop(CHECK_(nullHandle));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   658
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   659
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   660
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   661
void MethodHandleCompiler::emit_bc(Bytecodes::Code op, int index) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   662
  Bytecodes::check(op);  // Are we legal?
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   663
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   664
  switch (op) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   665
  // b
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   666
  case Bytecodes::_aconst_null:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   667
  case Bytecodes::_iconst_m1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   668
  case Bytecodes::_iconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   669
  case Bytecodes::_iconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   670
  case Bytecodes::_iconst_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   671
  case Bytecodes::_iconst_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   672
  case Bytecodes::_iconst_4:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   673
  case Bytecodes::_iconst_5:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   674
  case Bytecodes::_lconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   675
  case Bytecodes::_lconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   676
  case Bytecodes::_fconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   677
  case Bytecodes::_fconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   678
  case Bytecodes::_fconst_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   679
  case Bytecodes::_dconst_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   680
  case Bytecodes::_dconst_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   681
  case Bytecodes::_iload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   682
  case Bytecodes::_iload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   683
  case Bytecodes::_iload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   684
  case Bytecodes::_iload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   685
  case Bytecodes::_lload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   686
  case Bytecodes::_lload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   687
  case Bytecodes::_lload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   688
  case Bytecodes::_lload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   689
  case Bytecodes::_fload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   690
  case Bytecodes::_fload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   691
  case Bytecodes::_fload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   692
  case Bytecodes::_fload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   693
  case Bytecodes::_dload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   694
  case Bytecodes::_dload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   695
  case Bytecodes::_dload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   696
  case Bytecodes::_dload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   697
  case Bytecodes::_aload_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   698
  case Bytecodes::_aload_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   699
  case Bytecodes::_aload_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   700
  case Bytecodes::_aload_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   701
  case Bytecodes::_istore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   702
  case Bytecodes::_istore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   703
  case Bytecodes::_istore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   704
  case Bytecodes::_istore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   705
  case Bytecodes::_lstore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   706
  case Bytecodes::_lstore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   707
  case Bytecodes::_lstore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   708
  case Bytecodes::_lstore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   709
  case Bytecodes::_fstore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   710
  case Bytecodes::_fstore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   711
  case Bytecodes::_fstore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   712
  case Bytecodes::_fstore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   713
  case Bytecodes::_dstore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   714
  case Bytecodes::_dstore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   715
  case Bytecodes::_dstore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   716
  case Bytecodes::_dstore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   717
  case Bytecodes::_astore_0:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   718
  case Bytecodes::_astore_1:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   719
  case Bytecodes::_astore_2:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   720
  case Bytecodes::_astore_3:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   721
  case Bytecodes::_i2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   722
  case Bytecodes::_i2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   723
  case Bytecodes::_i2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   724
  case Bytecodes::_i2b:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   725
  case Bytecodes::_i2c:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   726
  case Bytecodes::_i2s:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   727
  case Bytecodes::_l2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   728
  case Bytecodes::_l2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   729
  case Bytecodes::_l2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   730
  case Bytecodes::_f2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   731
  case Bytecodes::_f2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   732
  case Bytecodes::_f2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   733
  case Bytecodes::_d2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   734
  case Bytecodes::_d2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   735
  case Bytecodes::_d2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   736
  case Bytecodes::_ireturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   737
  case Bytecodes::_lreturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   738
  case Bytecodes::_freturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   739
  case Bytecodes::_dreturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   740
  case Bytecodes::_areturn:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   741
  case Bytecodes::_return:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
   742
    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
   743
    _bytecode.push(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   744
    break;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   745
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   746
  // bi
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   747
  case Bytecodes::_ldc:
6064
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   748
    assert(Bytecodes::format_bits(op, false) == (Bytecodes::_fmt_b|Bytecodes::_fmt_has_k), "wrong bytecode format");
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   749
    assert((char) index == index, "index does not fit in 8-bit");
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   750
    _bytecode.push(op);
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   751
    _bytecode.push(index);
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   752
    break;
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   753
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   754
  case Bytecodes::_iload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   755
  case Bytecodes::_lload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   756
  case Bytecodes::_fload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   757
  case Bytecodes::_dload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   758
  case Bytecodes::_aload:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   759
  case Bytecodes::_istore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   760
  case Bytecodes::_lstore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   761
  case Bytecodes::_fstore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   762
  case Bytecodes::_dstore:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   763
  case Bytecodes::_astore:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
   764
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_bi, "wrong bytecode format");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   765
    assert((char) index == index, "index does not fit in 8-bit");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   766
    _bytecode.push(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   767
    _bytecode.push(index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   768
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   769
6064
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   770
  // bkk
71e316283a85 6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents: 5702
diff changeset
   771
  case Bytecodes::_ldc_w:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   772
  case Bytecodes::_ldc2_w:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   773
  case Bytecodes::_checkcast:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
   774
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_bkk, "wrong bytecode format");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   775
    assert((short) index == index, "index does not fit in 16-bit");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   776
    _bytecode.push(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   777
    _bytecode.push(index >> 8);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   778
    _bytecode.push(index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   779
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   780
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
   781
  // bJJ
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   782
  case Bytecodes::_invokestatic:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   783
  case Bytecodes::_invokespecial:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   784
  case Bytecodes::_invokevirtual:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 5420
diff changeset
   785
    assert(Bytecodes::format_bits(op, false) == Bytecodes::_fmt_bJJ, "wrong bytecode format");
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   786
    assert((short) index == index, "index does not fit in 16-bit");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   787
    _bytecode.push(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   788
    _bytecode.push(index >> 8);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   789
    _bytecode.push(index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   790
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   791
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   792
  default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   793
    ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   794
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   795
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   796
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   797
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   798
void MethodHandleCompiler::emit_load(BasicType bt, int index) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   799
  if (index <= 3) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   800
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   801
    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
   802
    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
   803
    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
   804
    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
   805
    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
   806
    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
   807
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   808
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   809
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   810
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   811
  else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   812
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   813
    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
   814
    case T_INT:    emit_bc(Bytecodes::_iload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   815
    case T_LONG:   emit_bc(Bytecodes::_lload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   816
    case T_FLOAT:  emit_bc(Bytecodes::_fload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   817
    case T_DOUBLE: emit_bc(Bytecodes::_dload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   818
    case T_OBJECT: emit_bc(Bytecodes::_aload, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   819
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   820
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   821
    }
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   822
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   823
  stack_push(bt);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   824
}
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   825
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   826
void MethodHandleCompiler::emit_store(BasicType bt, int index) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   827
  if (index <= 3) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   828
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   829
    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
   830
    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
   831
    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
   832
    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
   833
    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
   834
    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
   835
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   836
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   837
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   838
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   839
  else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   840
    switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   841
    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
   842
    case T_INT:    emit_bc(Bytecodes::_istore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   843
    case T_LONG:   emit_bc(Bytecodes::_lstore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   844
    case T_FLOAT:  emit_bc(Bytecodes::_fstore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   845
    case T_DOUBLE: emit_bc(Bytecodes::_dstore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   846
    case T_OBJECT: emit_bc(Bytecodes::_astore, index); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   847
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   848
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   849
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   850
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   851
  stack_pop(bt);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   852
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   853
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   854
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   855
void MethodHandleCompiler::emit_load_constant(ArgToken arg) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   856
  BasicType bt = arg.basic_type();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   857
  switch (bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   858
  case T_INT: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   859
    jint value = arg.get_jint();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   860
    if (-1 <= value && value <= 5)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   861
      emit_bc(Bytecodes::cast(Bytecodes::_iconst_0 + value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   862
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   863
      emit_bc(Bytecodes::_ldc, cpool_int_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   864
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   865
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   866
  case T_LONG: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   867
    jlong value = arg.get_jlong();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   868
    if (0 <= value && value <= 1)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   869
      emit_bc(Bytecodes::cast(Bytecodes::_lconst_0 + (int) value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   870
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   871
      emit_bc(Bytecodes::_ldc2_w, cpool_long_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   872
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   873
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   874
  case T_FLOAT: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   875
    jfloat value  = arg.get_jfloat();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   876
    if (value == 0.0 || value == 1.0 || value == 2.0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   877
      emit_bc(Bytecodes::cast(Bytecodes::_fconst_0 + (int) value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   878
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   879
      emit_bc(Bytecodes::_ldc, cpool_float_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   880
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   881
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   882
  case T_DOUBLE: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   883
    jdouble value = arg.get_jdouble();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   884
    if (value == 0.0 || value == 1.0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   885
      emit_bc(Bytecodes::cast(Bytecodes::_dconst_0 + (int) value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   886
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   887
      emit_bc(Bytecodes::_ldc2_w, cpool_double_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   888
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   889
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   890
  case T_OBJECT: {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   891
    Handle value = arg.object();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   892
    if (value.is_null())
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   893
      emit_bc(Bytecodes::_aconst_null);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   894
    else
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   895
      emit_bc(Bytecodes::_ldc, cpool_object_put(value));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   896
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   897
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   898
  default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   899
    ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   900
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   901
  stack_push(bt);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   902
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   903
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   904
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   905
MethodHandleWalker::ArgToken
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   906
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
   907
                                      const ArgToken& src, TRAPS) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   908
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   909
  BasicType srctype = src.basic_type();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   910
  int index = src.index();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   911
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   912
  switch (op) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   913
  case Bytecodes::_i2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   914
  case Bytecodes::_i2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   915
  case Bytecodes::_i2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   916
  case Bytecodes::_i2b:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   917
  case Bytecodes::_i2c:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   918
  case Bytecodes::_i2s:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   919
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   920
  case Bytecodes::_l2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   921
  case Bytecodes::_l2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   922
  case Bytecodes::_l2d:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   923
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   924
  case Bytecodes::_f2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   925
  case Bytecodes::_f2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   926
  case Bytecodes::_f2d:
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
  case Bytecodes::_d2i:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   929
  case Bytecodes::_d2l:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   930
  case Bytecodes::_d2f:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   931
    emit_load(srctype, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   932
    stack_pop(srctype);  // pop the src type
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   933
    emit_bc(op);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   934
    stack_push(type);    // push the dest value
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   935
    if (srctype != type)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   936
      index = new_local_index(type);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   937
    emit_store(type, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   938
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   939
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   940
  case Bytecodes::_checkcast:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   941
    emit_load(srctype, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   942
    emit_bc(op, cpool_klass_put(tk));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   943
    emit_store(srctype, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   944
    break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   945
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   946
  default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   947
    ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   948
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   949
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   950
  return make_parameter(type, tk, index, THREAD);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   951
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   952
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   953
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
// MethodHandleCompiler
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
static jvalue zero_jvalue;
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
// Emit bytecodes for the given invoke instruction.
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   961
MethodHandleWalker::ArgToken
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   962
MethodHandleCompiler::make_invoke(methodOop m, vmIntrinsics::ID iid,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   963
                                  Bytecodes::Code op, bool tailcall,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   964
                                  int argc, MethodHandleWalker::ArgToken* argv,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
   965
                                  TRAPS) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   966
  if (m == NULL) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   967
    // Get the intrinsic methodOop.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   968
    m = vmIntrinsics::method_for(iid);
8675
e9fef2a9bef7 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8296
diff changeset
   969
    if (m == NULL) {
e9fef2a9bef7 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8296
diff changeset
   970
      ArgToken zero;
e9fef2a9bef7 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8296
diff changeset
   971
      lose(vmIntrinsics::name_at(iid), CHECK_(zero));
e9fef2a9bef7 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8296
diff changeset
   972
    }
4567
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
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
   975
  klassOop  klass   = m->method_holder();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
   976
  Symbol* name      = m->name();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
   977
  Symbol* signature = m->signature();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   978
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   979
  if (tailcall) {
4581
e89fbd1bcb3d 6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents: 4571
diff changeset
   980
    // Actually, in order to make these methods more recognizable,
7426
dba53a0065f8 7001363: java/dyn/InvokeDynamic should not be a well-known class in the JVM
twisti
parents: 7397
diff changeset
   981
    // let's put them in holder class MethodHandle.  That way stack
dba53a0065f8 7001363: java/dyn/InvokeDynamic should not be a well-known class in the JVM
twisti
parents: 7397
diff changeset
   982
    // walkers and compiler heuristics can recognize them.
dba53a0065f8 7001363: java/dyn/InvokeDynamic should not be a well-known class in the JVM
twisti
parents: 7397
diff changeset
   983
    _target_klass = SystemDictionary::MethodHandle_klass();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   984
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   985
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   986
  // Inline the method.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   987
  InvocationCounter* ic = m->invocation_counter();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6064
diff changeset
   988
  ic->set_carry_flag();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   989
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   990
  for (int i = 0; i < argc; i++) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   991
    ArgToken arg = argv[i];
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   992
    TokenType tt = arg.token_type();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   993
    BasicType bt = arg.basic_type();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   994
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   995
    switch (tt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   996
    case tt_parameter:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   997
    case tt_temporary:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   998
      emit_load(bt, arg.index());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
   999
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1000
    case tt_constant:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1001
      emit_load_constant(arg);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1002
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1003
    case tt_illegal:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1004
      // Sentinel.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1005
      assert(i == (argc - 1), "sentinel must be last entry");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1006
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1007
    case tt_void:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1008
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1009
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1010
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1011
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1012
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1013
  // Populate constant pool.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1014
  int name_index          = cpool_symbol_put(name);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1015
  int signature_index     = cpool_symbol_put(signature);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1016
  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
  1017
  int klass_index         = cpool_klass_put(klass);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1018
  int methodref_index     = cpool_methodref_put(klass_index, name_and_type_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1019
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1020
  // Generate invoke.
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1021
  switch (op) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1022
  case Bytecodes::_invokestatic:
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1023
  case Bytecodes::_invokespecial:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1024
  case Bytecodes::_invokevirtual:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1025
    emit_bc(op, methodref_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1026
    break;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1027
  case Bytecodes::_invokeinterface:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1028
    Unimplemented();
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1029
    break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1030
  default:
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1031
    ShouldNotReachHere();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1032
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1033
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1034
  // 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
  1035
  // Otherwise, make a recursive call to some helper routine.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1036
  BasicType rbt = m->result_type();
4581
e89fbd1bcb3d 6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents: 4571
diff changeset
  1037
  if (rbt == T_ARRAY)  rbt = T_OBJECT;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1038
  ArgToken ret;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1039
  if (tailcall) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1040
    if (rbt != _rtype) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1041
      if (rbt == T_VOID) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1042
        // push a zero of the right sort
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1043
        ArgToken zero;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1044
        if (_rtype == T_OBJECT) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1045
          zero = make_oop_constant(NULL, CHECK_(zero));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1046
        } else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1047
          zero = make_prim_constant(_rtype, &zero_jvalue, CHECK_(zero));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1048
        }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1049
        emit_load_constant(zero);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1050
      } else if (_rtype == T_VOID) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1051
        // We'll emit a _return with something on the stack.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1052
        // It's OK to ignore what's on the stack.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1053
      } else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1054
        tty->print_cr("*** rbt=%d != rtype=%d", rbt, _rtype);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1055
        assert(false, "IMPLEMENT ME");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1056
      }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1057
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1058
    switch (_rtype) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1059
    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
  1060
    case T_INT:    emit_bc(Bytecodes::_ireturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1061
    case T_LONG:   emit_bc(Bytecodes::_lreturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1062
    case T_FLOAT:  emit_bc(Bytecodes::_freturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1063
    case T_DOUBLE: emit_bc(Bytecodes::_dreturn); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1064
    case T_VOID:   emit_bc(Bytecodes::_return);  break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1065
    case T_OBJECT:
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4567
diff changeset
  1066
      if (_rklass.not_null() && _rklass() != SystemDictionary::Object_klass())
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1067
        emit_bc(Bytecodes::_checkcast, cpool_klass_put(_rklass()));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1068
      emit_bc(Bytecodes::_areturn);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1069
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1070
    default: ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1071
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1072
    ret = ArgToken();  // Dummy return value.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1073
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1074
  else {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1075
    stack_push(rbt);  // The return value is already pushed onto the stack.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1076
    int index = new_local_index(rbt);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1077
    switch (rbt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1078
    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
  1079
    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
  1080
    case T_OBJECT:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1081
      emit_store(rbt, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1082
      ret = ArgToken(tt_temporary, rbt, index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1083
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1084
    case T_VOID:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1085
      ret = ArgToken(tt_void);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1086
      break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1087
    default:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1088
      ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1089
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1090
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1091
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1092
  return ret;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1093
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1094
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1095
MethodHandleWalker::ArgToken
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1096
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
  1097
                                 const MethodHandleWalker::ArgToken& base,
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1098
                                 const MethodHandleWalker::ArgToken& offset,
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1099
                                 TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1100
  Unimplemented();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1101
  return ArgToken();
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1102
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1103
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1104
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1105
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
  1106
  jvalue con_copy;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1107
  assert(bt < T_OBJECT, "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1108
  if (type2aelembytes(bt) < jintSize) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1109
    // widen to int
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1110
    con_copy = (*con);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1111
    con = &con_copy;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1112
    switch (bt) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1113
    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
  1114
    case T_BYTE:    con->i = con->b;           break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1115
    case T_CHAR:    con->i = con->c;           break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1116
    case T_SHORT:   con->i = con->s;           break;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1117
    default: ShouldNotReachHere();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1118
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1119
    bt = T_INT;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1120
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1121
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1122
//   for (int i = 1, imax = _constants.length(); i < imax; i++) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1123
//     ConstantValue* con = _constants.at(i);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1124
//     if (con != NULL && con->is_primitive() && con->_type == bt) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1125
//       bool match = false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1126
//       switch (type2size[bt]) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1127
//       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
  1128
//       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
  1129
//       }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1130
//       if (match)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1131
//         return i;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1132
//     }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1133
//   }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1134
  ConstantValue* cv = new ConstantValue(bt, *con);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1135
  int index = _constants.append(cv);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1136
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1137
  // 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
  1138
  if (type2size[bt] == 2)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1139
    (void) _constants.append(NULL);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1140
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1141
  return index;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1142
}
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
constantPoolHandle MethodHandleCompiler::get_constant_pool(TRAPS) const {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1146
  constantPoolHandle nullHandle;
8296
b1c2163e4e59 6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents: 8076
diff changeset
  1147
  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
  1148
                                                           oopDesc::IsSafeConc,
b1c2163e4e59 6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents: 8076
diff changeset
  1149
                                                           CHECK_(nullHandle));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1150
  constantPoolHandle cpool(THREAD, cpool_oop);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1151
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1152
  // Fill the real constant pool skipping the zero element.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1153
  for (int i = 1; i < _constants.length(); i++) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1154
    ConstantValue* cv = _constants.at(i);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1155
    switch (cv->tag()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
  1156
    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
  1157
    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
  1158
    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
  1159
    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
  1160
    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
  1161
    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
  1162
    case JVM_CONSTANT_Methodref:   cpool->method_at_put(       i, cv->first_index(), cv->second_index()); break;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1163
    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
  1164
    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
  1165
    default: ShouldNotReachHere();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1166
    }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1167
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1168
    switch (cv->tag()) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1169
    case JVM_CONSTANT_Long:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1170
    case JVM_CONSTANT_Double:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1171
      i++;  // Skip empty entry.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1172
      assert(_constants.at(i) == NULL, "empty entry");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1173
      break;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1174
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1175
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1176
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1177
  // 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
  1178
  cpool->set_pool_holder(_target_klass());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1179
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1180
  return cpool;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1181
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1182
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1183
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1184
methodHandle MethodHandleCompiler::get_method_oop(TRAPS) const {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1185
  methodHandle nullHandle;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1186
  // Create a method that holds the generated bytecode.  invokedynamic
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1187
  // has no receiver, normal MH calls do.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1188
  int flags_bits;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1189
  if (for_invokedynamic())
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4581
diff changeset
  1190
    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
  1191
  else
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4581
diff changeset
  1192
    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
  1193
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1194
  methodOop m_oop = oopFactory::new_method(bytecode_length(),
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1195
                                           accessFlags_from(flags_bits),
8296
b1c2163e4e59 6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents: 8076
diff changeset
  1196
                                           0, 0, 0, oopDesc::IsSafeConc, CHECK_(nullHandle));
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1197
  methodHandle m(THREAD, m_oop);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1198
  m_oop = NULL;  // oop not GC safe
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1199
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1200
  constantPoolHandle cpool = get_constant_pool(CHECK_(nullHandle));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1201
  m->set_constants(cpool());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1202
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1203
  m->set_name_index(_name_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1204
  m->set_signature_index(_signature_index);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1205
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1206
  m->set_code((address) bytecode());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1207
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1208
  m->set_max_stack(_max_stack);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1209
  m->set_max_locals(max_locals());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1210
  m->set_size_of_parameters(_num_params);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1211
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1212
  typeArrayHandle exception_handlers(THREAD, Universe::the_empty_int_array());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1213
  m->set_exception_table(exception_handlers());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1214
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1215
  // Set the carry bit of the invocation counter to force inlining of
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1216
  // the adapter.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1217
  InvocationCounter* ic = m->invocation_counter();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6064
diff changeset
  1218
  ic->set_carry_flag();
4567
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
  // Rewrite the method and set up the constant pool cache.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1221
  objArrayOop m_array = oopFactory::new_system_objArray(1, CHECK_(nullHandle));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1222
  objArrayHandle methods(THREAD, m_array);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1223
  methods->obj_at_put(0, m());
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1224
  Rewriter::rewrite(_target_klass(), cpool, methods, CHECK_(nullHandle));  // Use fake class.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1225
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1226
#ifndef PRODUCT
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1227
  if (TraceMethodHandles) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1228
    m->print();
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1229
    m->print_codes();
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
#endif //PRODUCT
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1232
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4581
diff changeset
  1233
  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
  1234
  return m;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1235
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1236
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1237
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1238
#ifndef PRODUCT
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1239
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1240
#if 0
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1241
// MH printer for debugging.
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1242
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1243
class MethodHandlePrinter : public MethodHandleWalker {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1244
private:
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1245
  outputStream* _out;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1246
  bool          _verbose;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1247
  int           _temp_num;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1248
  stringStream  _strbuf;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1249
  const char* strbuf() {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1250
    const char* s = _strbuf.as_string();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1251
    _strbuf.reset();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1252
    return s;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1253
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1254
  ArgToken token(const char* str) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1255
    return (ArgToken) str;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1256
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1257
  void start_params() {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1258
    _out->print("(");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1259
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1260
  void end_params() {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1261
    if (_verbose)  _out->print("\n");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1262
    _out->print(") => {");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1263
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1264
  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
  1265
    const char* kname = NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1266
    if (tk != NULL)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1267
      kname = Klass::cast(tk)->external_name();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1268
    s->print("%s", (kname != NULL) ? kname : type2name(type));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1269
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1270
  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
  1271
    const char* value = strbuf();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1272
    if (!_verbose)  return token(value);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1273
    // make an explicit binding for each separate value
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1274
    _strbuf.print("%s%d", temp_name, ++_temp_num);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1275
    const char* temp = strbuf();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1276
    _out->print("\n  %s %s %s = %s;", statement_op, type2name(type), temp, value);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1277
    return token(temp);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1278
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1279
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1280
public:
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1281
  MethodHandlePrinter(Handle root, bool verbose, outputStream* out, TRAPS)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1282
    : MethodHandleWalker(root, THREAD),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1283
      _out(out),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1284
      _verbose(verbose),
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1285
      _temp_num(0)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1286
  {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1287
    start_params();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1288
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1289
  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
  1290
    if (argnum < 0) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1291
      end_params();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1292
      return NULL;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1293
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1294
    if (argnum == 0) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1295
      _out->print(_verbose ? "\n  " : "");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1296
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1297
      _out->print(_verbose ? ",\n  " : ", ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1298
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1299
    if (argnum >= _temp_num)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1300
      _temp_num = argnum;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1301
    // generate an argument name
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1302
    _strbuf.print("a%d", argnum);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1303
    const char* arg = strbuf();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1304
    put_type_name(type, tk, _out);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1305
    _out->print(" %s", arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1306
    return token(arg);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1307
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1308
  virtual ArgToken make_oop_constant(oop con, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1309
    if (con == NULL)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1310
      _strbuf.print("null");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1311
    else
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1312
      con->print_value_on(&_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1313
    if (_strbuf.size() == 0) {  // yuck
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1314
      _strbuf.print("(a ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1315
      put_type_name(T_OBJECT, con->klass(), &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1316
      _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1317
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1318
    return maybe_make_temp("constant", T_OBJECT, "k");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1319
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1320
  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
  1321
    java_lang_boxing_object::print(type, con, &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1322
    return maybe_make_temp("constant", type, "k");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1323
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1324
  virtual ArgToken make_conversion(BasicType type, klassOop tk, Bytecodes::Code op, ArgToken src, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1325
    _strbuf.print("%s(%s", Bytecodes::name(op), (const char*)src);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1326
    if (tk != NULL) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1327
      _strbuf.print(", ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1328
      put_type_name(type, tk, &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1329
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1330
    _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1331
    return maybe_make_temp("convert", type, "v");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1332
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1333
  virtual ArgToken make_fetch(BasicType type, klassOop tk, Bytecodes::Code op, ArgToken base, ArgToken offset, TRAPS) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1334
    _strbuf.print("%s(%s, %s", Bytecodes::name(op), (const char*)base, (const char*)offset);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1335
    if (tk != NULL) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1336
      _strbuf.print(", ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1337
      put_type_name(type, tk, &_strbuf);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1338
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1339
    _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1340
    return maybe_make_temp("fetch", type, "x");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1341
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1342
  virtual ArgToken make_invoke(methodOop m, vmIntrinsics::ID iid,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1343
                               Bytecodes::Code op, bool tailcall,
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1344
                               int argc, ArgToken* argv, TRAPS) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7888
diff changeset
  1345
    Symbol* name, sig;
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1346
    if (m != NULL) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1347
      name = m->name();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1348
      sig  = m->signature();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1349
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1350
      name = vmSymbols::symbol_at(vmIntrinsics::name_for(iid));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1351
      sig  = vmSymbols::symbol_at(vmIntrinsics::signature_for(iid));
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1352
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1353
    _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
  1354
    for (int i = 0; i < argc; i++) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1355
      _strbuf.print("%s%s", (i > 0 ? ", " : ""), (const char*)argv[i]);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1356
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1357
    _strbuf.print(")");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1358
    if (!tailcall) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1359
      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
  1360
      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
  1361
      return maybe_make_temp("invoke", rt, "x");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1362
    } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1363
      const char* ret = strbuf();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1364
      _out->print(_verbose ? "\n  return " : " ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1365
      _out->print("%s", ret);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1366
      _out->print(_verbose ? "\n}\n" : " }");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1367
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1368
    return ArgToken();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1369
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1370
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1371
  virtual void set_method_handle(oop mh) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1372
    if (WizardMode && Verbose) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1373
      tty->print("\n--- next target: ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1374
      mh->print();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1375
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1376
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1377
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1378
  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
  1379
    ResourceMark rm;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1380
    MethodHandlePrinter printer(root, verbose, out, CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1381
    printer.walk(CHECK);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1382
    out->print("\n");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1383
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1384
  static void print(Handle root, bool verbose = Verbose, outputStream* out = tty) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1385
    EXCEPTION_MARK;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1386
    ResourceMark rm;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1387
    MethodHandlePrinter printer(root, verbose, out, THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1388
    if (!HAS_PENDING_EXCEPTION)
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1389
      printer.walk(THREAD);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1390
    if (HAS_PENDING_EXCEPTION) {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1391
      oop ex = PENDING_EXCEPTION;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1392
      CLEAR_PENDING_EXCEPTION;
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1393
      out->print("\n*** ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1394
      if (ex != Universe::virtual_machine_error_instance())
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1395
        ex->print_on(out);
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1396
      else
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1397
        out->print("lose: %s", printer.lose_message());
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1398
      out->print("\n}\n");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1399
    }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1400
    out->print("\n");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1401
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1402
};
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1403
#endif // 0
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1404
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1405
extern "C"
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1406
void print_method_handle(oop mh) {
6463
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 6453
diff changeset
  1407
  if (!mh->is_oop()) {
f4362c8da849 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 6453
diff changeset
  1408
    tty->print_cr("*** not a method handle: "INTPTR_FORMAT, (intptr_t)mh);
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1409
  } else if (java_lang_invoke_MethodHandle::is_instance(mh)) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4562
diff changeset
  1410
    //MethodHandlePrinter::print(mh);
4562
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1411
  } else {
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1412
    tty->print("*** not a method handle: ");
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1413
    mh->print();
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1414
  }
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1415
}
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1416
5d93cb2d2090 6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff changeset
  1417
#endif // PRODUCT