hotspot/src/share/vm/prims/methodHandles.cpp
author tschatzl
Wed, 11 Sep 2013 16:25:02 +0200
changeset 19986 33d188c66ed9
parent 18508 3b95160639d8
child 20017 81eba62e9048
permissions -rw-r--r--
8010722: assert: failed: heap size is too big for compressed oops Summary: Use conservative assumptions of required alignment for the various garbage collector components into account when determining the maximum heap size that supports compressed oops. Using this conservative value avoids several circular dependencies in the calculation. Reviewed-by: stefank, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     1
/*
17828
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
     2
 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     4
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     7
 * published by the Free Software Foundation.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     8
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    13
 * accompanied this code).
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    14
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5421
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5421
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: 5421
diff changeset
    21
 * questions.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    22
 *
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    23
 */
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    26
#include "classfile/symbolTable.hpp"
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 10004
diff changeset
    27
#include "compiler/compileBroker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    28
#include "interpreter/interpreter.hpp"
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9638
diff changeset
    29
#include "interpreter/oopMapCache.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    30
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    31
#include "memory/oopFactory.hpp"
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
    32
#include "prims/jvmtiRedefineClassesTrace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    33
#include "prims/methodHandles.hpp"
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 10004
diff changeset
    34
#include "runtime/compilationPolicy.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    35
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    36
#include "runtime/reflection.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    37
#include "runtime/signature.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    38
#include "runtime/stubRoutines.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    39
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    40
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    41
/*
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    42
 * JSR 292 reference implementation: method handles
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    43
 * The JDK 7 reference implementation represented method handle
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    44
 * combinations as chains.  Each link in the chain had a "vmentry"
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    45
 * field which pointed at a bit of assembly code which performed
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    46
 * one transformation before dispatching to the next link in the chain.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    47
 *
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    48
 * The current reference implementation pushes almost all code generation
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    49
 * responsibility to (trusted) Java code.  A method handle contains a
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    50
 * pointer to its "LambdaForm", which embodies all details of the method
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    51
 * handle's behavior.  The LambdaForm is a normal Java object, managed
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    52
 * by a runtime coded in Java.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    53
 */
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    54
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    55
bool MethodHandles::_enabled = false; // set true after successful native linkage
9976
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9967
diff changeset
    56
MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL;
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    57
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    58
//------------------------------------------------------------------------------
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    59
// MethodHandles::generate_adapters
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    60
//
7887
7aa0354cbf25 7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents: 7712
diff changeset
    61
void MethodHandles::generate_adapters() {
8883
5569135acca3 6817525: turn on method handle functionality by default for JSR 292
twisti
parents: 8676
diff changeset
    62
  if (!EnableInvokeDynamic || SystemDictionary::MethodHandle_klass() == NULL)  return;
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    63
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    64
  assert(_adapter_code == NULL, "generate only once");
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    65
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    66
  ResourceMark rm;
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    67
  TraceTime timer("MethodHandles adapters generation", TraceStartupTime);
9976
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9967
diff changeset
    68
  _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size);
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    69
  if (_adapter_code == NULL)
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17033
diff changeset
    70
    vm_exit_out_of_memory(adapter_code_size, OOM_MALLOC_ERROR,
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17033
diff changeset
    71
                          "CodeCache: no room for MethodHandles adapters");
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10967
diff changeset
    72
  {
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10967
diff changeset
    73
    CodeBuffer code(_adapter_code);
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10967
diff changeset
    74
    MethodHandlesAdapterGenerator g(&code);
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10967
diff changeset
    75
    g.generate();
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10967
diff changeset
    76
    code.log_section_sizes("MethodHandlesAdapterBlob");
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10967
diff changeset
    77
  }
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    78
}
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    79
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    80
//------------------------------------------------------------------------------
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    81
// MethodHandlesAdapterGenerator::generate
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    82
//
7887
7aa0354cbf25 7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents: 7712
diff changeset
    83
void MethodHandlesAdapterGenerator::generate() {
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    84
  // Generate generic method handle adapters.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    85
  // Generate interpreter entries
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    86
  for (Interpreter::MethodKind mk = Interpreter::method_handle_invoke_FIRST;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    87
       mk <= Interpreter::method_handle_invoke_LAST;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    88
       mk = Interpreter::MethodKind(1 + (int)mk)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    89
    vmIntrinsics::ID iid = Interpreter::method_handle_intrinsic(mk);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    90
    StubCodeMark mark(this, "MethodHandle::interpreter_entry", vmIntrinsics::name_at(iid));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    91
    address entry = MethodHandles::generate_method_handle_interpreter_entry(_masm, iid);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    92
    if (entry != NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    93
      Interpreter::set_entry_for_kind(mk, entry);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
    94
    }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    95
    // If the entry is not set, it will throw AbstractMethodError.
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    96
  }
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    97
}
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    98
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    99
void MethodHandles::set_enabled(bool z) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   100
  if (_enabled != z) {
8883
5569135acca3 6817525: turn on method handle functionality by default for JSR 292
twisti
parents: 8676
diff changeset
   101
    guarantee(z && EnableInvokeDynamic, "can only enable once, and only if -XX:+EnableInvokeDynamic");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   102
    _enabled = z;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   103
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   104
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   105
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   106
// MemberName support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   107
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   108
// import java_lang_invoke_MemberName.*
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   109
enum {
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   110
  IS_METHOD            = java_lang_invoke_MemberName::MN_IS_METHOD,
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   111
  IS_CONSTRUCTOR       = java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR,
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   112
  IS_FIELD             = java_lang_invoke_MemberName::MN_IS_FIELD,
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   113
  IS_TYPE              = java_lang_invoke_MemberName::MN_IS_TYPE,
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   114
  CALLER_SENSITIVE     = java_lang_invoke_MemberName::MN_CALLER_SENSITIVE,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   115
  REFERENCE_KIND_SHIFT = java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   116
  REFERENCE_KIND_MASK  = java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK,
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   117
  SEARCH_SUPERCLASSES  = java_lang_invoke_MemberName::MN_SEARCH_SUPERCLASSES,
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   118
  SEARCH_INTERFACES    = java_lang_invoke_MemberName::MN_SEARCH_INTERFACES,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   119
  ALL_KINDS      = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   120
};
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   121
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
   122
Handle MethodHandles::new_MemberName(TRAPS) {
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
   123
  Handle empty;
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
   124
  instanceKlassHandle k(THREAD, SystemDictionary::MemberName_klass());
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
   125
  if (!k->is_initialized())  k->initialize(CHECK_(empty));
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
   126
  return Handle(THREAD, k->allocate_instance(THREAD));
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
   127
}
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
   128
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   129
oop MethodHandles::init_MemberName(Handle mname, Handle target) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   130
  Thread* thread = Thread::current();
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   131
  oop target_oop = target();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   132
  Klass* target_klass = target_oop->klass();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   133
  if (target_klass == SystemDictionary::reflect_Field_klass()) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   134
    oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder()
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   135
    int slot  = java_lang_reflect_Field::slot(target_oop);  // fd.index()
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   136
    int mods  = java_lang_reflect_Field::modifiers(target_oop);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   137
    oop type  = java_lang_reflect_Field::type(target_oop);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   138
    oop name  = java_lang_reflect_Field::name(target_oop);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   139
    KlassHandle k(thread, java_lang_Class::as_Klass(clazz));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   140
    intptr_t offset = InstanceKlass::cast(k())->field_offset(slot);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   141
    return init_field_MemberName(mname, k, accessFlags_from(mods), type, name, offset);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   142
  } else if (target_klass == SystemDictionary::reflect_Method_klass()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   143
    oop clazz  = java_lang_reflect_Method::clazz(target_oop);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   144
    int slot   = java_lang_reflect_Method::slot(target_oop);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   145
    KlassHandle k(thread, java_lang_Class::as_Klass(clazz));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   146
    if (!k.is_null() && k->oop_is_instance()) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   147
      Method* m = InstanceKlass::cast(k())->method_with_idnum(slot);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   148
      return init_method_MemberName(mname, m, true, k);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   149
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   150
  } else if (target_klass == SystemDictionary::reflect_Constructor_klass()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   151
    oop clazz  = java_lang_reflect_Constructor::clazz(target_oop);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   152
    int slot   = java_lang_reflect_Constructor::slot(target_oop);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   153
    KlassHandle k(thread, java_lang_Class::as_Klass(clazz));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   154
    if (!k.is_null() && k->oop_is_instance()) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   155
      Method* m = InstanceKlass::cast(k())->method_with_idnum(slot);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   156
      return init_method_MemberName(mname, m, false, k);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   157
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   158
  } else if (target_klass == SystemDictionary::MemberName_klass()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   159
    // Note: This only works if the MemberName has already been resolved.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   160
    oop clazz        = java_lang_invoke_MemberName::clazz(target_oop);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   161
    int flags        = java_lang_invoke_MemberName::flags(target_oop);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   162
    Metadata* vmtarget=java_lang_invoke_MemberName::vmtarget(target_oop);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   163
    intptr_t vmindex = java_lang_invoke_MemberName::vmindex(target_oop);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   164
    KlassHandle k(thread, java_lang_Class::as_Klass(clazz));
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   165
    int ref_kind     = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   166
    if (vmtarget == NULL)  return NULL;  // not resolved
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   167
    if ((flags & IS_FIELD) != 0) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   168
      assert(vmtarget->is_klass(), "field vmtarget is Klass*");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   169
      int basic_mods = (ref_kind_is_static(ref_kind) ? JVM_ACC_STATIC : 0);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   170
      // FIXME:  how does k (receiver_limit) contribute?
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   171
      KlassHandle k_vmtarget(thread, (Klass*)vmtarget);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   172
      return init_field_MemberName(mname, k_vmtarget, accessFlags_from(basic_mods), NULL, NULL, vmindex);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   173
    } else if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   174
      assert(vmtarget->is_method(), "method or constructor vmtarget is Method*");
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   175
      return init_method_MemberName(mname, (Method*)vmtarget, ref_kind_does_dispatch(ref_kind), k);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   176
    } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   177
      return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   178
    }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   179
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   180
  return NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   181
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   182
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   183
oop MethodHandles::init_method_MemberName(Handle mname, Method* m, bool do_dispatch,
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   184
                                          KlassHandle receiver_limit_h) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   185
  Klass* receiver_limit = receiver_limit_h();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   186
  AccessFlags mods = m->access_flags();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   187
  int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS );
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   188
  int vmindex = Method::nonvirtual_vtable_index; // implies never any dispatch
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   189
  Klass* mklass = m->method_holder();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   190
  if (receiver_limit == NULL)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   191
    receiver_limit = mklass;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   192
  if (m->is_initializer()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   193
    flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   194
  } else if (mods.is_static()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   195
    flags |= IS_METHOD | (JVM_REF_invokeStatic << REFERENCE_KIND_SHIFT);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   196
  } else if (receiver_limit != mklass &&
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   197
             !receiver_limit->is_subtype_of(mklass)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   198
    return NULL;  // bad receiver limit
17364
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   199
  } else if (do_dispatch && receiver_limit->is_interface() &&
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   200
             mklass->is_interface()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   201
    flags |= IS_METHOD | (JVM_REF_invokeInterface << REFERENCE_KIND_SHIFT);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   202
    receiver_limit = mklass;  // ignore passed-in limit; interfaces are interconvertible
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   203
    vmindex = klassItable::compute_itable_index(m);
17364
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   204
  } else if (do_dispatch && mklass != receiver_limit && mklass->is_interface()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   205
    flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   206
    // it is a miranda method, so m->vtable_index is not what we want
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   207
    ResourceMark rm;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   208
    klassVtable* vt = InstanceKlass::cast(receiver_limit)->vtable();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   209
    vmindex = vt->index_of_miranda(m->name(), m->signature());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   210
  } else if (!do_dispatch || m->can_be_statically_bound()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   211
    flags |= IS_METHOD | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   212
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   213
    flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   214
    vmindex = m->vtable_index();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   215
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   216
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   217
  // @CallerSensitive annotation detected
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   218
  if (m->caller_sensitive()) {
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   219
    flags |= CALLER_SENSITIVE;
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   220
  }
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   221
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   222
  oop mname_oop = mname();
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   223
  java_lang_invoke_MemberName::set_flags(   mname_oop, flags);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   224
  java_lang_invoke_MemberName::set_vmtarget(mname_oop, m);
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   225
  java_lang_invoke_MemberName::set_vmindex( mname_oop, vmindex);   // vtable/itable index
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   226
  java_lang_invoke_MemberName::set_clazz(   mname_oop, receiver_limit->java_mirror());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   227
  // Note:  name and type can be lazily computed by resolve_MemberName,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   228
  // if Java code needs them as resolved String and MethodType objects.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   229
  // The clazz must be eagerly stored, because it provides a GC
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   230
  // root to help keep alive the Method*.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   231
  // If relevant, the vtable or itable value is stored as vmindex.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   232
  // This is done eagerly, since it is readily available without
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   233
  // constructing any new objects.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   234
  // TO DO: maybe intern mname_oop
17828
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   235
  m->method_holder()->add_member_name(m->method_idnum(), mname);
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   236
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   237
  return mname();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   238
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   239
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   240
Handle MethodHandles::init_method_MemberName(Handle mname, CallInfo& info, TRAPS) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   241
  Handle empty;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   242
  if (info.resolved_appendix().not_null()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   243
    // The resolved MemberName must not be accompanied by an appendix argument,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   244
    // since there is no way to bind this value into the MemberName.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   245
    // Caller is responsible to prevent this from happening.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   246
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   247
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   248
  methodHandle m = info.resolved_method();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   249
  KlassHandle defc = info.resolved_klass();
17364
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   250
  int vmindex = Method::invalid_vtable_index;
14391
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 13973
diff changeset
   251
  if (defc->is_interface() && m->method_holder()->is_interface()) {
17364
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   252
    // static interface methods do not reference vtable or itable
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   253
    if (m->is_static()) {
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   254
      vmindex = Method::nonvirtual_vtable_index;
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   255
    }
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   256
    // interface methods invoked via invokespecial also
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   257
    // do not reference vtable or itable.
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   258
    int ref_kind = ((java_lang_invoke_MemberName::flags(mname()) >>
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   259
                     REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK);
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   260
    if (ref_kind == JVM_REF_invokeSpecial) {
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   261
      vmindex = Method::nonvirtual_vtable_index;
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   262
    }
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   263
    // If neither m is static nor ref_kind is invokespecial,
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   264
    // set it to itable index.
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   265
    if (vmindex == Method::invalid_vtable_index) {
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   266
      // LinkResolver does not report itable indexes!  (fix this?)
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   267
      vmindex = klassItable::compute_itable_index(m());
cf8b9767e64c 8013875: Incorrect vtable index being set during methodHandle creation for static
bharadwaj
parents: 17087
diff changeset
   268
    }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   269
  } else if (m->can_be_statically_bound()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   270
    // LinkResolver reports vtable index even for final methods!
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   271
    vmindex = Method::nonvirtual_vtable_index;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   272
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   273
    vmindex = info.vtable_index();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   274
  }
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   275
  oop res = init_method_MemberName(mname, m(), (vmindex >= 0), defc());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   276
  assert(res == NULL || (java_lang_invoke_MemberName::vmindex(res) == vmindex), "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   277
  return Handle(THREAD, res);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   278
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   279
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   280
oop MethodHandles::init_field_MemberName(Handle mname, KlassHandle field_holder,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   281
                                         AccessFlags mods, oop type, oop name,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   282
                                         intptr_t offset, bool is_setter) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   283
  int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS );
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   284
  flags |= IS_FIELD | ((mods.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   285
  if (is_setter)  flags += ((JVM_REF_putField - JVM_REF_getField) << REFERENCE_KIND_SHIFT);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   286
  Metadata* vmtarget = field_holder();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   287
  int vmindex  = offset;  // determines the field uniquely when combined with static bit
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   288
  oop mname_oop = mname();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   289
  java_lang_invoke_MemberName::set_flags(mname_oop,    flags);
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   290
  java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget);
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   291
  java_lang_invoke_MemberName::set_vmindex(mname_oop,  vmindex);
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   292
  java_lang_invoke_MemberName::set_clazz(mname_oop,    field_holder->java_mirror());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   293
  if (name != NULL)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   294
    java_lang_invoke_MemberName::set_name(mname_oop,   name);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   295
  if (type != NULL)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   296
    java_lang_invoke_MemberName::set_type(mname_oop,   type);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   297
  // Note:  name and type can be lazily computed by resolve_MemberName,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   298
  // if Java code needs them as resolved String and Class objects.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   299
  // Note that the incoming type oop might be pre-resolved (non-null).
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   300
  // The base clazz and field offset (vmindex) must be eagerly stored,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   301
  // because they unambiguously identify the field.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   302
  // Although the fieldDescriptor::_index would also identify the field,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   303
  // we do not use it, because it is harder to decode.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   304
  // TO DO: maybe intern mname_oop
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   305
  return mname();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   306
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   307
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   308
Handle MethodHandles::init_field_MemberName(Handle mname, FieldAccessInfo& info, TRAPS) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   309
  return Handle();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   310
#if 0 // FIXME
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   311
  KlassHandle field_holder = info.klass();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   312
  intptr_t    field_offset = info.field_offset();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   313
  return init_field_MemberName(mname_oop, field_holder(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   314
                               info.access_flags(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   315
                               type, name,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   316
                               field_offset, false /*is_setter*/);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   317
#endif
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   318
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   319
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   320
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   321
// JVM 2.9 Special Methods:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   322
// A method is signature polymorphic if and only if all of the following conditions hold :
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   323
// * It is declared in the java.lang.invoke.MethodHandle class.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   324
// * It has a single formal parameter of type Object[].
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   325
// * It has a return type of Object.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   326
// * It has the ACC_VARARGS and ACC_NATIVE flags set.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   327
bool MethodHandles::is_method_handle_invoke_name(Klass* klass, Symbol* name) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   328
  if (klass == NULL)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   329
    return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   330
  // The following test will fail spuriously during bootstrap of MethodHandle itself:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   331
  //    if (klass != SystemDictionary::MethodHandle_klass())
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   332
  // Test the name instead:
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   333
  if (klass->name() != vmSymbols::java_lang_invoke_MethodHandle())
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   334
    return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   335
  Symbol* poly_sig = vmSymbols::object_array_object_signature();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   336
  Method* m = InstanceKlass::cast(klass)->find_method(name, poly_sig);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   337
  if (m == NULL)  return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   338
  int required = JVM_ACC_NATIVE | JVM_ACC_VARARGS;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   339
  int flags = m->access_flags().as_int();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   340
  return (flags & required) == required;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   341
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   342
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   343
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   344
Symbol* MethodHandles::signature_polymorphic_intrinsic_name(vmIntrinsics::ID iid) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   345
  assert(is_signature_polymorphic_intrinsic(iid), err_msg("iid=%d", iid));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   346
  switch (iid) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   347
  case vmIntrinsics::_invokeBasic:      return vmSymbols::invokeBasic_name();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   348
  case vmIntrinsics::_linkToVirtual:    return vmSymbols::linkToVirtual_name();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   349
  case vmIntrinsics::_linkToStatic:     return vmSymbols::linkToStatic_name();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   350
  case vmIntrinsics::_linkToSpecial:    return vmSymbols::linkToSpecial_name();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   351
  case vmIntrinsics::_linkToInterface:  return vmSymbols::linkToInterface_name();
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
   352
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   353
  assert(false, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   354
  return 0;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   355
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   356
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   357
int MethodHandles::signature_polymorphic_intrinsic_ref_kind(vmIntrinsics::ID iid) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   358
  switch (iid) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   359
  case vmIntrinsics::_invokeBasic:      return 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   360
  case vmIntrinsics::_linkToVirtual:    return JVM_REF_invokeVirtual;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   361
  case vmIntrinsics::_linkToStatic:     return JVM_REF_invokeStatic;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   362
  case vmIntrinsics::_linkToSpecial:    return JVM_REF_invokeSpecial;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   363
  case vmIntrinsics::_linkToInterface:  return JVM_REF_invokeInterface;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   364
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   365
  assert(false, err_msg("iid=%d", iid));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   366
  return 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   367
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   368
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   369
vmIntrinsics::ID MethodHandles::signature_polymorphic_name_id(Symbol* name) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   370
  vmSymbols::SID name_id = vmSymbols::find_sid(name);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   371
  switch (name_id) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   372
  // The ID _invokeGeneric stands for all non-static signature-polymorphic methods, except built-ins.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   373
  case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name):           return vmIntrinsics::_invokeGeneric;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   374
  // The only built-in non-static signature-polymorphic method is MethodHandle.invokeBasic:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   375
  case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeBasic_name):      return vmIntrinsics::_invokeBasic;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   376
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   377
  // There is one static signature-polymorphic method for each JVM invocation mode.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   378
  case vmSymbols::VM_SYMBOL_ENUM_NAME(linkToVirtual_name):    return vmIntrinsics::_linkToVirtual;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   379
  case vmSymbols::VM_SYMBOL_ENUM_NAME(linkToStatic_name):     return vmIntrinsics::_linkToStatic;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   380
  case vmSymbols::VM_SYMBOL_ENUM_NAME(linkToSpecial_name):    return vmIntrinsics::_linkToSpecial;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   381
  case vmSymbols::VM_SYMBOL_ENUM_NAME(linkToInterface_name):  return vmIntrinsics::_linkToInterface;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   382
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   383
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   384
  // Cover the case of invokeExact and any future variants of invokeFoo.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   385
  Klass* mh_klass = SystemDictionary::well_known_klass(
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   386
                              SystemDictionary::WK_KLASS_ENUM_NAME(MethodHandle_klass) );
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   387
  if (mh_klass != NULL && is_method_handle_invoke_name(mh_klass, name))
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   388
    return vmIntrinsics::_invokeGeneric;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   389
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   390
  // Note: The pseudo-intrinsic _compiledLambdaForm is never linked against.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   391
  // Instead it is used to mark lambda forms bound to invokehandle or invokedynamic.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   392
  return vmIntrinsics::_none;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   393
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   394
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   395
vmIntrinsics::ID MethodHandles::signature_polymorphic_name_id(Klass* klass, Symbol* name) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   396
  if (klass != NULL &&
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   397
      klass->name() == vmSymbols::java_lang_invoke_MethodHandle()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   398
    vmIntrinsics::ID iid = signature_polymorphic_name_id(name);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   399
    if (iid != vmIntrinsics::_none)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   400
      return iid;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   401
    if (is_method_handle_invoke_name(klass, name))
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   402
      return vmIntrinsics::_invokeGeneric;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   403
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   404
  return vmIntrinsics::_none;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   405
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   406
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   407
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   408
// convert the external string or reflective type to an internal signature
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   409
Symbol* MethodHandles::lookup_signature(oop type_str, bool intern_if_not_found, TRAPS) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   410
  if (java_lang_invoke_MethodType::is_instance(type_str)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   411
    return java_lang_invoke_MethodType::as_signature(type_str, intern_if_not_found, CHECK_NULL);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   412
  } else if (java_lang_Class::is_instance(type_str)) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   413
    return java_lang_Class::as_signature(type_str, false, CHECK_NULL);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   414
  } else if (java_lang_String::is_instance(type_str)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   415
    if (intern_if_not_found) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   416
      return java_lang_String::as_symbol(type_str, CHECK_NULL);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   417
    } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   418
      return java_lang_String::as_symbol_or_null(type_str);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   419
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   420
  } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   421
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized type", NULL);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   422
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   423
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   424
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   425
static const char OBJ_SIG[] = "Ljava/lang/Object;";
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   426
enum { OBJ_SIG_LEN = 18 };
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   427
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   428
bool MethodHandles::is_basic_type_signature(Symbol* sig) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   429
  assert(vmSymbols::object_signature()->utf8_length() == (int)OBJ_SIG_LEN, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   430
  assert(vmSymbols::object_signature()->equals(OBJ_SIG), "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   431
  const int len = sig->utf8_length();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   432
  for (int i = 0; i < len; i++) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   433
    switch (sig->byte_at(i)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   434
    case 'L':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   435
      // only java/lang/Object is valid here
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   436
      if (sig->index_of_at(i, OBJ_SIG, OBJ_SIG_LEN) != i)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   437
        return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   438
      i += OBJ_SIG_LEN-1;  //-1 because of i++ in loop
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   439
      continue;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   440
    case '(': case ')': case 'V':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   441
    case 'I': case 'J': case 'F': case 'D':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   442
      continue;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   443
    //case '[':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   444
    //case 'Z': case 'B': case 'C': case 'S':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   445
    default:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   446
      return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   447
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   448
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   449
  return true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   450
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   451
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   452
Symbol* MethodHandles::lookup_basic_type_signature(Symbol* sig, bool keep_last_arg, TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   453
  Symbol* bsig = NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   454
  if (sig == NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   455
    return sig;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   456
  } else if (is_basic_type_signature(sig)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   457
    sig->increment_refcount();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   458
    return sig;  // that was easy
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   459
  } else if (sig->byte_at(0) != '(') {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   460
    BasicType bt = char2type(sig->byte_at(0));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   461
    if (is_subword_type(bt)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   462
      bsig = vmSymbols::int_signature();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   463
    } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   464
      assert(bt == T_OBJECT || bt == T_ARRAY, "is_basic_type_signature was false");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   465
      bsig = vmSymbols::object_signature();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   466
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   467
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   468
    ResourceMark rm;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   469
    stringStream buffer(128);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   470
    buffer.put('(');
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   471
    int arg_pos = 0, keep_arg_pos = -1;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   472
    if (keep_last_arg)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   473
      keep_arg_pos = ArgumentCount(sig).size() - 1;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   474
    for (SignatureStream ss(sig); !ss.is_done(); ss.next()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   475
      BasicType bt = ss.type();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   476
      size_t this_arg_pos = buffer.size();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   477
      if (ss.at_return_type()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   478
        buffer.put(')');
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   479
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   480
      if (arg_pos == keep_arg_pos) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   481
        buffer.write((char*) ss.raw_bytes(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   482
                     (int)   ss.raw_length());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   483
      } else if (bt == T_OBJECT || bt == T_ARRAY) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   484
        buffer.write(OBJ_SIG, OBJ_SIG_LEN);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   485
      } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   486
        if (is_subword_type(bt))
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   487
          bt = T_INT;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   488
        buffer.put(type2char(bt));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   489
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   490
      arg_pos++;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   491
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   492
    const char* sigstr =       buffer.base();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   493
    int         siglen = (int) buffer.size();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   494
    bsig = SymbolTable::new_symbol(sigstr, siglen, THREAD);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   495
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   496
  assert(is_basic_type_signature(bsig) ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   497
         // detune assert in case the injected argument is not a basic type:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   498
         keep_last_arg, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   499
  return bsig;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   500
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   501
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   502
void MethodHandles::print_as_basic_type_signature_on(outputStream* st,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   503
                                                     Symbol* sig,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   504
                                                     bool keep_arrays,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   505
                                                     bool keep_basic_names) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   506
  st = st ? st : tty;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   507
  int len  = sig->utf8_length();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   508
  int array = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   509
  bool prev_type = false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   510
  for (int i = 0; i < len; i++) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   511
    char ch = sig->byte_at(i);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   512
    switch (ch) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   513
    case '(': case ')':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   514
      prev_type = false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   515
      st->put(ch);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   516
      continue;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   517
    case '[':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   518
      if (!keep_basic_names && keep_arrays)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   519
        st->put(ch);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   520
      array++;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   521
      continue;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   522
    case 'L':
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   523
      {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   524
        if (prev_type)  st->put(',');
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   525
        int start = i+1, slash = start;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   526
        while (++i < len && (ch = sig->byte_at(i)) != ';') {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   527
          if (ch == '/' || ch == '.' || ch == '$')  slash = i+1;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   528
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   529
        if (slash < i)  start = slash;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   530
        if (!keep_basic_names) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   531
          st->put('L');
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   532
        } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   533
          for (int j = start; j < i; j++)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   534
            st->put(sig->byte_at(j));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   535
          prev_type = true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   536
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   537
        break;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   538
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   539
    default:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   540
      {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   541
        if (array && char2type(ch) != T_ILLEGAL && !keep_arrays) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   542
          ch = '[';
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   543
          array = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   544
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   545
        if (prev_type)  st->put(',');
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   546
        const char* n = NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   547
        if (keep_basic_names)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   548
          n = type2name(char2type(ch));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   549
        if (n == NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   550
          // unknown letter, or we don't want to know its name
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   551
          st->put(ch);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   552
        } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   553
          st->print(n);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   554
          prev_type = true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   555
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   556
        break;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   557
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   558
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   559
    // Switch break goes here to take care of array suffix:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   560
    if (prev_type) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   561
      while (array > 0) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   562
        st->print("[]");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   563
        --array;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   564
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   565
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   566
    array = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   567
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   568
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   569
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   570
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   571
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   572
static oop object_java_mirror() {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   573
  return SystemDictionary::Object_klass()->java_mirror();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   574
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   575
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   576
static oop field_name_or_null(Symbol* s) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   577
  if (s == NULL)  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   578
  return StringTable::lookup(s);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   579
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   580
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   581
static oop field_signature_type_or_null(Symbol* s) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   582
  if (s == NULL)  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   583
  BasicType bt = FieldType::basic_type(s);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   584
  if (is_java_primitive(bt)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   585
    assert(s->utf8_length() == 1, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   586
    return java_lang_Class::primitive_mirror(bt);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   587
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   588
  // Here are some more short cuts for common types.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   589
  // They are optional, since reference types can be resolved lazily.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   590
  if (bt == T_OBJECT) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   591
    if (s == vmSymbols::object_signature()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   592
      return object_java_mirror();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   593
    } else if (s == vmSymbols::class_signature()) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   594
      return SystemDictionary::Class_klass()->java_mirror();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   595
    } else if (s == vmSymbols::string_signature()) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   596
      return SystemDictionary::String_klass()->java_mirror();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   597
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   598
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   599
  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   600
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   601
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   602
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   603
// An unresolved member name is a mere symbolic reference.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   604
// Resolving it plants a vmtarget/vmindex in it,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   605
// which refers directly to JVM internals.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   606
Handle MethodHandles::resolve_MemberName(Handle mname, TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   607
  Handle empty;
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   608
  assert(java_lang_invoke_MemberName::is_instance(mname()), "");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   609
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   610
  if (java_lang_invoke_MemberName::vmtarget(mname()) != NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   611
    // Already resolved.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   612
    DEBUG_ONLY(int vmindex = java_lang_invoke_MemberName::vmindex(mname()));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   613
    assert(vmindex >= Method::nonvirtual_vtable_index, "");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   614
    return mname;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   615
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   616
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   617
  Handle defc_oop(THREAD, java_lang_invoke_MemberName::clazz(mname()));
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   618
  Handle name_str(THREAD, java_lang_invoke_MemberName::name( mname()));
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   619
  Handle type_str(THREAD, java_lang_invoke_MemberName::type( mname()));
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   620
  int    flags    =       java_lang_invoke_MemberName::flags(mname());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   621
  int    ref_kind =       (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   622
  if (!ref_kind_is_valid(ref_kind)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   623
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "obsolete MemberName format", empty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   624
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   625
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   626
  DEBUG_ONLY(int old_vmindex);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   627
  assert((old_vmindex = java_lang_invoke_MemberName::vmindex(mname())) == 0, "clean input");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   628
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   629
  if (defc_oop.is_null() || name_str.is_null() || type_str.is_null()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   630
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve", empty);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   631
  }
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   632
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   633
  instanceKlassHandle defc;
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   634
  {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   635
    Klass* defc_klass = java_lang_Class::as_Klass(defc_oop());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   636
    if (defc_klass == NULL)  return empty;  // a primitive; no resolution possible
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   637
    if (!defc_klass->oop_is_instance()) {
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   638
      if (!defc_klass->oop_is_array())  return empty;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   639
      defc_klass = SystemDictionary::Object_klass();
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   640
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   641
    defc = instanceKlassHandle(THREAD, defc_klass);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   642
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   643
  if (defc.is_null()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   644
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "primitive class", empty);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   645
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   646
  defc->link_class(CHECK_(empty));  // possible safepoint
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   647
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   648
  // convert the external string name to an internal symbol
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   649
  TempNewSymbol name = java_lang_String::as_symbol_or_null(name_str());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   650
  if (name == NULL)  return empty;  // no such name
10004
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 9980
diff changeset
   651
  if (name == vmSymbols::class_initializer_name())
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   652
    return empty; // illegal name
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   653
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   654
  vmIntrinsics::ID mh_invoke_id = vmIntrinsics::_none;
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 5420
diff changeset
   655
  if ((flags & ALL_KINDS) == IS_METHOD &&
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   656
      (defc() == SystemDictionary::MethodHandle_klass()) &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   657
      (ref_kind == JVM_REF_invokeVirtual ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   658
       ref_kind == JVM_REF_invokeSpecial ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   659
       // static invocation mode is required for _linkToVirtual, etc.:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   660
       ref_kind == JVM_REF_invokeStatic)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   661
    vmIntrinsics::ID iid = signature_polymorphic_name_id(name);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   662
    if (iid != vmIntrinsics::_none &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   663
        ((ref_kind == JVM_REF_invokeStatic) == is_signature_polymorphic_static(iid))) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   664
      // Virtual methods invoke and invokeExact, plus internal invokers like _invokeBasic.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   665
      // For a static reference it could an internal linkage routine like _linkToVirtual, etc.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   666
      mh_invoke_id = iid;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   667
    }
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   668
  }
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 5420
diff changeset
   669
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   670
  // convert the external string or reflective type to an internal signature
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   671
  TempNewSymbol type = lookup_signature(type_str(), (mh_invoke_id != vmIntrinsics::_none), CHECK_(empty));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   672
  if (type == NULL)  return empty;  // no such signature exists in the VM
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   673
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   674
  // Time to do the lookup.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   675
  switch (flags & ALL_KINDS) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   676
  case IS_METHOD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   677
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   678
      CallInfo result;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   679
      {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   680
        assert(!HAS_PENDING_EXCEPTION, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   681
        if (ref_kind == JVM_REF_invokeStatic) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   682
          LinkResolver::resolve_static_call(result,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   683
                        defc, name, type, KlassHandle(), false, false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   684
        } else if (ref_kind == JVM_REF_invokeInterface) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   685
          LinkResolver::resolve_interface_call(result, Handle(), defc,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   686
                        defc, name, type, KlassHandle(), false, false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   687
        } else if (mh_invoke_id != vmIntrinsics::_none) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   688
          assert(!is_signature_polymorphic_static(mh_invoke_id), "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   689
          LinkResolver::resolve_handle_call(result,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   690
                        defc, name, type, KlassHandle(), THREAD);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   691
        } else if (ref_kind == JVM_REF_invokeSpecial) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   692
          LinkResolver::resolve_special_call(result,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   693
                        defc, name, type, KlassHandle(), false, THREAD);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   694
        } else if (ref_kind == JVM_REF_invokeVirtual) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   695
          LinkResolver::resolve_virtual_call(result, Handle(), defc,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   696
                        defc, name, type, KlassHandle(), false, false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   697
        } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   698
          assert(false, err_msg("ref_kind=%d", ref_kind));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   699
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   700
        if (HAS_PENDING_EXCEPTION) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   701
          return empty;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   702
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   703
      }
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   704
      return init_method_MemberName(mname, result, THREAD);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   705
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   706
  case IS_CONSTRUCTOR:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   707
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   708
      CallInfo result;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   709
      {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   710
        assert(!HAS_PENDING_EXCEPTION, "");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   711
        if (name == vmSymbols::object_initializer_name()) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   712
          LinkResolver::resolve_special_call(result,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   713
                        defc, name, type, KlassHandle(), false, THREAD);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   714
        } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   715
          break;                // will throw after end of switch
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   716
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   717
        if (HAS_PENDING_EXCEPTION) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   718
          return empty;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   719
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   720
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   721
      assert(result.is_statically_bound(), "");
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   722
      return init_method_MemberName(mname, result, THREAD);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   723
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   724
  case IS_FIELD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   725
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   726
      // This is taken from LinkResolver::resolve_field, sans access checks.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   727
      fieldDescriptor fd; // find_field initializes fd if found
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   728
      KlassHandle sel_klass(THREAD, InstanceKlass::cast(defc())->find_field(name, type, &fd));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   729
      // check if field exists; i.e., if a klass containing the field def has been selected
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   730
      if (sel_klass.is_null())  return empty;  // should not happen
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   731
      oop type = field_signature_type_or_null(fd.signature());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   732
      oop name = field_name_or_null(fd.name());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   733
      bool is_setter = (ref_kind_is_valid(ref_kind) && ref_kind_is_setter(ref_kind));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   734
      mname = Handle(THREAD,
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   735
                     init_field_MemberName(mname, sel_klass,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   736
                                           fd.access_flags(), type, name, fd.offset(), is_setter));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   737
      return mname;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   738
    }
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 5420
diff changeset
   739
  default:
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   740
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   741
  }
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 5420
diff changeset
   742
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   743
  return empty;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   744
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   745
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   746
// Conversely, a member name which is only initialized from JVM internals
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   747
// may have null defc, name, and type fields.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   748
// Resolving it plants a vmtarget/vmindex in it,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   749
// which refers directly to JVM internals.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   750
void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   751
  assert(java_lang_invoke_MemberName::is_instance(mname()), "");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   752
  Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   753
  int vmindex  = java_lang_invoke_MemberName::vmindex(mname());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   754
  if (vmtarget == NULL) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   755
    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   756
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   757
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   758
  bool have_defc = (java_lang_invoke_MemberName::clazz(mname()) != NULL);
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   759
  bool have_name = (java_lang_invoke_MemberName::name(mname()) != NULL);
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   760
  bool have_type = (java_lang_invoke_MemberName::type(mname()) != NULL);
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   761
  int flags      = java_lang_invoke_MemberName::flags(mname());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   762
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   763
  if (suppress != 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   764
    if (suppress & _suppress_defc)  have_defc = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   765
    if (suppress & _suppress_name)  have_name = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   766
    if (suppress & _suppress_type)  have_type = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   767
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   768
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   769
  if (have_defc && have_name && have_type)  return;  // nothing needed
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   770
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   771
  switch (flags & ALL_KINDS) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   772
  case IS_METHOD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   773
  case IS_CONSTRUCTOR:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   774
    {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   775
      assert(vmtarget->is_method(), "method or constructor vmtarget is Method*");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   776
      methodHandle m(THREAD, (Method*)vmtarget);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   777
      DEBUG_ONLY(vmtarget = NULL);  // safety
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   778
      if (m.is_null())  break;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   779
      if (!have_defc) {
14391
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 13973
diff changeset
   780
        InstanceKlass* defc = m->method_holder();
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 13973
diff changeset
   781
        java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   782
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   783
      if (!have_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   784
        //not java_lang_String::create_from_symbol; let's intern member names
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   785
        Handle name = StringTable::intern(m->name(), CHECK);
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   786
        java_lang_invoke_MemberName::set_name(mname(), name());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   787
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   788
      if (!have_type) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   789
        Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK);
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   790
        java_lang_invoke_MemberName::set_type(mname(), type());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   791
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   792
      return;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   793
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   794
  case IS_FIELD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   795
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   796
      // This is taken from LinkResolver::resolve_field, sans access checks.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   797
      assert(vmtarget->is_klass(), "field vmtarget is Klass*");
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   798
      if (!((Klass*) vmtarget)->oop_is_instance())  break;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   799
      instanceKlassHandle defc(THREAD, (Klass*) vmtarget);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   800
      DEBUG_ONLY(vmtarget = NULL);  // safety
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   801
      bool is_static = ((flags & JVM_ACC_STATIC) != 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   802
      fieldDescriptor fd; // find_field initializes fd if found
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   803
      if (!defc->find_field_from_offset(vmindex, is_static, &fd))
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   804
        break;                  // cannot expand
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   805
      if (!have_defc) {
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   806
        java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   807
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   808
      if (!have_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   809
        //not java_lang_String::create_from_symbol; let's intern member names
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   810
        Handle name = StringTable::intern(fd.name(), CHECK);
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   811
        java_lang_invoke_MemberName::set_name(mname(), name());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   812
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   813
      if (!have_type) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   814
        // If it is a primitive field type, don't mess with short strings like "I".
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   815
        Handle type = field_signature_type_or_null(fd.signature());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   816
        if (type.is_null()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   817
          java_lang_String::create_from_symbol(fd.signature(), CHECK);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   818
        }
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   819
        java_lang_invoke_MemberName::set_type(mname(), type());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   820
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   821
      return;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   822
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   823
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   824
  THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   825
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   826
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   827
int MethodHandles::find_MemberNames(KlassHandle k,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   828
                                    Symbol* name, Symbol* sig,
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   829
                                    int mflags, KlassHandle caller,
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   830
                                    int skip, objArrayHandle results) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   831
  // %%% take caller into account!
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   832
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   833
  Thread* thread = Thread::current();
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   834
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   835
  if (k.is_null() || !k->oop_is_instance())  return -1;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   836
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   837
  int rfill = 0, rlimit = results->length(), rskip = skip;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   838
  // overflow measurement:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   839
  int overflow = 0, overflow_limit = MAX2(1000, rlimit);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   840
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   841
  int match_flags = mflags;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   842
  bool search_superc = ((match_flags & SEARCH_SUPERCLASSES) != 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   843
  bool search_intfc  = ((match_flags & SEARCH_INTERFACES)   != 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   844
  bool local_only = !(search_superc | search_intfc);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   845
  bool classes_only = false;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   846
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   847
  if (name != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   848
    if (name->utf8_length() == 0)  return 0; // a match is not possible
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   849
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   850
  if (sig != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   851
    if (sig->utf8_length() == 0)  return 0; // a match is not possible
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   852
    if (sig->byte_at(0) == '(')
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   853
      match_flags &= ~(IS_FIELD | IS_TYPE);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   854
    else
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   855
      match_flags &= ~(IS_CONSTRUCTOR | IS_METHOD);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   856
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   857
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   858
  if ((match_flags & IS_TYPE) != 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   859
    // NYI, and Core Reflection works quite well for this query
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   860
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   861
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   862
  if ((match_flags & IS_FIELD) != 0) {
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   863
    for (FieldStream st(k(), local_only, !search_intfc); !st.eos(); st.next()) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   864
      if (name != NULL && st.name() != name)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   865
          continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   866
      if (sig != NULL && st.signature() != sig)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   867
        continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   868
      // passed the filters
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   869
      if (rskip > 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   870
        --rskip;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   871
      } else if (rfill < rlimit) {
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   872
        Handle result(thread, results->obj_at(rfill++));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   873
        if (!java_lang_invoke_MemberName::is_instance(result()))
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   874
          return -99;  // caller bug!
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   875
        oop type = field_signature_type_or_null(st.signature());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   876
        oop name = field_name_or_null(st.name());
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   877
        oop saved = MethodHandles::init_field_MemberName(result, st.klass(),
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   878
                                                         st.access_flags(), type, name,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   879
                                                         st.offset());
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   880
        if (saved != result())
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   881
          results->obj_at_put(rfill-1, saved);  // show saved instance to user
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   882
      } else if (++overflow >= overflow_limit) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   883
        match_flags = 0; break; // got tired of looking at overflow
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   884
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   885
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   886
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   887
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   888
  if ((match_flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   889
    // watch out for these guys:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   890
    Symbol* init_name   = vmSymbols::object_initializer_name();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   891
    Symbol* clinit_name = vmSymbols::class_initializer_name();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   892
    if (name == clinit_name)  clinit_name = NULL; // hack for exposing <clinit>
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   893
    bool negate_name_test = false;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   894
    // fix name so that it captures the intention of IS_CONSTRUCTOR
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   895
    if (!(match_flags & IS_METHOD)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   896
      // constructors only
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   897
      if (name == NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   898
        name = init_name;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   899
      } else if (name != init_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   900
        return 0;               // no constructors of this method name
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   901
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   902
    } else if (!(match_flags & IS_CONSTRUCTOR)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   903
      // methods only
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   904
      if (name == NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   905
        name = init_name;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   906
        negate_name_test = true; // if we see the name, we *omit* the entry
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   907
      } else if (name == init_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   908
        return 0;               // no methods of this constructor name
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   909
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   910
    } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   911
      // caller will accept either sort; no need to adjust name
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   912
    }
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   913
    for (MethodStream st(k(), local_only, !search_intfc); !st.eos(); st.next()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   914
      Method* m = st.method();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   915
      Symbol* m_name = m->name();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   916
      if (m_name == clinit_name)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   917
        continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   918
      if (name != NULL && ((m_name != name) ^ negate_name_test))
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   919
          continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   920
      if (sig != NULL && m->signature() != sig)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   921
        continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   922
      // passed the filters
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   923
      if (rskip > 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   924
        --rskip;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   925
      } else if (rfill < rlimit) {
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   926
        Handle result(thread, results->obj_at(rfill++));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   927
        if (!java_lang_invoke_MemberName::is_instance(result()))
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   928
          return -99;  // caller bug!
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   929
        oop saved = MethodHandles::init_method_MemberName(result, m, true, NULL);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   930
        if (saved != result())
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   931
          results->obj_at_put(rfill-1, saved);  // show saved instance to user
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   932
      } else if (++overflow >= overflow_limit) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   933
        match_flags = 0; break; // got tired of looking at overflow
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   934
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   935
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   936
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   937
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   938
  // return number of elements we at leasted wanted to initialize
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   939
  return rfill + overflow;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   940
}
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   941
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   942
//------------------------------------------------------------------------------
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   943
// MemberNameTable
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   944
//
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   945
17828
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   946
MemberNameTable::MemberNameTable(int methods_cnt)
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   947
                  : GrowableArray<jweak>(methods_cnt, true) {
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   948
  assert_locked_or_safepoint(MemberNameTable_lock);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   949
}
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   950
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   951
MemberNameTable::~MemberNameTable() {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   952
  assert_locked_or_safepoint(MemberNameTable_lock);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   953
  int len = this->length();
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   954
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   955
  for (int idx = 0; idx < len; idx++) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   956
    jweak ref = this->at(idx);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   957
    JNIHandles::destroy_weak_global(ref);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   958
  }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   959
}
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   960
17828
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   961
void MemberNameTable::add_member_name(int index, jweak mem_name_wref) {
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   962
  assert_locked_or_safepoint(MemberNameTable_lock);
17828
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   963
  this->at_put_grow(index, mem_name_wref);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   964
}
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   965
17828
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   966
// Return a member name oop or NULL.
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   967
oop MemberNameTable::get_member_name(int index) {
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   968
  assert_locked_or_safepoint(MemberNameTable_lock);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   969
17828
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   970
  jweak ref = this->at(index);
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   971
  oop mem_name = JNIHandles::resolve(ref);
17131ab4b3b5 8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
sspitsyn
parents: 17388
diff changeset
   972
  return mem_name;
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   973
}
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   974
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   975
#if INCLUDE_JVMTI
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   976
oop MemberNameTable::find_member_name_by_method(Method* old_method) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   977
  assert_locked_or_safepoint(MemberNameTable_lock);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   978
  oop found = NULL;
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   979
  int len = this->length();
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   980
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   981
  for (int idx = 0; idx < len; idx++) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   982
    oop mem_name = JNIHandles::resolve(this->at(idx));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   983
    if (mem_name == NULL) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   984
      continue;
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   985
    }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   986
    Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(mem_name);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   987
    if (method == old_method) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   988
      found = mem_name;
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   989
      break;
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   990
    }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   991
  }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   992
  return found;
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   993
}
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   994
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   995
// It is called at safepoint only
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   996
void MemberNameTable::adjust_method_entries(Method** old_methods, Method** new_methods,
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   997
                                            int methods_length, bool *trace_name_printed) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   998
  assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   999
  // search the MemberNameTable for uses of either obsolete or EMCP methods
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1000
  for (int j = 0; j < methods_length; j++) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1001
    Method* old_method = old_methods[j];
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1002
    Method* new_method = new_methods[j];
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1003
    oop mem_name = find_member_name_by_method(old_method);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1004
    if (mem_name != NULL) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1005
      java_lang_invoke_MemberName::adjust_vmtarget(mem_name, new_method);
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1006
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1007
      if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1008
        if (!(*trace_name_printed)) {
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1009
          // RC_TRACE_MESG macro has an embedded ResourceMark
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1010
          RC_TRACE_MESG(("adjust: name=%s",
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1011
                         old_method->method_holder()->external_name()));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1012
          *trace_name_printed = true;
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1013
        }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1014
        // RC_TRACE macro has an embedded ResourceMark
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1015
        RC_TRACE(0x00400000, ("MemberName method update: %s(%s)",
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1016
                              new_method->name()->as_C_string(),
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1017
                              new_method->signature()->as_C_string()));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1018
      }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1019
    }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1020
  }
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1021
}
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1022
#endif // INCLUDE_JVMTI
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1023
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1024
//
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1025
// Here are the native methods in java.lang.invoke.MethodHandleNatives
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1026
// They are the private interface between this JVM and the HotSpot-specific
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1027
// Java code that implements JSR 292 method handles.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1028
//
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1029
// Note:  We use a JVM_ENTRY macro to define each of these, for this is the way
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1030
// that intrinsic (non-JNI) native methods are defined in HotSpot.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1031
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1032
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1033
JVM_ENTRY(jint, MHN_getConstant(JNIEnv *env, jobject igcls, jint which)) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1034
  switch (which) {
10514
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10250
diff changeset
  1035
  case MethodHandles::GC_COUNT_GWT:
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10250
diff changeset
  1036
#ifdef COMPILER2
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10250
diff changeset
  1037
    return true;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10250
diff changeset
  1038
#else
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10250
diff changeset
  1039
    return false;
e229a19078cf 7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents: 10250
diff changeset
  1040
#endif
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1041
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1042
  return 0;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1043
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1044
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1045
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1046
#ifndef PRODUCT
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1047
#define EACH_NAMED_CON(template, requirement) \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1048
    template(MethodHandles,GC_COUNT_GWT) \
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1049
    template(java_lang_invoke_MemberName,MN_IS_METHOD) \
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1050
    template(java_lang_invoke_MemberName,MN_IS_CONSTRUCTOR) \
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1051
    template(java_lang_invoke_MemberName,MN_IS_FIELD) \
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1052
    template(java_lang_invoke_MemberName,MN_IS_TYPE) \
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
  1053
    template(java_lang_invoke_MemberName,MN_CALLER_SENSITIVE) \
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1054
    template(java_lang_invoke_MemberName,MN_SEARCH_SUPERCLASSES) \
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1055
    template(java_lang_invoke_MemberName,MN_SEARCH_INTERFACES) \
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1056
    template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_SHIFT) \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1057
    template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_MASK) \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1058
    template(MethodHandles,GC_LAMBDA_SUPPORT) \
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1059
    /*end*/
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1060
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1061
#define IGNORE_REQ(req_expr) /* req_expr */
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1062
#define ONE_PLUS(scope,value) 1+
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1063
static const int con_value_count = EACH_NAMED_CON(ONE_PLUS, IGNORE_REQ) 0;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1064
#define VALUE_COMMA(scope,value) scope::value,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1065
static const int con_values[con_value_count+1] = { EACH_NAMED_CON(VALUE_COMMA, IGNORE_REQ) 0 };
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1066
#define STRING_NULL(scope,value) #value "\0"
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1067
static const char con_names[] = { EACH_NAMED_CON(STRING_NULL, IGNORE_REQ) };
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1068
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1069
static bool advertise_con_value(int which) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1070
  if (which < 0)  return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1071
  bool ok = true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1072
  int count = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1073
#define INC_COUNT(scope,value) \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1074
  ++count;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1075
#define CHECK_REQ(req_expr) \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1076
  if (which < count)  return ok; \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1077
  ok = (req_expr);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1078
  EACH_NAMED_CON(INC_COUNT, CHECK_REQ);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1079
#undef INC_COUNT
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1080
#undef CHECK_REQ
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1081
  assert(count == con_value_count, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1082
  if (which < count)  return ok;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1083
  return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1084
}
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1085
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1086
#undef ONE_PLUS
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1087
#undef VALUE_COMMA
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1088
#undef STRING_NULL
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1089
#undef EACH_NAMED_CON
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1090
#endif // PRODUCT
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1091
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1092
JVM_ENTRY(jint, MHN_getNamedCon(JNIEnv *env, jobject igcls, jint which, jobjectArray box_jh)) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1093
#ifndef PRODUCT
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1094
  if (advertise_con_value(which)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1095
    assert(which >= 0 && which < con_value_count, "");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1096
    int con = con_values[which];
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1097
    objArrayHandle box(THREAD, (objArrayOop) JNIHandles::resolve(box_jh));
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1098
    if (box.not_null() && box->klass() == Universe::objectArrayKlassObj() && box->length() > 0) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1099
      const char* str = &con_names[0];
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1100
      for (int i = 0; i < which; i++)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1101
        str += strlen(str) + 1;   // skip name and null
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1102
      oop name = java_lang_String::create_oop_from_str(str, CHECK_0);  // possible safepoint
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1103
      box->obj_at_put(0, name);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1104
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1105
    return con;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1106
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1107
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1108
  return 0;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1109
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1110
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1111
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1112
// void init(MemberName self, AccessibleObject ref)
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1113
JVM_ENTRY(void, MHN_init_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jobject target_jh)) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9947
diff changeset
  1114
  if (mname_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "mname is null"); }
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9947
diff changeset
  1115
  if (target_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "target is null"); }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1116
  Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1117
  Handle target(THREAD, JNIHandles::resolve_non_null(target_jh));
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1118
  MethodHandles::init_MemberName(mname, target);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1119
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1120
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1121
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1122
// void expand(MemberName self)
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1123
JVM_ENTRY(void, MHN_expand_Mem(JNIEnv *env, jobject igcls, jobject mname_jh)) {
9963
4a783069663c 7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents: 9947
diff changeset
  1124
  if (mname_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "mname is null"); }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1125
  Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1126
  MethodHandles::expand_MemberName(mname, 0, CHECK);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1127
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1128
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1129
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1130
// void resolve(MemberName self, Class<?> caller)
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1131
JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1132
  if (mname_jh == NULL) { THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "mname is null"); }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1133
  Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1134
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1135
  // The trusted Java code that calls this method should already have performed
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1136
  // access checks on behalf of the given caller.  But, we can verify this.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1137
  if (VerifyMethodHandles && caller_jh != NULL &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1138
      java_lang_invoke_MemberName::clazz(mname()) != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1139
    Klass* reference_klass = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
18508
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1140
    if (reference_klass != NULL && reference_klass->oop_is_objArray()) {
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1141
      reference_klass = ObjArrayKlass::cast(reference_klass)->bottom_klass();
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1142
    }
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1143
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1144
    // Reflection::verify_class_access can only handle instance classes.
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1145
    if (reference_klass != NULL && reference_klass->oop_is_instance()) {
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1146
      // Emulate LinkResolver::check_klass_accessability.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1147
      Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1148
      if (!Reflection::verify_class_access(caller,
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1149
                                           reference_klass,
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1150
                                           true)) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1151
        THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name());
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1152
      }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1153
    }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1154
  }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1155
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1156
  Handle resolved = MethodHandles::resolve_MemberName(mname, CHECK_NULL);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1157
  if (resolved.is_null()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1158
    int flags = java_lang_invoke_MemberName::flags(mname());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1159
    int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1160
    if (!MethodHandles::ref_kind_is_valid(ref_kind)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1161
      THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "obsolete MemberName format");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1162
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1163
    if ((flags & ALL_KINDS) == IS_FIELD) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1164
      THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), "field resolution failed");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1165
    } else if ((flags & ALL_KINDS) == IS_METHOD ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1166
               (flags & ALL_KINDS) == IS_CONSTRUCTOR) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1167
      THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), "method resolution failed");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1168
    } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1169
      THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "resolution failed");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1170
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1171
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1172
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1173
  return JNIHandles::make_local(THREAD, resolved());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1174
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1175
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1176
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1177
static jlong find_member_field_offset(oop mname, bool must_be_static, TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1178
  if (mname == NULL ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1179
      java_lang_invoke_MemberName::vmtarget(mname) == NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1180
    THROW_MSG_0(vmSymbols::java_lang_InternalError(), "mname not resolved");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1181
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1182
    int flags = java_lang_invoke_MemberName::flags(mname);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1183
    if ((flags & IS_FIELD) != 0 &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1184
        (must_be_static
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1185
         ? (flags & JVM_ACC_STATIC) != 0
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1186
         : (flags & JVM_ACC_STATIC) == 0)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1187
      int vmindex = java_lang_invoke_MemberName::vmindex(mname);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1188
      return (jlong) vmindex;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1189
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1190
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1191
  const char* msg = (must_be_static ? "static field required" : "non-static field required");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1192
  THROW_MSG_0(vmSymbols::java_lang_InternalError(), msg);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1193
  return 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1194
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1195
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1196
JVM_ENTRY(jlong, MHN_objectFieldOffset(JNIEnv *env, jobject igcls, jobject mname_jh)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1197
  return find_member_field_offset(JNIHandles::resolve(mname_jh), false, THREAD);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1198
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1199
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1200
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1201
JVM_ENTRY(jlong, MHN_staticFieldOffset(JNIEnv *env, jobject igcls, jobject mname_jh)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1202
  return find_member_field_offset(JNIHandles::resolve(mname_jh), true, THREAD);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1203
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1204
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1205
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1206
JVM_ENTRY(jobject, MHN_staticFieldBase(JNIEnv *env, jobject igcls, jobject mname_jh)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1207
  // use the other function to perform sanity checks:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1208
  jlong ignore = find_member_field_offset(JNIHandles::resolve(mname_jh), true, CHECK_NULL);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1209
  oop clazz = java_lang_invoke_MemberName::clazz(JNIHandles::resolve_non_null(mname_jh));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1210
  return JNIHandles::make_local(THREAD, clazz);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1211
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1212
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1213
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1214
JVM_ENTRY(jobject, MHN_getMemberVMInfo(JNIEnv *env, jobject igcls, jobject mname_jh)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1215
  if (mname_jh == NULL)  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1216
  Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1217
  intptr_t vmindex  = java_lang_invoke_MemberName::vmindex(mname());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1218
  Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1219
  objArrayHandle result = oopFactory::new_objArray(SystemDictionary::Object_klass(), 2, CHECK_NULL);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1220
  jvalue vmindex_value; vmindex_value.j = (long)vmindex;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1221
  oop x = java_lang_boxing_object::create(T_LONG, &vmindex_value, CHECK_NULL);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1222
  result->obj_at_put(0, x);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1223
  x = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1224
  if (vmtarget == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1225
    x = NULL;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1226
  } else if (vmtarget->is_klass()) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1227
    x = ((Klass*) vmtarget)->java_mirror();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1228
  } else if (vmtarget->is_method()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1229
    Handle mname2 = MethodHandles::new_MemberName(CHECK_NULL);
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1230
    x = MethodHandles::init_method_MemberName(mname2, (Method*)vmtarget, false, NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1231
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1232
  result->obj_at_put(1, x);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1233
  return JNIHandles::make_local(env, result());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1234
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1235
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1236
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1237
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1238
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1239
//  static native int getMembers(Class<?> defc, String matchName, String matchSig,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1240
//          int matchFlags, Class<?> caller, int skip, MemberName[] results);
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1241
JVM_ENTRY(jint, MHN_getMembers(JNIEnv *env, jobject igcls,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1242
                               jclass clazz_jh, jstring name_jh, jstring sig_jh,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1243
                               int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1244
  if (clazz_jh == NULL || results_jh == NULL)  return -1;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1245
  KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz_jh)));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1246
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1247
  objArrayHandle results(THREAD, (objArrayOop) JNIHandles::resolve(results_jh));
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1248
  if (results.is_null() || !results->is_objArray())  return -1;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1249
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
  1250
  TempNewSymbol name = NULL;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
  1251
  TempNewSymbol sig = NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1252
  if (name_jh != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1253
    name = java_lang_String::as_symbol_or_null(JNIHandles::resolve_non_null(name_jh));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1254
    if (name == NULL)  return 0; // a match is not possible
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1255
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1256
  if (sig_jh != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1257
    sig = java_lang_String::as_symbol_or_null(JNIHandles::resolve_non_null(sig_jh));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1258
    if (sig == NULL)  return 0; // a match is not possible
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1259
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1260
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1261
  KlassHandle caller;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1262
  if (caller_jh != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1263
    oop caller_oop = JNIHandles::resolve_non_null(caller_jh);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1264
    if (!java_lang_Class::is_instance(caller_oop))  return -1;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1265
    caller = KlassHandle(THREAD, java_lang_Class::as_Klass(caller_oop));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1266
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1267
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1268
  if (name != NULL && sig != NULL && results.not_null()) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1269
    // try a direct resolve
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1270
    // %%% TO DO
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1271
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1272
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1273
  int res = MethodHandles::find_MemberNames(k, name, sig, mflags,
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1274
                                            caller, skip, results);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1275
  // TO DO: expand at least some of the MemberNames, to avoid massive callbacks
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1276
  return res;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1277
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1278
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1279
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1280
JVM_ENTRY(void, MHN_setCallSiteTargetNormal(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
10967
e13ea25b2f0b 7094138: JSR 292: JRuby junit test fails in CallSite.setTargetNormal: obj->is_oop() failed: sanity check
twisti
parents: 10546
diff changeset
  1281
  Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
e13ea25b2f0b 7094138: JSR 292: JRuby junit test fails in CallSite.setTargetNormal: obj->is_oop() failed: sanity check
twisti
parents: 10546
diff changeset
  1282
  Handle target   (THREAD, JNIHandles::resolve(target_jh));
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1283
  {
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1284
    // Walk all nmethods depending on this call site.
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1285
    MutexLocker mu(Compile_lock, thread);
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1286
    Universe::flush_dependents_on(call_site, target);
14825
8bc43f610c87 8003238: JSR 292: intermittent exception failure with java/lang/invoke/CallSiteTest.java
twisti
parents: 14488
diff changeset
  1287
    java_lang_invoke_CallSite::set_target(call_site(), target());
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1288
  }
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1289
}
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1290
JVM_END
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1291
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1292
JVM_ENTRY(void, MHN_setCallSiteTargetVolatile(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
10967
e13ea25b2f0b 7094138: JSR 292: JRuby junit test fails in CallSite.setTargetNormal: obj->is_oop() failed: sanity check
twisti
parents: 10546
diff changeset
  1293
  Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
e13ea25b2f0b 7094138: JSR 292: JRuby junit test fails in CallSite.setTargetNormal: obj->is_oop() failed: sanity check
twisti
parents: 10546
diff changeset
  1294
  Handle target   (THREAD, JNIHandles::resolve(target_jh));
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1295
  {
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1296
    // Walk all nmethods depending on this call site.
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1297
    MutexLocker mu(Compile_lock, thread);
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1298
    Universe::flush_dependents_on(call_site, target);
14825
8bc43f610c87 8003238: JSR 292: intermittent exception failure with java/lang/invoke/CallSiteTest.java
twisti
parents: 14488
diff changeset
  1299
    java_lang_invoke_CallSite::set_target_volatile(call_site(), target());
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1300
  }
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1301
}
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1302
JVM_END
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1303
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1304
/**
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1305
 * Throws a java/lang/UnsupportedOperationException unconditionally.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1306
 * This is required by the specification of MethodHandle.invoke if
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1307
 * invoked directly.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1308
 */
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1309
JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1310
  THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively");
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1311
  return NULL;
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1312
}
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1313
JVM_END
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1314
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1315
/**
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1316
 * Throws a java/lang/UnsupportedOperationException unconditionally.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1317
 * This is required by the specification of MethodHandle.invokeExact if
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1318
 * invoked directly.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1319
 */
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1320
JVM_ENTRY(jobject, MH_invokeExact_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1321
  THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invokeExact cannot be invoked reflectively");
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1322
  return NULL;
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1323
}
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1324
JVM_END
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1325
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1326
/// JVM_RegisterMethodHandleMethods
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1327
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1328
#undef CS  // Solaris builds complain
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1329
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1330
#define LANG "Ljava/lang/"
9116
9bc44be338d6 6981791: remove experimental code for JSR 292
jrose
parents: 8883
diff changeset
  1331
#define JLINV "Ljava/lang/invoke/"
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1332
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1333
#define OBJ   LANG"Object;"
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1334
#define CLS   LANG"Class;"
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1335
#define STRG  LANG"String;"
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1336
#define CS    JLINV"CallSite;"
9116
9bc44be338d6 6981791: remove experimental code for JSR 292
jrose
parents: 8883
diff changeset
  1337
#define MT    JLINV"MethodType;"
9bc44be338d6 6981791: remove experimental code for JSR 292
jrose
parents: 8883
diff changeset
  1338
#define MH    JLINV"MethodHandle;"
9bc44be338d6 6981791: remove experimental code for JSR 292
jrose
parents: 8883
diff changeset
  1339
#define MEM   JLINV"MemberName;"
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1340
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1341
#define CC (char*)  /*cast a literal from (const char*)*/
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1342
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1343
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1344
// These are the native methods on java.lang.invoke.MethodHandleNatives.
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1345
static JNINativeMethod MHN_methods[] = {
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1346
  {CC"init",                      CC"("MEM""OBJ")V",                     FN_PTR(MHN_init_Mem)},
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1347
  {CC"expand",                    CC"("MEM")V",                          FN_PTR(MHN_expand_Mem)},
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1348
  {CC"resolve",                   CC"("MEM""CLS")"MEM,                   FN_PTR(MHN_resolve_Mem)},
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1349
  {CC"getConstant",               CC"(I)I",                              FN_PTR(MHN_getConstant)},
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1350
  //  static native int getNamedCon(int which, Object[] name)
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1351
  {CC"getNamedCon",               CC"(I["OBJ")I",                        FN_PTR(MHN_getNamedCon)},
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1352
  //  static native int getMembers(Class<?> defc, String matchName, String matchSig,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1353
  //          int matchFlags, Class<?> caller, int skip, MemberName[] results);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1354
  {CC"getMembers",                CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)},
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1355
  {CC"objectFieldOffset",         CC"("MEM")J",                          FN_PTR(MHN_objectFieldOffset)},
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1356
  {CC"setCallSiteTargetNormal",   CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetNormal)},
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1357
  {CC"setCallSiteTargetVolatile", CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetVolatile)},
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1358
  {CC"staticFieldOffset",         CC"("MEM")J",                          FN_PTR(MHN_staticFieldOffset)},
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1359
  {CC"staticFieldBase",           CC"("MEM")"OBJ,                        FN_PTR(MHN_staticFieldBase)},
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1360
  {CC"getMemberVMInfo",           CC"("MEM")"OBJ,                        FN_PTR(MHN_getMemberVMInfo)}
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1361
};
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1362
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1363
static JNINativeMethod MH_methods[] = {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1364
  // UnsupportedOperationException throwers
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1365
  {CC"invoke",                    CC"(["OBJ")"OBJ,                       FN_PTR(MH_invoke_UOE)},
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1366
  {CC"invokeExact",               CC"(["OBJ")"OBJ,                       FN_PTR(MH_invokeExact_UOE)}
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1367
};
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1368
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1369
/**
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1370
 * Helper method to register native methods.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1371
 */
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1372
static bool register_natives(JNIEnv* env, jclass clazz, const JNINativeMethod* methods, jint nMethods) {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1373
  int status = env->RegisterNatives(clazz, methods, nMethods);
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1374
  if (status != JNI_OK || env->ExceptionOccurred()) {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1375
    warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1376
    env->ExceptionClear();
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1377
    return false;
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1378
  }
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1379
  return true;
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1380
}
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1382
/**
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1383
 * This one function is exported, used by NativeLookup.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1384
 */
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1385
JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
8883
5569135acca3 6817525: turn on method handle functionality by default for JSR 292
twisti
parents: 8676
diff changeset
  1386
  if (!EnableInvokeDynamic) {
5569135acca3 6817525: turn on method handle functionality by default for JSR 292
twisti
parents: 8676
diff changeset
  1387
    warning("JSR 292 is disabled in this JVM.  Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable.");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1388
    return;  // bind nothing
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1389
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1390
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1391
  assert(!MethodHandles::enabled(), "must not be enabled");
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1392
  bool enable_MH = true;
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1393
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1394
  jclass MH_class = NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1395
  if (SystemDictionary::MethodHandle_klass() == NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1396
    enable_MH = false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1397
  } else {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1398
    oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1399
    MH_class = (jclass) JNIHandles::make_local(env, mirror);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1400
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1401
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1402
  if (enable_MH) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1403
    ThreadToNativeFromVM ttnfv(thread);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1404
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1405
    if (enable_MH) {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1406
      enable_MH = register_natives(env, MHN_class, MHN_methods, sizeof(MHN_methods)/sizeof(JNINativeMethod));
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1407
    }
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1408
    if (enable_MH) {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1409
      enable_MH = register_natives(env, MH_class, MH_methods, sizeof(MH_methods)/sizeof(JNINativeMethod));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1410
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1411
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1412
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1413
  if (TraceInvokeDynamic) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1414
    tty->print_cr("MethodHandle support loaded (using LambdaForms)");
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1415
  }
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1416
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1417
  if (enable_MH) {
7887
7aa0354cbf25 7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents: 7712
diff changeset
  1418
    MethodHandles::generate_adapters();
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1419
    MethodHandles::set_enabled(true);
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1420
  }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1421
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1422
JVM_END