src/hotspot/share/prims/methodHandles.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 58722 cba8afa5cfed
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
     1
/*
53547
9d1a788dea3d 8217921: Runtime dead code removal
redestad
parents: 52819
diff changeset
     2
 * Copyright (c) 2008, 2019, 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"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28374
diff changeset
    26
#include "classfile/javaClasses.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents: 22250
diff changeset
    27
#include "classfile/stringTable.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54623
diff changeset
    28
#include "classfile/symbolTable.hpp"
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27694
diff changeset
    29
#include "code/codeCache.hpp"
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
    30
#include "code/dependencyContext.hpp"
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 10004
diff changeset
    31
#include "compiler/compileBroker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    32
#include "interpreter/interpreter.hpp"
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 9638
diff changeset
    33
#include "interpreter/oopMapCache.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28374
diff changeset
    34
#include "interpreter/linkResolver.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    35
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    36
#include "memory/oopFactory.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37179
diff changeset
    37
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54623
diff changeset
    38
#include "memory/universe.hpp"
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54623
diff changeset
    39
#include "oops/objArrayKlass.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28374
diff changeset
    40
#include "oops/objArrayOop.inline.hpp"
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28374
diff changeset
    41
#include "oops/oop.inline.hpp"
49036
bc92debe57e4 8197999: Accessors in typeArrayOopDesc should use new Access API
rkennke
parents: 48826
diff changeset
    42
#include "oops/typeArrayOop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    43
#include "prims/methodHandles.hpp"
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58177
diff changeset
    44
#include "runtime/deoptimization.hpp"
51467
12997ebbc0d8 8209647: constantPoolHandle::constantPoolHandle(ConstantPool*) when precompiled header is disabled
iklam
parents: 51329
diff changeset
    45
#include "runtime/fieldDescriptor.inline.hpp"
53582
881c5fbeb849 8218041: Assorted wrong/missing includes
rehn
parents: 53547
diff changeset
    46
#include "runtime/handles.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49192
diff changeset
    47
#include "runtime/interfaceSupport.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    48
#include "runtime/javaCalls.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49036
diff changeset
    49
#include "runtime/jniHandles.inline.hpp"
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents: 36199
diff changeset
    50
#include "runtime/timerTrace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    51
#include "runtime/reflection.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49449
diff changeset
    52
#include "runtime/safepointVerifiers.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    53
#include "runtime/signature.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    54
#include "runtime/stubRoutines.hpp"
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    55
#include "utilities/exceptions.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7113
diff changeset
    56
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    57
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    58
/*
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    59
 * 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
    60
 * 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
    61
 * 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
    62
 * 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
    63
 * 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
    64
 *
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    65
 * 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
    66
 * 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
    67
 * 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
    68
 * 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
    69
 * by a runtime coded in Java.
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    70
 */
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    71
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
    72
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
    73
MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL;
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    74
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    75
/**
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    76
 * Generates method handle adapters. Returns 'false' if memory allocation
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    77
 * failed and true otherwise.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    78
 */
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
    79
void MethodHandles::generate_adapters() {
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
    80
  assert(SystemDictionary::MethodHandle_klass() != NULL, "should be present");
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    81
  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
    82
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    83
  ResourceMark rm;
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents: 36199
diff changeset
    84
  TraceTime timer("MethodHandles adapters generation", TRACETIME_LOG(Info, startuptime));
9976
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 9967
diff changeset
    85
  _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size);
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    86
  CodeBuffer code(_adapter_code);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    87
  MethodHandlesAdapterGenerator g(&code);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    88
  g.generate();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 24429
diff changeset
    89
  code.log_section_sizes("MethodHandlesAdapterBlob");
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    90
}
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    91
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    92
//------------------------------------------------------------------------------
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    93
// MethodHandlesAdapterGenerator::generate
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    94
//
7887
7aa0354cbf25 7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents: 7712
diff changeset
    95
void MethodHandlesAdapterGenerator::generate() {
5050
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
    96
  // 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
    97
  // Generate interpreter entries
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
    98
  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
    99
       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
   100
       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
   101
    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
   102
    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
   103
    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
   104
    if (entry != NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   105
      Interpreter::set_entry_for_kind(mk, entry);
9630
d6419e4395e3 6939861: JVM should handle more conversion operations
never
parents: 9323
diff changeset
   106
    }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   107
    // 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
   108
  }
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
   109
}
47ecd86932ce 6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents: 4571
diff changeset
   110
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   111
void MethodHandles::set_enabled(bool z) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   112
  if (_enabled != z) {
24322
c2978d1578e3 8036956: remove EnableInvokeDynamic flag
anoll
parents: 22250
diff changeset
   113
    guarantee(z, "can only enable once");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   114
    _enabled = z;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   115
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   116
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   117
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   118
// MemberName support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   119
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   120
// import java_lang_invoke_MemberName.*
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   121
enum {
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   122
  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
   123
  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
   124
  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
   125
  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
   126
  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
   127
  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
   128
  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
   129
  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
   130
  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
   131
  ALL_KINDS      = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   132
};
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   133
48514
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   134
int MethodHandles::ref_kind_to_flags(int ref_kind) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   135
  assert(ref_kind_is_valid(ref_kind), "%d", ref_kind);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   136
  int flags = (ref_kind << REFERENCE_KIND_SHIFT);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   137
  if (ref_kind_is_field(ref_kind)) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   138
    flags |= IS_FIELD;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   139
  } else if (ref_kind_is_method(ref_kind)) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   140
    flags |= IS_METHOD;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   141
  } else if (ref_kind == JVM_REF_newInvokeSpecial) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   142
    flags |= IS_CONSTRUCTOR;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   143
  }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   144
  return flags;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   145
}
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   146
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   147
Handle MethodHandles::resolve_MemberName_type(Handle mname, Klass* caller, TRAPS) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   148
  Handle empty;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   149
  Handle type(THREAD, java_lang_invoke_MemberName::type(mname()));
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   150
  if (!java_lang_String::is_instance_inlined(type())) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   151
    return type; // already resolved
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   152
  }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   153
  Symbol* signature = java_lang_String::as_symbol_or_null(type());
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   154
  if (signature == NULL) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   155
    return empty;  // no such signature exists in the VM
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   156
  }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   157
  Handle resolved;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   158
  int flags = java_lang_invoke_MemberName::flags(mname());
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   159
  switch (flags & ALL_KINDS) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   160
    case IS_METHOD:
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   161
    case IS_CONSTRUCTOR:
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   162
      resolved = SystemDictionary::find_method_handle_type(signature, caller, CHECK_(empty));
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   163
      break;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   164
    case IS_FIELD:
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   165
      resolved = SystemDictionary::find_field_handle_type(signature, caller, CHECK_(empty));
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   166
      break;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   167
    default:
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   168
      THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   169
  }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   170
  if (resolved.is_null()) {
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   171
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MemberName type", empty);
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   172
  }
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   173
  return resolved;
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   174
}
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 48157
diff changeset
   175
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   176
oop MethodHandles::init_MemberName(Handle mname, Handle target, TRAPS) {
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   177
  // This method is used from java.lang.invoke.MemberName constructors.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   178
  // It fills in the new MemberName from a java.lang.reflect.Member.
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   179
  Thread* thread = Thread::current();
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   180
  oop target_oop = target();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   181
  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
   182
  if (target_klass == SystemDictionary::reflect_Field_klass()) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   183
    oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder()
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   184
    int slot  = java_lang_reflect_Field::slot(target_oop);  // fd.index()
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   185
    Klass* k = java_lang_Class::as_Klass(clazz);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   186
    if (k != NULL && k->is_instance_klass()) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   187
      fieldDescriptor fd(InstanceKlass::cast(k), slot);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   188
      oop mname2 = init_field_MemberName(mname, fd);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   189
      if (mname2 != NULL) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   190
        // Since we have the reified name and type handy, add them to the result.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   191
        if (java_lang_invoke_MemberName::name(mname2) == NULL)
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   192
          java_lang_invoke_MemberName::set_name(mname2, java_lang_reflect_Field::name(target_oop));
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   193
        if (java_lang_invoke_MemberName::type(mname2) == NULL)
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   194
          java_lang_invoke_MemberName::set_type(mname2, java_lang_reflect_Field::type(target_oop));
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   195
      }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   196
      return mname2;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   197
    }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   198
  } 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
   199
    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
   200
    int slot   = java_lang_reflect_Method::slot(target_oop);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   201
    Klass* k = java_lang_Class::as_Klass(clazz);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   202
    if (k != NULL && k->is_instance_klass()) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   203
      Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   204
      if (m == NULL || is_signature_polymorphic(m->intrinsic_id()))
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   205
        return NULL;            // do not resolve unless there is a concrete signature
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   206
      CallInfo info(m, k, CHECK_NULL);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   207
      return init_method_MemberName(mname, info);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   208
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   209
  } 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
   210
    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
   211
    int slot   = java_lang_reflect_Constructor::slot(target_oop);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   212
    Klass* k = java_lang_Class::as_Klass(clazz);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   213
    if (k != NULL && k->is_instance_klass()) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   214
      Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   215
      if (m == NULL)  return NULL;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   216
      CallInfo info(m, k, CHECK_NULL);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   217
      return init_method_MemberName(mname, info);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   218
    }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   219
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   220
  return NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   221
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   222
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   223
oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info) {
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   224
  assert(info.resolved_appendix().is_null(), "only normal methods here");
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58722
diff changeset
   225
  methodHandle m(Thread::current(), info.resolved_method());
30615
4713e7c7b96f 8030680: 292 cleanup from default method code assessment
acorn
parents: 30310
diff changeset
   226
  assert(m.not_null(), "null method handle");
51329
9c68699bebe5 8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents: 50771
diff changeset
   227
  InstanceKlass* m_klass = m->method_holder();
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   228
  assert(m_klass != NULL, "null holder for method handle");
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   229
  int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS );
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   230
  int vmindex = Method::invalid_vtable_index;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   231
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   232
  switch (info.call_kind()) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   233
  case CallInfo::itable_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   234
    vmindex = info.itable_index();
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   235
    // More importantly, the itable index only works with the method holder.
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   236
    assert(m_klass->verify_itable_index(vmindex), "");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   237
    flags |= IS_METHOD | (JVM_REF_invokeInterface << REFERENCE_KIND_SHIFT);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   238
    if (TraceInvokeDynamic) {
35543
0961315f4016 8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents: 35086
diff changeset
   239
      ttyLocker ttyl;
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   240
      ResourceMark rm;
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   241
      tty->print_cr("memberName: invokeinterface method_holder::method: %s, itableindex: %d, access_flags:",
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   242
            Method::name_and_sig_as_C_string(m->method_holder(), m->name(), m->signature()),
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   243
            vmindex);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   244
       m->access_flags().print_on(tty);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   245
       if (!m->is_abstract()) {
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   246
         if (!m->is_private()) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   247
           tty->print("default");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   248
         }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   249
         else {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   250
           tty->print("private-intf");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   251
         }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   252
       }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   253
       tty->cr();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   254
    }
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   255
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   256
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   257
  case CallInfo::vtable_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   258
    vmindex = info.vtable_index();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   259
    flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   260
    assert(info.resolved_klass()->is_subtype_of(m_klass), "virtual call must be type-safe");
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   261
    if (m_klass->is_interface()) {
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   262
      // This is a vtable call to an interface method (abstract "miranda method" or default method).
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   263
      // The vtable index is meaningless without a class (not interface) receiver type, so get one.
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   264
      // (LinkResolver should help us figure this out.)
51329
9c68699bebe5 8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents: 50771
diff changeset
   265
      assert(info.resolved_klass()->is_instance_klass(), "subtype of interface must be an instance klass");
9c68699bebe5 8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents: 50771
diff changeset
   266
      InstanceKlass* m_klass_non_interface = InstanceKlass::cast(info.resolved_klass());
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   267
      if (m_klass_non_interface->is_interface()) {
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   268
        m_klass_non_interface = SystemDictionary::Object_klass();
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   269
#ifdef ASSERT
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   270
        { ResourceMark rm;
46408
70aab0c2ea8b 8178350: klassVtable and klassItable should be ValueObj
iklam
parents: 46329
diff changeset
   271
          Method* m2 = m_klass_non_interface->vtable().method_at(vmindex);
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   272
          assert(m->name() == m2->name() && m->signature() == m2->signature(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
   273
                 "at %d, %s != %s", vmindex,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
   274
                 m->name_and_sig_as_C_string(), m2->name_and_sig_as_C_string());
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   275
        }
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   276
#endif //ASSERT
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   277
      }
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   278
      if (!m->is_public()) {
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   279
        assert(m->is_public(), "virtual call must be to public interface method");
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   280
        return NULL;  // elicit an error later in product build
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   281
      }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   282
      assert(info.resolved_klass()->is_subtype_of(m_klass_non_interface), "virtual call must be type-safe");
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   283
      m_klass = m_klass_non_interface;
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   284
    }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   285
    if (TraceInvokeDynamic) {
35543
0961315f4016 8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents: 35086
diff changeset
   286
      ttyLocker ttyl;
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   287
      ResourceMark rm;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   288
      tty->print_cr("memberName: invokevirtual method_holder::method: %s, receiver: %s, vtableindex: %d, access_flags:",
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   289
            Method::name_and_sig_as_C_string(m->method_holder(), m->name(), m->signature()),
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
   290
            m_klass->internal_name(), vmindex);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   291
       m->access_flags().print_on(tty);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   292
       if (m->is_default_method()) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   293
         tty->print("default");
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   294
       }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   295
       tty->cr();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20017
diff changeset
   296
    }
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   297
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   298
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   299
  case CallInfo::direct_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   300
    vmindex = Method::nonvirtual_vtable_index;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   301
    if (m->is_static()) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   302
      flags |= IS_METHOD      | (JVM_REF_invokeStatic  << REFERENCE_KIND_SHIFT);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   303
    } else if (m->is_initializer()) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   304
      flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   305
    } else {
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   306
      // "special" reflects that this is a direct call, not that it
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   307
      // necessarily originates from an invokespecial. We can also do
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 49658
diff changeset
   308
      // direct calls for private and/or final non-static methods.
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   309
      flags |= IS_METHOD      | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   310
    }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   311
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   312
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   313
  default:  assert(false, "bad CallInfo");  return NULL;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   314
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   315
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   316
  // @CallerSensitive annotation detected
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   317
  if (m->caller_sensitive()) {
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   318
    flags |= CALLER_SENSITIVE;
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   319
  }
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 14825
diff changeset
   320
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   321
  Handle resolved_method = info.resolved_method_name();
54389
772f62a13376 8221437: assert(java_lang_invoke_ResolvedMethodName::vmtarget(resolved_method()) == m()) failed: Should not change after link resolution
lmesnik
parents: 53745
diff changeset
   322
  assert(java_lang_invoke_ResolvedMethodName::vmtarget(resolved_method()) == m() || m->is_old(),
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   323
         "Should not change after link resolution");
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   324
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   325
  oop mname_oop = mname();
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   326
  java_lang_invoke_MemberName::set_flags  (mname_oop, flags);
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   327
  java_lang_invoke_MemberName::set_method (mname_oop, resolved_method());
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   328
  java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);   // vtable/itable index
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   329
  java_lang_invoke_MemberName::set_clazz  (mname_oop, m_klass->java_mirror());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   330
  // 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
   331
  // 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
   332
  // 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
   333
  // 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
   334
  // constructing any new objects.
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   335
  return mname();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   336
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   337
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   338
oop MethodHandles::init_field_MemberName(Handle mname, fieldDescriptor& fd, bool is_setter) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   339
  int flags = (jushort)( fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS );
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   340
  flags |= IS_FIELD | ((fd.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   341
  if (is_setter)  flags += ((JVM_REF_putField - JVM_REF_getField) << REFERENCE_KIND_SHIFT);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   342
  int vmindex        = fd.offset();  // determines the field uniquely when combined with static bit
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   343
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   344
  oop mname_oop = mname();
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   345
  java_lang_invoke_MemberName::set_flags  (mname_oop, flags);
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   346
  java_lang_invoke_MemberName::set_method (mname_oop, NULL);
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   347
  java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex);
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   348
  java_lang_invoke_MemberName::set_clazz  (mname_oop, fd.field_holder()->java_mirror());
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   349
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   350
  oop type = field_signature_type_or_null(fd.signature());
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   351
  oop name = field_name_or_null(fd.name());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   352
  if (name != NULL)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   353
    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
   354
  if (type != NULL)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   355
    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
   356
  // 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
   357
  // 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
   358
  // 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
   359
  // 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
   360
  // 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
   361
  // 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
   362
  // 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
   363
  // 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
   364
  return mname();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   365
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   366
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   367
// JVM 2.9 Special Methods:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   368
// A method is signature polymorphic if and only if all of the following conditions hold :
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   369
// * It is declared in the java.lang.invoke.MethodHandle/VarHandle classes.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   370
// * It has a single formal parameter of type Object[].
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   371
// * It has a return type of Object for a polymorphic return type, otherwise a fixed return type.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   372
// * 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
   373
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
   374
  if (klass == NULL)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   375
    return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   376
  // 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
   377
  //    if (klass != SystemDictionary::MethodHandle_klass())
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   378
  // Test the name instead:
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   379
  if (klass->name() != vmSymbols::java_lang_invoke_MethodHandle() &&
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   380
      klass->name() != vmSymbols::java_lang_invoke_VarHandle()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   381
    return false;
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   382
  }
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   383
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   384
  // Look up signature polymorphic method with polymorphic return type
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   385
  Symbol* poly_sig = vmSymbols::object_array_object_signature();
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   386
  InstanceKlass* iklass = InstanceKlass::cast(klass);
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   387
  Method* m = iklass->find_method(name, poly_sig);
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   388
  if (m != NULL) {
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   389
    int required = JVM_ACC_NATIVE | JVM_ACC_VARARGS;
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   390
    int flags = m->access_flags().as_int();
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   391
    if ((flags & required) == required) {
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   392
      return true;
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   393
    }
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   394
  }
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   395
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   396
  // Look up signature polymorphic method with non-polymorphic (non Object) return type
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   397
  int me;
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   398
  int ms = iklass->find_method_by_name(name, &me);
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   399
  if (ms == -1) return false;
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   400
  for (; ms < me; ms++) {
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   401
    Method* m = iklass->methods()->at(ms);
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   402
    int required = JVM_ACC_NATIVE | JVM_ACC_VARARGS;
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   403
    int flags = m->access_flags().as_int();
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   404
    if ((flags & required) == required && ArgumentCount(m->signature()).size() == 1) {
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   405
      return true;
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   406
    }
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   407
  }
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   408
  return false;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   409
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   410
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   411
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   412
Symbol* MethodHandles::signature_polymorphic_intrinsic_name(vmIntrinsics::ID iid) {
33198
dlong
parents: 33105 33160
diff changeset
   413
  assert(is_signature_polymorphic_intrinsic(iid), "%d %s", iid, vmIntrinsics::name_at(iid));
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   414
  switch (iid) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   415
  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
   416
  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
   417
  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
   418
  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
   419
  case vmIntrinsics::_linkToInterface:  return vmSymbols::linkToInterface_name();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46505
diff changeset
   420
  default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46505
diff changeset
   421
    fatal("unexpected intrinsic id: %d %s", iid, vmIntrinsics::name_at(iid));
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46505
diff changeset
   422
    return 0;
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
   423
  }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   424
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   425
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   426
Bytecodes::Code MethodHandles::signature_polymorphic_intrinsic_bytecode(vmIntrinsics::ID id) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   427
  switch(id) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   428
    case vmIntrinsics::_linkToVirtual:   return Bytecodes::_invokevirtual;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   429
    case vmIntrinsics::_linkToInterface: return Bytecodes::_invokeinterface;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   430
    case vmIntrinsics::_linkToStatic:    return Bytecodes::_invokestatic;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   431
    case vmIntrinsics::_linkToSpecial:   return Bytecodes::_invokespecial;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   432
    case vmIntrinsics::_invokeBasic:     return Bytecodes::_invokehandle;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   433
    default:
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   434
      fatal("unexpected id: (%d) %s", (uint)id, vmIntrinsics::name_at(id));
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   435
      return Bytecodes::_illegal;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   436
  }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   437
}
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34317
diff changeset
   438
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   439
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
   440
  switch (iid) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   441
  case vmIntrinsics::_invokeBasic:      return 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   442
  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
   443
  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
   444
  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
   445
  case vmIntrinsics::_linkToInterface:  return JVM_REF_invokeInterface;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46505
diff changeset
   446
  default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46505
diff changeset
   447
    fatal("unexpected intrinsic id: %d %s", iid, vmIntrinsics::name_at(iid));
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46505
diff changeset
   448
    return 0;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   449
  }
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
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
   453
  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
   454
  switch (name_id) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   455
  // 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
   456
  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
   457
  // 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
   458
  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
   459
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   460
  // 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
   461
  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
   462
  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
   463
  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
   464
  case vmSymbols::VM_SYMBOL_ENUM_NAME(linkToInterface_name):  return vmIntrinsics::_linkToInterface;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46505
diff changeset
   465
  default:                                                    break;
13391
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
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   468
  // 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
   469
  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
   470
                              SystemDictionary::WK_KLASS_ENUM_NAME(MethodHandle_klass) );
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   471
  if (mh_klass != NULL && is_method_handle_invoke_name(mh_klass, name)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   472
    return vmIntrinsics::_invokeGeneric;
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   473
  }
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   474
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   475
  // Cover the case of methods on VarHandle.
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   476
  Klass* vh_klass = SystemDictionary::well_known_klass(
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   477
                              SystemDictionary::WK_KLASS_ENUM_NAME(VarHandle_klass) );
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   478
  if (vh_klass != NULL && is_method_handle_invoke_name(vh_klass, name)) {
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   479
    return vmIntrinsics::_invokeGeneric;
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   480
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   481
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   482
  // 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
   483
  // 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
   484
  return vmIntrinsics::_none;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   485
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   486
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   487
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
   488
  if (klass != NULL &&
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   489
      (klass->name() == vmSymbols::java_lang_invoke_MethodHandle() ||
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 36199
diff changeset
   490
       klass->name() == vmSymbols::java_lang_invoke_VarHandle())) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   491
    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
   492
    if (iid != vmIntrinsics::_none)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   493
      return iid;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   494
    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
   495
      return vmIntrinsics::_invokeGeneric;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   496
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   497
  return vmIntrinsics::_none;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   498
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   499
50771
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   500
// Returns true if method is signature polymorphic and public
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   501
bool MethodHandles::is_signature_polymorphic_public_name(Klass* klass, Symbol* name) {
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   502
  if (is_signature_polymorphic_name(klass, name)) {
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   503
    InstanceKlass* iklass = InstanceKlass::cast(klass);
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   504
    int me;
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   505
    int ms = iklass->find_method_by_name(name, &me);
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   506
    assert(ms != -1, "");
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   507
    for (; ms < me; ms++) {
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   508
      Method* m = iklass->methods()->at(ms);
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   509
      int required = JVM_ACC_NATIVE | JVM_ACC_VARARGS | JVM_ACC_PUBLIC;
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   510
      int flags = m->access_flags().as_int();
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   511
      if ((flags & required) == required && ArgumentCount(m->signature()).size() == 1) {
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   512
        return true;
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   513
      }
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   514
    }
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   515
  }
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   516
  return false;
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   517
}
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   518
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   519
// 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
   520
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
   521
  if (java_lang_invoke_MethodType::is_instance(type_str)) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   522
    return java_lang_invoke_MethodType::as_signature(type_str, intern_if_not_found);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   523
  } else if (java_lang_Class::is_instance(type_str)) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   524
    return java_lang_Class::as_signature(type_str, false);
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28374
diff changeset
   525
  } else if (java_lang_String::is_instance_inlined(type_str)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   526
    if (intern_if_not_found) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   527
      return java_lang_String::as_symbol(type_str);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   528
    } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   529
      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
   530
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   531
  } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   532
    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
   533
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   534
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   535
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   536
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
   537
enum { OBJ_SIG_LEN = 18 };
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
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
   540
  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
   541
  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
   542
  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
   543
  for (int i = 0; i < len; i++) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51467
diff changeset
   544
    switch (sig->char_at(i)) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   545
    case JVM_SIGNATURE_CLASS:
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   546
      // 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
   547
      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
   548
        return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   549
      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
   550
      continue;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   551
    case JVM_SIGNATURE_FUNC:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   552
    case JVM_SIGNATURE_ENDFUNC:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   553
    case JVM_SIGNATURE_VOID:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   554
    case JVM_SIGNATURE_INT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   555
    case JVM_SIGNATURE_LONG:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   556
    case JVM_SIGNATURE_FLOAT:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   557
    case JVM_SIGNATURE_DOUBLE:
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   558
      continue;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   559
    default:
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   560
      // subword types (T_BYTE etc.), arrays
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   561
      return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   562
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   563
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   564
  return true;
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
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   567
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
   568
  Symbol* bsig = NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   569
  if (sig == NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   570
    return sig;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   571
  } 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
   572
    sig->increment_refcount();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   573
    return sig;  // that was easy
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   574
  } else if (sig->char_at(0) != JVM_SIGNATURE_FUNC) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51467
diff changeset
   575
    BasicType bt = char2type(sig->char_at(0));
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   576
    if (is_subword_type(bt)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   577
      bsig = vmSymbols::int_signature();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   578
    } else {
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 58226
diff changeset
   579
      assert(is_reference_type(bt), "is_basic_type_signature was false");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   580
      bsig = vmSymbols::object_signature();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   581
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   582
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   583
    ResourceMark rm;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   584
    stringStream buffer(128);
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   585
    buffer.put(JVM_SIGNATURE_FUNC);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   586
    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
   587
    if (keep_last_arg)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   588
      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
   589
    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
   590
      BasicType bt = ss.type();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   591
      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
   592
      if (ss.at_return_type()) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   593
        buffer.put(JVM_SIGNATURE_ENDFUNC);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   594
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   595
      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
   596
        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
   597
                     (int)   ss.raw_length());
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 58226
diff changeset
   598
      } else if (is_reference_type(bt)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   599
        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
   600
      } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   601
        if (is_subword_type(bt))
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   602
          bt = T_INT;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   603
        buffer.put(type2char(bt));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   604
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   605
      arg_pos++;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   606
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   607
    const char* sigstr =       buffer.base();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   608
    int         siglen = (int) buffer.size();
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   609
    bsig = SymbolTable::new_symbol(sigstr, siglen);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   610
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   611
  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
   612
         // 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
   613
         keep_last_arg, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   614
  return bsig;
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
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   617
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
   618
                                                     Symbol* sig,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   619
                                                     bool keep_arrays,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   620
                                                     bool keep_basic_names) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   621
  st = st ? st : tty;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   622
  int len  = sig->utf8_length();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   623
  int array = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   624
  bool prev_type = false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   625
  for (int i = 0; i < len; i++) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51467
diff changeset
   626
    char ch = sig->char_at(i);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   627
    switch (ch) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   628
    case JVM_SIGNATURE_FUNC:
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   629
    case JVM_SIGNATURE_ENDFUNC:
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   630
      prev_type = false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   631
      st->put(ch);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   632
      continue;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   633
    case JVM_SIGNATURE_ARRAY:
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   634
      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
   635
        st->put(ch);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   636
      array++;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   637
      continue;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   638
    case JVM_SIGNATURE_CLASS:
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   639
      {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   640
        if (prev_type)  st->put(',');
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   641
        int start = i+1, slash = start;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   642
        while (++i < len && (ch = sig->char_at(i)) != JVM_SIGNATURE_ENDCLASS) {
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   643
          if (ch == JVM_SIGNATURE_SLASH || ch == JVM_SIGNATURE_DOT || ch == '$')  slash = i+1;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   644
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   645
        if (slash < i)  start = slash;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   646
        if (!keep_basic_names) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   647
          st->put(JVM_SIGNATURE_CLASS);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   648
        } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   649
          for (int j = start; j < i; j++)
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51467
diff changeset
   650
            st->put(sig->char_at(j));
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   651
          prev_type = true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   652
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   653
        break;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   654
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   655
    default:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   656
      {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   657
        if (array && char2type(ch) != T_ILLEGAL && !keep_arrays) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   658
          ch = JVM_SIGNATURE_ARRAY;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   659
          array = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   660
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   661
        if (prev_type)  st->put(',');
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   662
        const char* n = NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   663
        if (keep_basic_names)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   664
          n = type2name(char2type(ch));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   665
        if (n == NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   666
          // 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
   667
          st->put(ch);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   668
        } else {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24322
diff changeset
   669
          st->print("%s", n);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   670
          prev_type = true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   671
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   672
        break;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   673
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   674
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   675
    // 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
   676
    if (prev_type) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   677
      while (array > 0) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   678
        st->print("[]");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   679
        --array;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   680
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   681
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   682
    array = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   683
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   684
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   685
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   686
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   687
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   688
static oop object_java_mirror() {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   689
  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
   690
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   691
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   692
oop MethodHandles::field_name_or_null(Symbol* s) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   693
  if (s == NULL)  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   694
  return StringTable::lookup(s);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   695
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   696
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   697
oop MethodHandles::field_signature_type_or_null(Symbol* s) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   698
  if (s == NULL)  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   699
  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
   700
  if (is_java_primitive(bt)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   701
    assert(s->utf8_length() == 1, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   702
    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
   703
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   704
  // 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
   705
  // 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
   706
  if (bt == T_OBJECT) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   707
    if (s == vmSymbols::object_signature()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   708
      return object_java_mirror();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   709
    } else if (s == vmSymbols::class_signature()) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   710
      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
   711
    } else if (s == vmSymbols::string_signature()) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   712
      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
   713
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   714
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   715
  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   716
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   717
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   718
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   719
// An unresolved member name is a mere symbolic reference.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   720
// 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
   721
// which refers directly to JVM internals.
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   722
Handle MethodHandles::resolve_MemberName(Handle mname, Klass* caller,
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   723
                                         bool speculative_resolve, TRAPS) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   724
  Handle empty;
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   725
  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
   726
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   727
  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
   728
    // Already resolved.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   729
    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
   730
    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
   731
    return mname;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   732
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   733
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   734
  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
   735
  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
   736
  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
   737
  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
   738
  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
   739
  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
   740
    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
   741
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   742
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   743
  DEBUG_ONLY(int old_vmindex);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   744
  assert((old_vmindex = java_lang_invoke_MemberName::vmindex(mname())) == 0, "clean input");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   745
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   746
  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
   747
    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve", empty);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   748
  }
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   749
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   750
  InstanceKlass* defc = NULL;
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   751
  {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   752
    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
   753
    if (defc_klass == NULL)  return empty;  // a primitive; no resolution possible
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33198
diff changeset
   754
    if (!defc_klass->is_instance_klass()) {
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33198
diff changeset
   755
      if (!defc_klass->is_array_klass())  return empty;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   756
      defc_klass = SystemDictionary::Object_klass();
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   757
    }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   758
    defc = InstanceKlass::cast(defc_klass);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   759
  }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   760
  if (defc == NULL) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   761
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "primitive class", empty);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   762
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   763
  defc->link_class(CHECK_(empty));  // possible safepoint
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   764
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   765
  // 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
   766
  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
   767
  if (name == NULL)  return empty;  // no such name
10004
190e88f7edd1 7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents: 9980
diff changeset
   768
  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
   769
    return empty; // illegal name
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   770
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   771
  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
   772
  if ((flags & ALL_KINDS) == IS_METHOD &&
50771
9ca95539747d 8195650: Method references to VarHandle accessors
psandoz
parents: 50735
diff changeset
   773
      (defc == SystemDictionary::MethodHandle_klass() || defc == SystemDictionary::VarHandle_klass()) &&
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   774
      (ref_kind == JVM_REF_invokeVirtual ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   775
       ref_kind == JVM_REF_invokeSpecial ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   776
       // 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
   777
       ref_kind == JVM_REF_invokeStatic)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   778
    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
   779
    if (iid != vmIntrinsics::_none &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   780
        ((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
   781
      // 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
   782
      // 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
   783
      mh_invoke_id = iid;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   784
    }
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
   785
  }
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 5420
diff changeset
   786
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   787
  // 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
   788
  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
   789
  if (type == NULL)  return empty;  // no such signature exists in the VM
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   790
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   791
  LinkInfo::AccessCheck access_check = caller != NULL ?
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38259
diff changeset
   792
                                              LinkInfo::needs_access_check :
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38259
diff changeset
   793
                                              LinkInfo::skip_access_check;
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38259
diff changeset
   794
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   795
  // Time to do the lookup.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   796
  switch (flags & ALL_KINDS) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   797
  case IS_METHOD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   798
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   799
      CallInfo result;
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38259
diff changeset
   800
      LinkInfo link_info(defc, name, type, caller, access_check);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   801
      {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   802
        assert(!HAS_PENDING_EXCEPTION, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   803
        if (ref_kind == JVM_REF_invokeStatic) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   804
          LinkResolver::resolve_static_call(result,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30615
diff changeset
   805
                        link_info, false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   806
        } else if (ref_kind == JVM_REF_invokeInterface) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   807
          LinkResolver::resolve_interface_call(result, Handle(), defc,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30615
diff changeset
   808
                        link_info, false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   809
        } 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
   810
          assert(!is_signature_polymorphic_static(mh_invoke_id), "");
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30615
diff changeset
   811
          LinkResolver::resolve_handle_call(result, link_info, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   812
        } else if (ref_kind == JVM_REF_invokeSpecial) {
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 43929
diff changeset
   813
          LinkResolver::resolve_special_call(result, Handle(),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30615
diff changeset
   814
                        link_info, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   815
        } else if (ref_kind == JVM_REF_invokeVirtual) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   816
          LinkResolver::resolve_virtual_call(result, Handle(), defc,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30615
diff changeset
   817
                        link_info, false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   818
        } else {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
   819
          assert(false, "ref_kind=%d", ref_kind);
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
        if (HAS_PENDING_EXCEPTION) {
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   822
          if (speculative_resolve) {
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   823
            CLEAR_PENDING_EXCEPTION;
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   824
          }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   825
          return empty;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   826
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   827
      }
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   828
      if (result.resolved_appendix().not_null()) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   829
        // The resolved MemberName must not be accompanied by an appendix argument,
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   830
        // since there is no way to bind this value into the MemberName.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   831
        // Caller is responsible to prevent this from happening.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   832
        THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   833
      }
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   834
      result.set_resolved_method_name(CHECK_(empty));
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   835
      oop mname2 = init_method_MemberName(mname, result);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   836
      return Handle(THREAD, mname2);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   837
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   838
  case IS_CONSTRUCTOR:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   839
    {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   840
      CallInfo result;
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38259
diff changeset
   841
      LinkInfo link_info(defc, name, type, caller, access_check);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   842
      {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   843
        assert(!HAS_PENDING_EXCEPTION, "");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   844
        if (name == vmSymbols::object_initializer_name()) {
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 43929
diff changeset
   845
          LinkResolver::resolve_special_call(result, Handle(), link_info, THREAD);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   846
        } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   847
          break;                // will throw after end of switch
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   848
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   849
        if (HAS_PENDING_EXCEPTION) {
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   850
          if (speculative_resolve) {
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   851
            CLEAR_PENDING_EXCEPTION;
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   852
          }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   853
          return empty;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   854
        }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   855
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   856
      assert(result.is_statically_bound(), "");
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   857
      result.set_resolved_method_name(CHECK_(empty));
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   858
      oop mname2 = init_method_MemberName(mname, result);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   859
      return Handle(THREAD, mname2);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   860
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   861
  case IS_FIELD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   862
    {
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   863
      fieldDescriptor result; // find_field initializes fd if found
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   864
      {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   865
        assert(!HAS_PENDING_EXCEPTION, "");
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38259
diff changeset
   866
        LinkInfo link_info(defc, name, type, caller, LinkInfo::skip_access_check);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30615
diff changeset
   867
        LinkResolver::resolve_field(result, link_info, Bytecodes::_nop, false, THREAD);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   868
        if (HAS_PENDING_EXCEPTION) {
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   869
          if (speculative_resolve) {
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   870
            CLEAR_PENDING_EXCEPTION;
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
   871
          }
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   872
          return empty;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   873
        }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   874
      }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   875
      oop mname2 = init_field_MemberName(mname, result, ref_kind_is_setter(ref_kind));
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
   876
      return Handle(THREAD, mname2);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   877
    }
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 5420
diff changeset
   878
  default:
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   879
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   880
  }
5421
e294db54fc0d 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 5420
diff changeset
   881
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   882
  return empty;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   883
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   884
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   885
// Conversely, a member name which is only initialized from JVM internals
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   886
// may have null defc, name, and type fields.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   887
// Resolving it plants a vmtarget/vmindex in it,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   888
// which refers directly to JVM internals.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   889
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
   890
  assert(java_lang_invoke_MemberName::is_instance(mname()), "");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   891
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   892
  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
   893
  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
   894
  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
   895
  int flags      = java_lang_invoke_MemberName::flags(mname());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   896
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   897
  if (suppress != 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   898
    if (suppress & _suppress_defc)  have_defc = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   899
    if (suppress & _suppress_name)  have_name = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   900
    if (suppress & _suppress_type)  have_type = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   901
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   902
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   903
  if (have_defc && have_name && have_type)  return;  // nothing needed
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   904
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   905
  switch (flags & ALL_KINDS) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   906
  case IS_METHOD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   907
  case IS_CONSTRUCTOR:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   908
    {
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   909
      Method* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   910
      if (vmtarget == NULL) {
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   911
        THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand");
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   912
      }
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   913
      methodHandle m(THREAD, vmtarget);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   914
      DEBUG_ONLY(vmtarget = NULL);  // safety
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   915
      if (!have_defc) {
14391
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 13973
diff changeset
   916
        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
   917
        java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   918
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   919
      if (!have_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   920
        //not java_lang_String::create_from_symbol; let's intern member names
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
   921
        oop name = StringTable::intern(m->name(), CHECK);
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
   922
        java_lang_invoke_MemberName::set_name(mname(), name);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   923
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   924
      if (!have_type) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   925
        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
   926
        java_lang_invoke_MemberName::set_type(mname(), type());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   927
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   928
      return;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   929
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   930
  case IS_FIELD:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   931
    {
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   932
      oop clazz = java_lang_invoke_MemberName::clazz(mname());
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   933
      if (clazz == NULL) {
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   934
        THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand (as field)");
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   935
      }
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   936
      InstanceKlass* defc = InstanceKlass::cast(java_lang_Class::as_Klass(clazz));
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   937
      DEBUG_ONLY(clazz = NULL);  // safety
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   938
      int vmindex  = java_lang_invoke_MemberName::vmindex(mname());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   939
      bool is_static = ((flags & JVM_ACC_STATIC) != 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   940
      fieldDescriptor fd; // find_field initializes fd if found
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   941
      if (!defc->find_field_from_offset(vmindex, is_static, &fd))
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   942
        break;                  // cannot expand
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   943
      if (!have_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   944
        //not java_lang_String::create_from_symbol; let's intern member names
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
   945
        oop name = StringTable::intern(fd.name(), CHECK);
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
   946
        java_lang_invoke_MemberName::set_name(mname(), name);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   947
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   948
      if (!have_type) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   949
        // If it is a primitive field type, don't mess with short strings like "I".
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
   950
        Handle type (THREAD, field_signature_type_or_null(fd.signature()));
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   951
        if (type.is_null()) {
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
   952
          type = java_lang_String::create_from_symbol(fd.signature(), CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
   953
        }
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
   954
        java_lang_invoke_MemberName::set_type(mname(), type());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   955
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   956
      return;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   957
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   958
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   959
  THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   960
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   961
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   962
int MethodHandles::find_MemberNames(Klass* k,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
   963
                                    Symbol* name, Symbol* sig,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   964
                                    int mflags, Klass* caller,
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   965
                                    int skip, objArrayHandle results, TRAPS) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   966
  // %%% take caller into account!
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   967
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   968
  Thread* thread = Thread::current();
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
   969
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   970
  if (k == NULL || !k->is_instance_klass())  return -1;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   971
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   972
  int rfill = 0, rlimit = results->length(), rskip = skip;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   973
  // overflow measurement:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   974
  int overflow = 0, overflow_limit = MAX2(1000, rlimit);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   975
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   976
  int match_flags = mflags;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   977
  bool search_superc = ((match_flags & SEARCH_SUPERCLASSES) != 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   978
  bool search_intfc  = ((match_flags & SEARCH_INTERFACES)   != 0);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   979
  bool local_only = !(search_superc | search_intfc);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   980
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   981
  if (name != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   982
    if (name->utf8_length() == 0)  return 0; // a match is not possible
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   983
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   984
  if (sig != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   985
    if (sig->utf8_length() == 0)  return 0; // a match is not possible
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
   986
    if (sig->char_at(0) == JVM_SIGNATURE_FUNC)
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   987
      match_flags &= ~(IS_FIELD | IS_TYPE);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   988
    else
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   989
      match_flags &= ~(IS_CONSTRUCTOR | IS_METHOD);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   990
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   991
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   992
  if ((match_flags & IS_TYPE) != 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   993
    // NYI, and Core Reflection works quite well for this query
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   994
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   995
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   996
  if ((match_flags & IS_FIELD) != 0) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   997
    InstanceKlass* ik = InstanceKlass::cast(k);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
   998
    for (FieldStream st(ik, local_only, !search_intfc); !st.eos(); st.next()) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
   999
      if (name != NULL && st.name() != name)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1000
          continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1001
      if (sig != NULL && st.signature() != sig)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1002
        continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1003
      // passed the filters
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1004
      if (rskip > 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1005
        --rskip;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1006
      } 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
  1007
        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
  1008
        if (!java_lang_invoke_MemberName::is_instance(result()))
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1009
          return -99;  // caller bug!
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 18508
diff changeset
  1010
        oop saved = MethodHandles::init_field_MemberName(result, st.field_descriptor());
58177
4932dce35882 8230841: Remove oopDesc::equals()
pliden
parents: 55479
diff changeset
  1011
        if (saved != result())
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1012
          results->obj_at_put(rfill-1, saved);  // show saved instance to user
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1013
      } else if (++overflow >= overflow_limit) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1014
        match_flags = 0; break; // got tired of looking at overflow
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1015
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1016
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1017
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1018
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1019
  if ((match_flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1020
    // watch out for these guys:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
  1021
    Symbol* init_name   = vmSymbols::object_initializer_name();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
  1022
    Symbol* clinit_name = vmSymbols::class_initializer_name();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1023
    if (name == clinit_name)  clinit_name = NULL; // hack for exposing <clinit>
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1024
    bool negate_name_test = false;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1025
    // fix name so that it captures the intention of IS_CONSTRUCTOR
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1026
    if (!(match_flags & IS_METHOD)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1027
      // constructors only
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1028
      if (name == NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1029
        name = init_name;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1030
      } else if (name != init_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1031
        return 0;               // no constructors of this method name
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1032
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1033
    } else if (!(match_flags & IS_CONSTRUCTOR)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1034
      // methods only
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1035
      if (name == NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1036
        name = init_name;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1037
        negate_name_test = true; // if we see the name, we *omit* the entry
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1038
      } else if (name == init_name) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1039
        return 0;               // no methods of this constructor name
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1040
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1041
    } else {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1042
      // caller will accept either sort; no need to adjust name
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1043
    }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
  1044
    InstanceKlass* ik = InstanceKlass::cast(k);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
  1045
    for (MethodStream st(ik, 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
  1046
      Method* m = st.method();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
  1047
      Symbol* m_name = m->name();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1048
      if (m_name == clinit_name)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1049
        continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1050
      if (name != NULL && ((m_name != name) ^ negate_name_test))
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1051
          continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1052
      if (sig != NULL && m->signature() != sig)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1053
        continue;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1054
      // passed the filters
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1055
      if (rskip > 0) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1056
        --rskip;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1057
      } 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
  1058
        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
  1059
        if (!java_lang_invoke_MemberName::is_instance(result()))
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1060
          return -99;  // caller bug!
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1061
        CallInfo info(m, NULL, CHECK_0);
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1062
        oop saved = MethodHandles::init_method_MemberName(result, info);
58177
4932dce35882 8230841: Remove oopDesc::equals()
pliden
parents: 55479
diff changeset
  1063
        if (saved != result())
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1064
          results->obj_at_put(rfill-1, saved);  // show saved instance to user
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1065
      } else if (++overflow >= overflow_limit) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1066
        match_flags = 0; break; // got tired of looking at overflow
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1067
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1068
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1069
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1070
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1071
  // return number of elements we at leasted wanted to initialize
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1072
  return rfill + overflow;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1073
}
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1074
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1075
void MethodHandles::add_dependent_nmethod(oop call_site, nmethod* nm) {
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1076
  assert_locked_or_safepoint(CodeCache_lock);
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1077
52411
35ebea32a23c 8212996: Use AS_NO_KEEPALIVE when accessing dead java.lang.invoke.CallSites during nmethod unloading
eosterlund
parents: 51997
diff changeset
  1078
  oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1079
  DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1080
  // Try to purge stale entries on updates.
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1081
  // Since GC doesn't clean dependency contexts rooted at CallSiteContext objects,
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1082
  // in order to avoid memory leak, stale entries are purged whenever a dependency list
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1083
  // is changed (both on addition and removal). Though memory reclamation is delayed,
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1084
  // it avoids indefinite memory usage growth.
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1085
  deps.add_dependent_nmethod(nm);
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1086
}
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1087
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1088
void MethodHandles::remove_dependent_nmethod(oop call_site, nmethod* nm) {
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1089
  assert_locked_or_safepoint(CodeCache_lock);
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1090
52411
35ebea32a23c 8212996: Use AS_NO_KEEPALIVE when accessing dead java.lang.invoke.CallSites during nmethod unloading
eosterlund
parents: 51997
diff changeset
  1091
  oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1092
  DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1093
  deps.remove_dependent_nmethod(nm);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1094
}
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1095
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1096
void MethodHandles::clean_dependency_context(oop call_site) {
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1097
  oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1098
  DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52411
diff changeset
  1099
  deps.clean_unloading_dependents();
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1100
}
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1101
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1102
void MethodHandles::flush_dependent_nmethods(Handle call_site, Handle target) {
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1103
  assert_lock_strong(Compile_lock);
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1104
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1105
  int marked = 0;
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
  1106
  CallSiteDepChange changes(call_site, target);
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1107
  {
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 34317
diff changeset
  1108
    NoSafepointVerifier nsv;
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54389
diff changeset
  1109
    MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1110
52411
35ebea32a23c 8212996: Use AS_NO_KEEPALIVE when accessing dead java.lang.invoke.CallSites during nmethod unloading
eosterlund
parents: 51997
diff changeset
  1111
    oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site());
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1112
    DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1113
    marked = deps.mark_dependent_nmethods(changes);
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1114
  }
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1115
  if (marked > 0) {
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1116
    // At least one nmethod has been marked for deoptimization.
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58177
diff changeset
  1117
    Deoptimization::deoptimize_all_marked();
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1118
  }
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1119
}
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1120
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1121
void MethodHandles::trace_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid) {
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1122
  if (TraceMethodHandles) {
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1123
    const char* name = vmIntrinsics::name_at(iid);
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1124
    if (*name == '_')  name += 1;
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1125
    const size_t len = strlen(name) + 50;
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1126
    char* qname = NEW_C_HEAP_ARRAY(char, len, mtInternal);
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1127
    const char* suffix = "";
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1128
    if (is_signature_polymorphic(iid)) {
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1129
      if (is_signature_polymorphic_static(iid))
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1130
        suffix = "/static";
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1131
      else
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1132
        suffix = "/private";
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1133
    }
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1134
    jio_snprintf(qname, len, "MethodHandle::interpreter_entry::%s%s", name, suffix);
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1135
    trace_method_handle(_masm, qname);
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1136
    // Note:  Don't free the allocated char array because it's used
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1137
    // during runtime.
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1138
  }
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1139
}
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
  1140
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1141
//
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1142
// Here are the native methods in java.lang.invoke.MethodHandleNatives
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1143
// They are the private interface between this JVM and the HotSpot-specific
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1144
// Java code that implements JSR 292 method handles.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1145
//
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1146
// 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
  1147
// that intrinsic (non-JNI) native methods are defined in HotSpot.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1148
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1149
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1150
#ifndef PRODUCT
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1151
#define EACH_NAMED_CON(template, requirement) \
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1152
    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
  1153
    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
  1154
    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
  1155
    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
  1156
    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
  1157
    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
  1158
    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
  1159
    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
  1160
    template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_MASK) \
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1161
    /*end*/
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1162
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1163
#define IGNORE_REQ(req_expr) /* req_expr */
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1164
#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
  1165
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
  1166
#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
  1167
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
  1168
#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
  1169
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
  1170
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1171
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
  1172
  if (which < 0)  return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1173
  bool ok = true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1174
  int count = 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1175
#define INC_COUNT(scope,value) \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1176
  ++count;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1177
#define CHECK_REQ(req_expr) \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1178
  if (which < count)  return ok; \
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1179
  ok = (req_expr);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1180
  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
  1181
#undef INC_COUNT
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1182
#undef CHECK_REQ
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1183
  assert(count == con_value_count, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1184
  if (which < count)  return ok;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1185
  return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1186
}
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1187
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1188
#undef ONE_PLUS
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1189
#undef VALUE_COMMA
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1190
#undef STRING_NULL
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1191
#undef EACH_NAMED_CON
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1192
#endif // PRODUCT
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1193
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1194
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
  1195
#ifndef PRODUCT
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1196
  if (advertise_con_value(which)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1197
    assert(which >= 0 && which < con_value_count, "");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1198
    int con = con_values[which];
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1199
    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
  1200
    if (box.not_null() && box->klass() == Universe::objectArrayKlassObj() && box->length() > 0) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1201
      const char* str = &con_names[0];
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1202
      for (int i = 0; i < which; i++)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1203
        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
  1204
      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
  1205
      box->obj_at_put(0, name);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1206
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1207
    return con;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1208
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1209
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1210
  return 0;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1211
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1212
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1213
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1214
// 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
  1215
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
  1216
  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
  1217
  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
  1218
  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
  1219
  Handle target(THREAD, JNIHandles::resolve_non_null(target_jh));
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1220
  MethodHandles::init_MemberName(mname, target, CHECK);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1221
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1222
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1223
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1224
// void expand(MemberName self)
8676
9098d4e927e1 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8675
diff changeset
  1225
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
  1226
  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
  1227
  Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1228
  MethodHandles::expand_MemberName(mname, 0, CHECK);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1229
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1230
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1231
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1232
// void resolve(MemberName self, Class<?> caller)
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1233
JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh,
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1234
    jboolean speculative_resolve)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1235
  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
  1236
  Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1237
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1238
  // 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
  1239
  // 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
  1240
  if (VerifyMethodHandles && caller_jh != NULL &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1241
      java_lang_invoke_MemberName::clazz(mname()) != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1242
    Klass* reference_klass = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33198
diff changeset
  1243
    if (reference_klass != NULL && reference_klass->is_objArray_klass()) {
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
  1244
      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
  1245
    }
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1246
3b95160639d8 8017571: JSR292: JVM crashing on assert "cast to instanceKlass" while producing MethodHandle for array methods with MethodHandle.findVirtual
twisti
parents: 17828
diff changeset
  1247
    // Reflection::verify_class_access can only handle instance classes.
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33198
diff changeset
  1248
    if (reference_klass != NULL && reference_klass->is_instance_klass()) {
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1249
      // Emulate LinkResolver::check_klass_accessability.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1250
      Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
43665
4bb003cad9b9 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42664
diff changeset
  1251
      if (caller != SystemDictionary::Object_klass()
4bb003cad9b9 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42664
diff changeset
  1252
          && Reflection::verify_class_access(caller,
46289
bobv
parents: 43665 46271
diff changeset
  1253
                                             InstanceKlass::cast(reference_klass),
43665
4bb003cad9b9 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42664
diff changeset
  1254
                                             true) != Reflection::ACCESS_OK) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1255
        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
  1256
      }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1257
    }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1258
  }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5050
diff changeset
  1259
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
  1260
  Klass* caller = caller_jh == NULL ? NULL :
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
  1261
                     java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
49646
24aca5861b91 8200424: Windows build fails due to implicit jboolean to bool conversion
redestad
parents: 49641
diff changeset
  1262
  Handle resolved = MethodHandles::resolve_MemberName(mname, caller, speculative_resolve == JNI_TRUE,
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1263
                                                      CHECK_NULL);
22250
fe165bf76695 8029507: Enhance JVM method processing
jrose
parents: 21107
diff changeset
  1264
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1265
  if (resolved.is_null()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1266
    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
  1267
    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
  1268
    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
  1269
      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
  1270
    }
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1271
    if (speculative_resolve) {
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1272
      assert(!HAS_PENDING_EXCEPTION, "No exceptions expected when resolving speculatively");
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1273
      return NULL;
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1274
    }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1275
    if ((flags & ALL_KINDS) == IS_FIELD) {
36833
0f6d4a480a96 8025962: JSR 292: NoSuchMethodError and NoSuchFieldError in MHN_resolve_Mem
vlivanov
parents: 36822
diff changeset
  1276
      THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), "field resolution failed");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1277
    } 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
  1278
               (flags & ALL_KINDS) == IS_CONSTRUCTOR) {
36833
0f6d4a480a96 8025962: JSR 292: NoSuchMethodError and NoSuchFieldError in MHN_resolve_Mem
vlivanov
parents: 36822
diff changeset
  1279
      THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), "method resolution failed");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1280
    } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1281
      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
  1282
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1283
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1284
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1285
  return JNIHandles::make_local(THREAD, resolved());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1286
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1287
JVM_END
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1288
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1289
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
  1290
  if (mname == NULL ||
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1291
      java_lang_invoke_MemberName::clazz(mname) == NULL) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1292
    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
  1293
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1294
    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
  1295
    if ((flags & IS_FIELD) != 0 &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1296
        (must_be_static
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1297
         ? (flags & JVM_ACC_STATIC) != 0
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1298
         : (flags & JVM_ACC_STATIC) == 0)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1299
      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
  1300
      return (jlong) vmindex;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1301
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1302
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1303
  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
  1304
  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
  1305
  return 0;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1306
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1307
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1308
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
  1309
  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
  1310
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1311
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1312
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1313
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
  1314
  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
  1315
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1316
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1317
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1318
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
  1319
  // 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
  1320
  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
  1321
  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
  1322
  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
  1323
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1324
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1325
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1326
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
  1327
  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
  1328
  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
  1329
  intptr_t vmindex  = java_lang_invoke_MemberName::vmindex(mname());
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 46262
diff changeset
  1330
  objArrayHandle result = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 2, CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1331
  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
  1332
  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
  1333
  result->obj_at_put(0, x);
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1334
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1335
  int flags = java_lang_invoke_MemberName::flags(mname());
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1336
  if ((flags & IS_FIELD) != 0) {
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1337
    x = java_lang_invoke_MemberName::clazz(mname());
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1338
  } else {
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1339
    Method* vmtarget = java_lang_invoke_MemberName::vmtarget(mname());
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1340
    assert(vmtarget != NULL && vmtarget->is_method(), "vmtarget is only method");
21107
aa84c4d14e6c 8023004: JSR 292: java.lang.RuntimeException: Original target method was called.
sspitsyn
parents: 20391
diff changeset
  1341
    x = mname();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1342
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1343
  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
  1344
  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
  1345
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1346
JVM_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1347
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1348
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1349
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1350
//  static native int getMembers(Class<?> defc, String matchName, String matchSig,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1351
//          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
  1352
JVM_ENTRY(jint, MHN_getMembers(JNIEnv *env, jobject igcls,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1353
                               jclass clazz_jh, jstring name_jh, jstring sig_jh,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1354
                               int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1355
  if (clazz_jh == NULL || results_jh == NULL)  return -1;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
  1356
  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz_jh));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1357
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1358
  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
  1359
  if (results.is_null() || !results->is_objArray())  return -1;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1360
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
  1361
  TempNewSymbol name = NULL;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7887
diff changeset
  1362
  TempNewSymbol sig = NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1363
  if (name_jh != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1364
    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
  1365
    if (name == NULL)  return 0; // a match is not possible
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1366
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1367
  if (sig_jh != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1368
    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
  1369
    if (sig == NULL)  return 0; // a match is not possible
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1370
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1371
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
  1372
  Klass* caller = NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1373
  if (caller_jh != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1374
    oop caller_oop = JNIHandles::resolve_non_null(caller_jh);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1375
    if (!java_lang_Class::is_instance(caller_oop))  return -1;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46327
diff changeset
  1376
    caller = java_lang_Class::as_Klass(caller_oop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1377
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1378
9323
20cc2230dc8a 7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents: 9134
diff changeset
  1379
  if (name != NULL && sig != NULL && results.not_null()) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1380
    // try a direct resolve
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1381
    // %%% TO DO
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1382
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1383
17029
9ff8d7c0ed79 8008511: JSR 292: MemberName vmtarget refs to methods must be updated at class redefinition
sspitsyn
parents: 17024
diff changeset
  1384
  int res = MethodHandles::find_MemberNames(k, name, sig, mflags,
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
  1385
                                            caller, skip, results, CHECK_0);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1386
  // TO DO: expand at least some of the MemberNames, to avoid massive callbacks
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1387
  return res;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1388
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1389
JVM_END
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
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
  1392
  Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1393
  Handle target   (THREAD, JNIHandles::resolve_non_null(target_jh));
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1394
  {
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1395
    // 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
  1396
    MutexLocker mu(Compile_lock, thread);
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1397
    MethodHandles::flush_dependent_nmethods(call_site, target);
14825
8bc43f610c87 8003238: JSR 292: intermittent exception failure with java/lang/invoke/CallSiteTest.java
twisti
parents: 14488
diff changeset
  1398
    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
  1399
  }
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1400
}
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1401
JVM_END
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1402
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1403
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
  1404
  Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1405
  Handle target   (THREAD, JNIHandles::resolve_non_null(target_jh));
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1406
  {
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1407
    // 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
  1408
    MutexLocker mu(Compile_lock, thread);
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1409
    MethodHandles::flush_dependent_nmethods(call_site, target);
14825
8bc43f610c87 8003238: JSR 292: intermittent exception failure with java/lang/invoke/CallSiteTest.java
twisti
parents: 14488
diff changeset
  1410
    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
  1411
  }
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1412
}
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1413
JVM_END
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1414
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1415
JVM_ENTRY(void, MHN_copyOutBootstrapArguments(JNIEnv* env, jobject igcls,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1416
                                              jobject caller_jh, jintArray index_info_jh,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1417
                                              jint start, jint end,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1418
                                              jobjectArray buf_jh, jint pos,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1419
                                              jboolean resolve, jobject ifna_jh)) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1420
  Klass* caller_k = java_lang_Class::as_Klass(JNIHandles::resolve(caller_jh));
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1421
  if (caller_k == NULL || !caller_k->is_instance_klass()) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1422
      THROW_MSG(vmSymbols::java_lang_InternalError(), "bad caller");
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1423
  }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1424
  InstanceKlass* caller = InstanceKlass::cast(caller_k);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1425
  typeArrayOop index_info_oop = (typeArrayOop) JNIHandles::resolve(index_info_jh);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1426
  if (index_info_oop == NULL ||
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1427
      index_info_oop->klass() != Universe::intArrayKlassObj() ||
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1428
      typeArrayOop(index_info_oop)->length() < 2) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1429
      THROW_MSG(vmSymbols::java_lang_InternalError(), "bad index info (0)");
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1430
  }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1431
  typeArrayHandle index_info(THREAD, index_info_oop);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1432
  int bss_index_in_pool = index_info->int_at(1);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1433
  // While we are here, take a quick look at the index info:
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1434
  if (bss_index_in_pool <= 0 ||
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1435
      bss_index_in_pool >= caller->constants()->length() ||
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1436
      index_info->int_at(0)
53745
a535ba736cab 8218004: Clean up terminology for shared methods within the JVM for indy and condy support
lfoltan
parents: 53582
diff changeset
  1437
      != caller->constants()->bootstrap_argument_count_at(bss_index_in_pool)) {
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1438
      THROW_MSG(vmSymbols::java_lang_InternalError(), "bad index info (1)");
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1439
  }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1440
  objArrayHandle buf(THREAD, (objArrayOop) JNIHandles::resolve(buf_jh));
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1441
  if (start < 0) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1442
    for (int pseudo_index = -4; pseudo_index < 0; pseudo_index++) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1443
      if (start == pseudo_index) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1444
        if (start >= end || 0 > pos || pos >= buf->length())  break;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1445
        oop pseudo_arg = NULL;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1446
        switch (pseudo_index) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1447
        case -4:  // bootstrap method
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1448
          {
53745
a535ba736cab 8218004: Clean up terminology for shared methods within the JVM for indy and condy support
lfoltan
parents: 53582
diff changeset
  1449
            int bsm_index = caller->constants()->bootstrap_method_ref_index_at(bss_index_in_pool);
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1450
            pseudo_arg = caller->constants()->resolve_possibly_cached_constant_at(bsm_index, CHECK);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1451
            break;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1452
          }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1453
        case -3:  // name
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1454
          {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1455
            Symbol* name = caller->constants()->name_ref_at(bss_index_in_pool);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1456
            Handle str = java_lang_String::create_from_symbol(name, CHECK);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1457
            pseudo_arg = str();
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1458
            break;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1459
          }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1460
        case -2:  // type
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1461
          {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1462
            Symbol* type = caller->constants()->signature_ref_at(bss_index_in_pool);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1463
            Handle th;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58545
diff changeset
  1464
            if (type->char_at(0) == JVM_SIGNATURE_FUNC) {
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1465
              th = SystemDictionary::find_method_handle_type(type, caller, CHECK);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1466
            } else {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1467
              th = SystemDictionary::find_java_mirror_for_type(type, caller, SignatureStream::NCDFError, CHECK);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1468
            }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1469
            pseudo_arg = th();
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1470
            break;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1471
          }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1472
        case -1:  // argument count
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1473
          {
53745
a535ba736cab 8218004: Clean up terminology for shared methods within the JVM for indy and condy support
lfoltan
parents: 53582
diff changeset
  1474
            int argc = caller->constants()->bootstrap_argument_count_at(bss_index_in_pool);
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1475
            jvalue argc_value; argc_value.i = (jint)argc;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1476
            pseudo_arg = java_lang_boxing_object::create(T_INT, &argc_value, CHECK);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1477
            break;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1478
          }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1479
        }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1480
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1481
        // Store the pseudo-argument, and advance the pointers.
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1482
        buf->obj_at_put(pos++, pseudo_arg);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1483
        ++start;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1484
      }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1485
    }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1486
    // When we are done with this there may be regular arguments to process too.
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1487
  }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1488
  Handle ifna(THREAD, JNIHandles::resolve(ifna_jh));
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1489
  caller->constants()->
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1490
    copy_bootstrap_arguments_at(bss_index_in_pool,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1491
                                start, end, buf, pos,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1492
                                (resolve == JNI_TRUE), ifna, CHECK);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1493
}
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1494
JVM_END
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1495
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1496
// It is called by a Cleaner object which ensures that dropped CallSites properly
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1497
// deallocate their dependency information.
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1498
JVM_ENTRY(void, MHN_clearCallSiteContext(JNIEnv* env, jobject igcls, jobject context_jh)) {
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 30615
diff changeset
  1499
  Handle context(THREAD, JNIHandles::resolve_non_null(context_jh));
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1500
  {
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1501
    // Walk all nmethods depending on this call site.
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1502
    MutexLocker mu1(Compile_lock, thread);
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1503
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1504
    int marked = 0;
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1505
    {
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 34317
diff changeset
  1506
      NoSafepointVerifier nsv;
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54389
diff changeset
  1507
      MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
34195
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1508
      DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context());
89011d12ebd3 8139595: MethodHandles::remove_dependent_nmethod is not MT safe
vlivanov
parents: 33611
diff changeset
  1509
      marked = deps.remove_all_dependents();
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1510
    }
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1511
    if (marked > 0) {
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1512
      // At least one nmethod has been marked for deoptimization
58226
408c445d04e8 8226705: [REDO] Deoptimize with handshakes
rehn
parents: 58177
diff changeset
  1513
      Deoptimization::deoptimize_all_marked();
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1514
    }
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1515
  }
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1516
}
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1517
JVM_END
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 30224
diff changeset
  1518
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1519
/**
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1520
 * 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
  1521
 * 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
  1522
 * invoked directly.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1523
 */
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1524
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
  1525
  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
  1526
  return NULL;
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1527
}
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1528
JVM_END
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1529
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1530
/**
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1531
 * 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
  1532
 * 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
  1533
 * invoked directly.
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1534
 */
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1535
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
  1536
  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
  1537
  return NULL;
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1538
}
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1539
JVM_END
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1540
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1541
/// JVM_RegisterMethodHandleMethods
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1542
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1543
#undef CS  // Solaris builds complain
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1544
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1545
#define LANG "Ljava/lang/"
9116
9bc44be338d6 6981791: remove experimental code for JSR 292
jrose
parents: 8883
diff changeset
  1546
#define JLINV "Ljava/lang/invoke/"
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1547
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1548
#define OBJ   LANG "Object;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1549
#define CLS   LANG "Class;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1550
#define STRG  LANG "String;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1551
#define CS    JLINV "CallSite;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1552
#define MT    JLINV "MethodType;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1553
#define MH    JLINV "MethodHandle;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1554
#define MEM   JLINV "MemberName;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1555
#define CTX   JLINV "MethodHandleNatives$CallSiteContext;"
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1556
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1557
#define CC (char*)  /*cast a literal from (const char*)*/
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1558
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1559
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1560
// 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
  1561
static JNINativeMethod MHN_methods[] = {
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1562
  {CC "init",                      CC "(" MEM "" OBJ ")V",                   FN_PTR(MHN_init_Mem)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1563
  {CC "expand",                    CC "(" MEM ")V",                          FN_PTR(MHN_expand_Mem)},
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 49594
diff changeset
  1564
  {CC "resolve",                   CC "(" MEM "" CLS "Z)" MEM,               FN_PTR(MHN_resolve_Mem)},
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1565
  //  static native int getNamedCon(int which, Object[] name)
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1566
  {CC "getNamedCon",               CC "(I[" OBJ ")I",                        FN_PTR(MHN_getNamedCon)},
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1567
  //  static native int getMembers(Class<?> defc, String matchName, String matchSig,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1568
  //          int matchFlags, Class<?> caller, int skip, MemberName[] results);
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1569
  {CC "getMembers",                CC "(" CLS "" STRG "" STRG "I" CLS "I[" MEM ")I", FN_PTR(MHN_getMembers)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1570
  {CC "objectFieldOffset",         CC "(" MEM ")J",                          FN_PTR(MHN_objectFieldOffset)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1571
  {CC "setCallSiteTargetNormal",   CC "(" CS "" MH ")V",                     FN_PTR(MHN_setCallSiteTargetNormal)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1572
  {CC "setCallSiteTargetVolatile", CC "(" CS "" MH ")V",                     FN_PTR(MHN_setCallSiteTargetVolatile)},
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48514
diff changeset
  1573
  {CC "copyOutBootstrapArguments", CC "(" CLS "[III[" OBJ "IZ" OBJ ")V",     FN_PTR(MHN_copyOutBootstrapArguments)},
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1574
  {CC "clearCallSiteContext",      CC "(" CTX ")V",                          FN_PTR(MHN_clearCallSiteContext)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1575
  {CC "staticFieldOffset",         CC "(" MEM ")J",                          FN_PTR(MHN_staticFieldOffset)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1576
  {CC "staticFieldBase",           CC "(" MEM ")" OBJ,                        FN_PTR(MHN_staticFieldBase)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1577
  {CC "getMemberVMInfo",           CC "(" MEM ")" OBJ,                        FN_PTR(MHN_getMemberVMInfo)}
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1578
};
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1579
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1580
static JNINativeMethod MH_methods[] = {
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1581
  // UnsupportedOperationException throwers
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1582
  {CC "invoke",                    CC "([" OBJ ")" OBJ,                       FN_PTR(MH_invoke_UOE)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 31050
diff changeset
  1583
  {CC "invokeExact",               CC "([" OBJ ")" OBJ,                       FN_PTR(MH_invokeExact_UOE)}
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1584
};
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1585
17381
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1586
/**
a53ac5bf4850 7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
twisti
parents: 17087
diff changeset
  1587
 * 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
  1588
 */
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1589
JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
10540
92d59dba2407 7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents: 10514
diff changeset
  1590
  assert(!MethodHandles::enabled(), "must not be enabled");
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1591
  assert(SystemDictionary::MethodHandle_klass() != NULL, "should be present");
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1592
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1593
  oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror();
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1594
  jclass MH_class = (jclass) JNIHandles::make_local(env, mirror);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1595
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1596
  {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1597
    ThreadToNativeFromVM ttnfv(thread);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1598
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1599
    int status = env->RegisterNatives(MHN_class, MHN_methods, sizeof(MHN_methods)/sizeof(JNINativeMethod));
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1600
    guarantee(status == JNI_OK && !env->ExceptionOccurred(),
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1601
              "register java.lang.invoke.MethodHandleNative natives");
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1602
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1603
    status = env->RegisterNatives(MH_class, MH_methods, sizeof(MH_methods)/sizeof(JNINativeMethod));
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1604
    guarantee(status == JNI_OK && !env->ExceptionOccurred(),
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1605
              "register java.lang.invoke.MethodHandle natives");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1606
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1607
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1608
  if (TraceInvokeDynamic) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13293
diff changeset
  1609
    tty->print_cr("MethodHandle support loaded (using LambdaForms)");
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1610
  }
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2570
diff changeset
  1611
36074
11263906664c 8138922: StubCodeDesc constructor publishes partially-constructed objects on StubCodeDesc::_list
vlivanov
parents: 35606
diff changeset
  1612
  MethodHandles::set_enabled(true);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1613
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents:
diff changeset
  1614
JVM_END