annotate src/share/vm/prims/methodHandles.cpp @ 10128:41ed397cc0cd

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