author | zmajo |
Wed, 06 Jul 2016 11:16:36 +0200 | |
changeset 39699 | 7a2a49fd5ee0 |
parent 39421 | a9652c919db8 |
child 41669 | 2091069b6851 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
35900 | 2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5421
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5421
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5421
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
14385 | 26 |
#include "classfile/defaultMethods.hpp" |
34666 | 27 |
#include "classfile/symbolTable.hpp" |
7397 | 28 |
#include "classfile/systemDictionary.hpp" |
29 |
#include "classfile/vmSymbols.hpp" |
|
30 |
#include "compiler/compileBroker.hpp" |
|
30764 | 31 |
#include "gc/shared/collectedHeap.inline.hpp" |
7397 | 32 |
#include "interpreter/bytecode.hpp" |
33 |
#include "interpreter/interpreterRuntime.hpp" |
|
34 |
#include "interpreter/linkResolver.hpp" |
|
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
35 |
#include "logging/log.hpp" |
7397 | 36 |
#include "memory/resourceArea.hpp" |
37 |
#include "memory/universe.inline.hpp" |
|
38 |
#include "oops/instanceKlass.hpp" |
|
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
39 |
#include "oops/method.hpp" |
7397 | 40 |
#include "oops/objArrayOop.hpp" |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28738
diff
changeset
|
41 |
#include "oops/oop.inline.hpp" |
7397 | 42 |
#include "prims/methodHandles.hpp" |
43 |
#include "prims/nativeLookup.hpp" |
|
44 |
#include "runtime/compilationPolicy.hpp" |
|
45 |
#include "runtime/fieldDescriptor.hpp" |
|
46 |
#include "runtime/frame.inline.hpp" |
|
47 |
#include "runtime/handles.inline.hpp" |
|
48 |
#include "runtime/reflection.hpp" |
|
49 |
#include "runtime/signature.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
14488
diff
changeset
|
50 |
#include "runtime/thread.inline.hpp" |
7397 | 51 |
#include "runtime/vmThread.hpp" |
1 | 52 |
|
53 |
||
54 |
//------------------------------------------------------------------------------------------------------------------------ |
|
55 |
// Implementation of CallInfo |
|
56 |
||
57 |
||
31019 | 58 |
void CallInfo::set_static(KlassHandle resolved_klass, const methodHandle& resolved_method, TRAPS) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
59 |
int vtable_index = Method::nonvirtual_vtable_index; |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
60 |
set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); |
1 | 61 |
} |
62 |
||
63 |
||
31019 | 64 |
void CallInfo::set_interface(KlassHandle resolved_klass, |
65 |
KlassHandle selected_klass, |
|
66 |
const methodHandle& resolved_method, |
|
67 |
const methodHandle& selected_method, |
|
68 |
int itable_index, TRAPS) { |
|
1 | 69 |
// This is only called for interface methods. If the resolved_method |
70 |
// comes from java/lang/Object, it can be the subject of a virtual call, so |
|
71 |
// we should pick the vtable index from the resolved method. |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
72 |
// In that case, the caller must call set_virtual instead of set_interface. |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
73 |
assert(resolved_method->method_holder()->is_interface(), ""); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
74 |
assert(itable_index == resolved_method()->itable_index(), ""); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
75 |
set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK); |
1 | 76 |
} |
77 |
||
31019 | 78 |
void CallInfo::set_virtual(KlassHandle resolved_klass, |
79 |
KlassHandle selected_klass, |
|
80 |
const methodHandle& resolved_method, |
|
81 |
const methodHandle& selected_method, |
|
82 |
int vtable_index, TRAPS) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
83 |
assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
84 |
assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), ""); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
85 |
CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
86 |
set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
87 |
assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); |
1 | 88 |
} |
89 |
||
31019 | 90 |
void CallInfo::set_handle(const methodHandle& resolved_method, |
91 |
Handle resolved_appendix, |
|
92 |
Handle resolved_method_type, TRAPS) { |
|
36819 | 93 |
set_handle(SystemDictionary::MethodHandle_klass(), resolved_method, resolved_appendix, resolved_method_type, CHECK); |
94 |
} |
|
95 |
||
96 |
void CallInfo::set_handle(KlassHandle resolved_klass, |
|
97 |
const methodHandle& resolved_method, |
|
98 |
Handle resolved_appendix, |
|
99 |
Handle resolved_method_type, TRAPS) { |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
100 |
if (resolved_method.is_null()) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
101 |
THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
102 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
103 |
assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic || |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
104 |
resolved_method->is_compiled_lambda_form(), |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
105 |
"linkMethod must return one of these"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
106 |
int vtable_index = Method::nonvirtual_vtable_index; |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
107 |
assert(!resolved_method->has_vtable_index(), ""); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
108 |
set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
109 |
_resolved_appendix = resolved_appendix; |
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
110 |
_resolved_method_type = resolved_method_type; |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5547
diff
changeset
|
111 |
} |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5547
diff
changeset
|
112 |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
113 |
void CallInfo::set_common(KlassHandle resolved_klass, |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
114 |
KlassHandle selected_klass, |
31019 | 115 |
const methodHandle& resolved_method, |
116 |
const methodHandle& selected_method, |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
117 |
CallKind kind, |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
118 |
int index, |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
119 |
TRAPS) { |
1 | 120 |
assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); |
121 |
_resolved_klass = resolved_klass; |
|
122 |
_selected_klass = selected_klass; |
|
123 |
_resolved_method = resolved_method; |
|
124 |
_selected_method = selected_method; |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
125 |
_call_kind = kind; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
126 |
_call_index = index; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
127 |
_resolved_appendix = Handle(); |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
128 |
DEBUG_ONLY(verify()); // verify before making side effects |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
129 |
|
38139
cf6f5c1b7205
8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents:
38034
diff
changeset
|
130 |
CompilationPolicy::compile_if_required(selected_method, THREAD); |
1 | 131 |
} |
132 |
||
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
133 |
// utility query for unreflecting a method |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
134 |
CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) { |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
135 |
Klass* resolved_method_holder = resolved_method->method_holder(); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
136 |
if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
137 |
resolved_klass = resolved_method_holder; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
138 |
} |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
139 |
_resolved_klass = resolved_klass; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
140 |
_selected_klass = resolved_klass; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
141 |
_resolved_method = resolved_method; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
142 |
_selected_method = resolved_method; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
143 |
// classify: |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
144 |
CallKind kind = CallInfo::unknown_kind; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
145 |
int index = resolved_method->vtable_index(); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
146 |
if (resolved_method->can_be_statically_bound()) { |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
147 |
kind = CallInfo::direct_call; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
148 |
} else if (!resolved_method_holder->is_interface()) { |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
149 |
// Could be an Object method inherited into an interface, but still a vtable call. |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
150 |
kind = CallInfo::vtable_call; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
151 |
} else if (!resolved_klass->is_interface()) { |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
152 |
// A default or miranda method. Compute the vtable index. |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
153 |
ResourceMark rm; |
35900 | 154 |
klassVtable* vt = resolved_klass->vtable(); |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
155 |
index = LinkResolver::vtable_index_of_interface_method(resolved_klass, |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
156 |
resolved_method); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
157 |
assert(index >= 0 , "we should have valid vtable index at this point"); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
158 |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
159 |
kind = CallInfo::vtable_call; |
20712
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
160 |
} else if (resolved_method->has_vtable_index()) { |
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
161 |
// Can occur if an interface redeclares a method of Object. |
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
162 |
|
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
163 |
#ifdef ASSERT |
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
164 |
// Ensure that this is really the case. |
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
165 |
KlassHandle object_klass = SystemDictionary::Object_klass(); |
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
166 |
Method * object_resolved_method = object_klass()->vtable()->method_at(index); |
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
167 |
assert(object_resolved_method->name() == resolved_method->name(), |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32189
diff
changeset
|
168 |
"Object and interface method names should match at vtable index %d, %s != %s", |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32189
diff
changeset
|
169 |
index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string()); |
20712
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
170 |
assert(object_resolved_method->signature() == resolved_method->signature(), |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32189
diff
changeset
|
171 |
"Object and interface method signatures should match at vtable index %d, %s != %s", |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32189
diff
changeset
|
172 |
index, object_resolved_method->signature()->as_C_string(), resolved_method->signature()->as_C_string()); |
20712
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
173 |
#endif // ASSERT |
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
174 |
|
a06e1f01fb6e
8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents:
20391
diff
changeset
|
175 |
kind = CallInfo::vtable_call; |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
176 |
} else { |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
177 |
// A regular interface call. |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
178 |
kind = CallInfo::itable_call; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
179 |
index = resolved_method->itable_index(); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
180 |
} |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32189
diff
changeset
|
181 |
assert(index == Method::nonvirtual_vtable_index || index >= 0, "bad index %d", index); |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
182 |
_call_kind = kind; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
183 |
_call_index = index; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
184 |
_resolved_appendix = Handle(); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
185 |
DEBUG_ONLY(verify()); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
186 |
} |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
187 |
|
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
188 |
#ifdef ASSERT |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
189 |
void CallInfo::verify() { |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
190 |
switch (call_kind()) { // the meaning and allowed value of index depends on kind |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
191 |
case CallInfo::direct_call: |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
192 |
if (_call_index == Method::nonvirtual_vtable_index) break; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
193 |
// else fall through to check vtable index: |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
194 |
case CallInfo::vtable_call: |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
195 |
assert(resolved_klass()->verify_vtable_index(_call_index), ""); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
196 |
break; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
197 |
case CallInfo::itable_call: |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
198 |
assert(resolved_method()->method_holder()->verify_itable_index(_call_index), ""); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
199 |
break; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
200 |
case CallInfo::unknown_kind: |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
201 |
assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set"); |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
202 |
break; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
203 |
default: |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32189
diff
changeset
|
204 |
fatal("Unexpected call kind %d", call_kind()); |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
205 |
} |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
206 |
} |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
207 |
#endif //ASSERT |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
208 |
|
31019 | 209 |
#ifndef PRODUCT |
210 |
void CallInfo::print() { |
|
211 |
ResourceMark rm; |
|
212 |
const char* kindstr = "unknown"; |
|
213 |
switch (_call_kind) { |
|
214 |
case direct_call: kindstr = "direct"; break; |
|
215 |
case vtable_call: kindstr = "vtable"; break; |
|
216 |
case itable_call: kindstr = "itable"; break; |
|
217 |
} |
|
218 |
tty->print_cr("Call %s@%d %s", kindstr, _call_index, |
|
219 |
_resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string()); |
|
220 |
} |
|
221 |
#endif |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
222 |
|
31019 | 223 |
//------------------------------------------------------------------------------------------------------------------------ |
224 |
// Implementation of LinkInfo |
|
1 | 225 |
|
39421
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
226 |
LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, methodHandle current_method, TRAPS) { |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
227 |
// resolve klass |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
228 |
Klass* result = pool->klass_ref_at(index, CHECK); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
229 |
_resolved_klass = KlassHandle(THREAD, result); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
230 |
|
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
231 |
// Get name, signature, and static klass |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
232 |
_name = pool->name_ref_at(index); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
233 |
_signature = pool->signature_ref_at(index); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
234 |
_tag = pool->tag_ref_at(index); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
235 |
_current_klass = KlassHandle(THREAD, pool->pool_holder()); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
236 |
_current_method = current_method; |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
237 |
|
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
238 |
// Coming from the constant pool always checks access |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
239 |
_check_access = true; |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
240 |
} |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
241 |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
242 |
LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, TRAPS) { |
31019 | 243 |
// resolve klass |
244 |
Klass* result = pool->klass_ref_at(index, CHECK); |
|
245 |
_resolved_klass = KlassHandle(THREAD, result); |
|
246 |
||
247 |
// Get name, signature, and static klass |
|
248 |
_name = pool->name_ref_at(index); |
|
249 |
_signature = pool->signature_ref_at(index); |
|
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
250 |
_tag = pool->tag_ref_at(index); |
31019 | 251 |
_current_klass = KlassHandle(THREAD, pool->pool_holder()); |
39421
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
252 |
_current_method = methodHandle(); |
31019 | 253 |
|
254 |
// Coming from the constant pool always checks access |
|
255 |
_check_access = true; |
|
256 |
} |
|
257 |
||
258 |
char* LinkInfo::method_string() const { |
|
259 |
return Method::name_and_sig_as_C_string(_resolved_klass(), _name, _signature); |
|
260 |
} |
|
261 |
||
262 |
#ifndef PRODUCT |
|
263 |
void LinkInfo::print() { |
|
264 |
ResourceMark rm; |
|
265 |
tty->print_cr("Link resolved_klass=%s name=%s signature=%s current_klass=%s check_access=%s", |
|
266 |
_resolved_klass->name()->as_C_string(), |
|
267 |
_name->as_C_string(), |
|
268 |
_signature->as_C_string(), |
|
269 |
_current_klass.is_null() ? "(none)" : _current_klass->name()->as_C_string(), |
|
270 |
_check_access ? "true" : "false"); |
|
271 |
} |
|
272 |
#endif // PRODUCT |
|
1 | 273 |
//------------------------------------------------------------------------------------------------------------------------ |
274 |
// Klass resolution |
|
275 |
||
276 |
void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { |
|
36508 | 277 |
Reflection::VerifyClassAccessResults vca_result = |
278 |
Reflection::verify_class_access(ref_klass(), sel_klass(), true); |
|
279 |
if (vca_result != Reflection::ACCESS_OK) { |
|
1 | 280 |
ResourceMark rm(THREAD); |
36508 | 281 |
char* msg = Reflection::verify_class_access_msg(ref_klass(), sel_klass(), vca_result); |
282 |
if (msg == NULL) { |
|
283 |
Exceptions::fthrow( |
|
284 |
THREAD_AND_LOCATION, |
|
285 |
vmSymbols::java_lang_IllegalAccessError(), |
|
286 |
"failed to access class %s from class %s", |
|
287 |
sel_klass->external_name(), |
|
288 |
ref_klass->external_name()); |
|
289 |
} else { |
|
290 |
// Use module specific message returned by verify_class_access_msg(). |
|
291 |
Exceptions::fthrow( |
|
292 |
THREAD_AND_LOCATION, |
|
293 |
vmSymbols::java_lang_IllegalAccessError(), |
|
294 |
"%s", msg); |
|
295 |
} |
|
1 | 296 |
} |
297 |
} |
|
298 |
||
299 |
//------------------------------------------------------------------------------------------------------------------------ |
|
300 |
// Method resolution |
|
301 |
// |
|
302 |
// According to JVM spec. $5.4.3c & $5.4.3d |
|
303 |
||
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
304 |
// Look up method in klasses, including static methods |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
305 |
// Then look up local default methods |
31019 | 306 |
methodHandle LinkResolver::lookup_method_in_klasses(const LinkInfo& link_info, |
307 |
bool checkpolymorphism, |
|
308 |
bool in_imethod_resolve, TRAPS) { |
|
309 |
KlassHandle klass = link_info.resolved_klass(); |
|
310 |
Symbol* name = link_info.name(); |
|
311 |
Symbol* signature = link_info.signature(); |
|
312 |
||
23999
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22739
diff
changeset
|
313 |
// Ignore overpasses so statics can be found during resolution |
31019 | 314 |
Method* result = klass->uncached_lookup_method(name, signature, Klass::skip_overpass); |
22219
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
315 |
|
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33602
diff
changeset
|
316 |
if (klass->is_array_klass()) { |
27020 | 317 |
// Only consider klass and super klass for arrays |
31019 | 318 |
return methodHandle(THREAD, result); |
27020 | 319 |
} |
320 |
||
33602 | 321 |
InstanceKlass* ik = InstanceKlass::cast(klass()); |
322 |
||
22219
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
323 |
// JDK 8, JVMS 5.4.3.4: Interface method resolution should |
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
324 |
// ignore static and non-public methods of java.lang.Object, |
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
325 |
// like clone, finalize, registerNatives. |
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
326 |
if (in_imethod_resolve && |
31019 | 327 |
result != NULL && |
33602 | 328 |
ik->is_interface() && |
31019 | 329 |
(result->is_static() || !result->is_public()) && |
330 |
result->method_holder() == SystemDictionary::Object_klass()) { |
|
331 |
result = NULL; |
|
22219
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
332 |
} |
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
333 |
|
23999
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22739
diff
changeset
|
334 |
// Before considering default methods, check for an overpass in the |
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22739
diff
changeset
|
335 |
// current class if a method has not been found. |
31019 | 336 |
if (result == NULL) { |
33602 | 337 |
result = ik->find_method(name, signature); |
23999
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22739
diff
changeset
|
338 |
} |
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22739
diff
changeset
|
339 |
|
31019 | 340 |
if (result == NULL) { |
33602 | 341 |
Array<Method*>* default_methods = ik->default_methods(); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
342 |
if (default_methods != NULL) { |
31019 | 343 |
result = InstanceKlass::find_method(default_methods, name, signature); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
344 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
345 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
346 |
|
31019 | 347 |
if (checkpolymorphism && result != NULL) { |
348 |
vmIntrinsics::ID iid = result->intrinsic_id(); |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
349 |
if (MethodHandles::is_signature_polymorphic(iid)) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
350 |
// Do not link directly to these. The VM must produce a synthetic one using lookup_polymorphic_method. |
31019 | 351 |
return NULL; |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4571
diff
changeset
|
352 |
} |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4571
diff
changeset
|
353 |
} |
31019 | 354 |
return methodHandle(THREAD, result); |
1 | 355 |
} |
356 |
||
357 |
// returns first instance method |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
358 |
// Looks up method in classes, then looks up local default methods |
31019 | 359 |
methodHandle LinkResolver::lookup_instance_method_in_klasses(KlassHandle klass, |
360 |
Symbol* name, |
|
361 |
Symbol* signature, TRAPS) { |
|
362 |
Method* result = klass->uncached_lookup_method(name, signature, Klass::find_overpass); |
|
363 |
||
364 |
while (result != NULL && result->is_static() && result->method_holder()->super() != NULL) { |
|
365 |
Klass* super_klass = result->method_holder()->super(); |
|
366 |
result = super_klass->uncached_lookup_method(name, signature, Klass::find_overpass); |
|
1 | 367 |
} |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
368 |
|
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33602
diff
changeset
|
369 |
if (klass->is_array_klass()) { |
27020 | 370 |
// Only consider klass and super klass for arrays |
31019 | 371 |
return methodHandle(THREAD, result); |
27020 | 372 |
} |
373 |
||
31019 | 374 |
if (result == NULL) { |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
375 |
Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods(); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
376 |
if (default_methods != NULL) { |
31019 | 377 |
result = InstanceKlass::find_method(default_methods, name, signature); |
378 |
assert(result == NULL || !result->is_static(), "static defaults not allowed"); |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
379 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
380 |
} |
31019 | 381 |
return methodHandle(THREAD, result); |
1 | 382 |
} |
383 |
||
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
384 |
int LinkResolver::vtable_index_of_interface_method(KlassHandle klass, |
31019 | 385 |
const methodHandle& resolved_method) { |
1 | 386 |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
387 |
int vtable_index = Method::invalid_vtable_index; |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
388 |
Symbol* name = resolved_method->name(); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
389 |
Symbol* signature = resolved_method->signature(); |
33602 | 390 |
InstanceKlass* ik = InstanceKlass::cast(klass()); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
391 |
|
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
392 |
// First check in default method array |
33602 | 393 |
if (!resolved_method->is_abstract() && ik->default_methods() != NULL) { |
394 |
int index = InstanceKlass::find_method_index(ik->default_methods(), |
|
32189
5264b560ab1b
8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents:
31019
diff
changeset
|
395 |
name, signature, Klass::find_overpass, |
5264b560ab1b
8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents:
31019
diff
changeset
|
396 |
Klass::find_static, Klass::find_private); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
397 |
if (index >= 0 ) { |
33602 | 398 |
vtable_index = ik->default_vtable_indices()->at(index); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
399 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
400 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
401 |
if (vtable_index == Method::invalid_vtable_index) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
402 |
// get vtable_index for miranda methods |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
403 |
ResourceMark rm; |
33602 | 404 |
klassVtable *vt = ik->vtable(); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
405 |
vtable_index = vt->index_of_miranda(name, signature); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
406 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
407 |
return vtable_index; |
1 | 408 |
} |
409 |
||
31019 | 410 |
methodHandle LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info, TRAPS) { |
411 |
InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass()()); |
|
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
412 |
|
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
413 |
// Specify 'true' in order to skip default methods when searching the |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
414 |
// interfaces. Function lookup_method_in_klasses() already looked for |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
415 |
// the method in the default methods table. |
31019 | 416 |
return methodHandle(THREAD, |
417 |
ik->lookup_method_in_all_interfaces(cp_info.name(), cp_info.signature(), |
|
418 |
Klass::skip_defaults)); |
|
1 | 419 |
} |
420 |
||
31019 | 421 |
methodHandle LinkResolver::lookup_polymorphic_method( |
422 |
const LinkInfo& link_info, |
|
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
423 |
Handle *appendix_result_or_null, |
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
424 |
Handle *method_type_result, |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
425 |
TRAPS) { |
31019 | 426 |
KlassHandle klass = link_info.resolved_klass(); |
427 |
Symbol* name = link_info.name(); |
|
428 |
Symbol* full_signature = link_info.signature(); |
|
429 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
430 |
vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
431 |
if (TraceMethodHandles) { |
16691 | 432 |
ResourceMark rm(THREAD); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
433 |
tty->print_cr("lookup_polymorphic_method iid=%s %s.%s%s", |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
434 |
vmIntrinsics::name_at(iid), klass->external_name(), |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
435 |
name->as_C_string(), full_signature->as_C_string()); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
436 |
} |
36819 | 437 |
if ((klass() == SystemDictionary::MethodHandle_klass() || |
438 |
klass() == SystemDictionary::VarHandle_klass()) && |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
439 |
iid != vmIntrinsics::_none) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
440 |
if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
441 |
// Most of these do not need an up-call to Java to resolve, so can be done anywhere. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
442 |
// Do not erase last argument type (MemberName) if it is a static linkTo method. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
443 |
bool keep_last_arg = MethodHandles::is_signature_polymorphic_static(iid); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
444 |
TempNewSymbol basic_signature = |
31019 | 445 |
MethodHandles::lookup_basic_type_signature(full_signature, keep_last_arg, CHECK_NULL); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
446 |
if (TraceMethodHandles) { |
16691 | 447 |
ResourceMark rm(THREAD); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
448 |
tty->print_cr("lookup_polymorphic_method %s %s => basic %s", |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
449 |
name->as_C_string(), |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
450 |
full_signature->as_C_string(), |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
451 |
basic_signature->as_C_string()); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
452 |
} |
31019 | 453 |
methodHandle result = SystemDictionary::find_method_handle_intrinsic(iid, |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
454 |
basic_signature, |
31019 | 455 |
CHECK_NULL); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
456 |
if (result.not_null()) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
457 |
assert(result->is_method_handle_intrinsic(), "MH.invokeBasic or MH.linkTo* intrinsic"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
458 |
assert(result->intrinsic_id() != vmIntrinsics::_invokeGeneric, "wrong place to find this"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
459 |
assert(basic_signature == result->signature(), "predict the result signature"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
460 |
if (TraceMethodHandles) { |
35543
0961315f4016
8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents:
35135
diff
changeset
|
461 |
ttyLocker ttyl; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
462 |
tty->print("lookup_polymorphic_method => intrinsic "); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
463 |
result->print_on(tty); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
464 |
} |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5547
diff
changeset
|
465 |
} |
31019 | 466 |
return result; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
467 |
} else if (iid == vmIntrinsics::_invokeGeneric |
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
32189
diff
changeset
|
468 |
&& THREAD->can_call_java() |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
469 |
&& appendix_result_or_null != NULL) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
470 |
// This is a method with type-checking semantics. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
471 |
// We will ask Java code to spin an adapter method for it. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
472 |
if (!MethodHandles::enabled()) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
473 |
// Make sure the Java part of the runtime has been booted up. |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
474 |
Klass* natives = SystemDictionary::MethodHandleNatives_klass(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
475 |
if (natives == NULL || InstanceKlass::cast(natives)->is_not_initialized()) { |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
476 |
SystemDictionary::resolve_or_fail(vmSymbols::java_lang_invoke_MethodHandleNatives(), |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
477 |
Handle(), |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
478 |
Handle(), |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
479 |
true, |
31019 | 480 |
CHECK_NULL); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
481 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
482 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
483 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
484 |
Handle appendix; |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
485 |
Handle method_type; |
31019 | 486 |
methodHandle result = SystemDictionary::find_method_handle_invoker( |
36819 | 487 |
klass, |
31019 | 488 |
name, |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
489 |
full_signature, |
31019 | 490 |
link_info.current_klass(), |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
491 |
&appendix, |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
492 |
&method_type, |
31019 | 493 |
CHECK_NULL); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
494 |
if (TraceMethodHandles) { |
35543
0961315f4016
8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents:
35135
diff
changeset
|
495 |
ttyLocker ttyl; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
496 |
tty->print("lookup_polymorphic_method => (via Java) "); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
497 |
result->print_on(tty); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
498 |
tty->print(" lookup_polymorphic_method => appendix = "); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
499 |
if (appendix.is_null()) tty->print_cr("(none)"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
500 |
else appendix->print_on(tty); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
501 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
502 |
if (result.not_null()) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
503 |
#ifdef ASSERT |
16691 | 504 |
ResourceMark rm(THREAD); |
505 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
506 |
TempNewSymbol basic_signature = |
31019 | 507 |
MethodHandles::lookup_basic_type_signature(full_signature, CHECK_NULL); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
508 |
int actual_size_of_params = result->size_of_parameters(); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
509 |
int expected_size_of_params = ArgumentSizeComputer(basic_signature).size(); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
510 |
// +1 for MethodHandle.this, +1 for trailing MethodType |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
511 |
if (!MethodHandles::is_signature_polymorphic_static(iid)) expected_size_of_params += 1; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
512 |
if (appendix.not_null()) expected_size_of_params += 1; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
513 |
if (actual_size_of_params != expected_size_of_params) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
514 |
tty->print_cr("*** basic_signature=%s", basic_signature->as_C_string()); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
515 |
tty->print_cr("*** result for %s: ", vmIntrinsics::name_at(iid)); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
516 |
result->print(); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
517 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
518 |
assert(actual_size_of_params == expected_size_of_params, |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32189
diff
changeset
|
519 |
"%d != %d", actual_size_of_params, expected_size_of_params); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
520 |
#endif //ASSERT |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
521 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
522 |
assert(appendix_result_or_null != NULL, ""); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
523 |
(*appendix_result_or_null) = appendix; |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
524 |
(*method_type_result) = method_type; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
525 |
} |
31019 | 526 |
return result; |
2534 | 527 |
} |
528 |
} |
|
31019 | 529 |
return NULL; |
2534 | 530 |
} |
531 |
||
1 | 532 |
void LinkResolver::check_method_accessability(KlassHandle ref_klass, |
533 |
KlassHandle resolved_klass, |
|
534 |
KlassHandle sel_klass, |
|
31019 | 535 |
const methodHandle& sel_method, |
1 | 536 |
TRAPS) { |
537 |
||
538 |
AccessFlags flags = sel_method->access_flags(); |
|
539 |
||
22219
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
540 |
// Special case: arrays always override "clone". JVMS 2.15. |
1 | 541 |
// If the resolved klass is an array class, and the declaring class |
542 |
// is java.lang.Object and the method is "clone", set the flags |
|
543 |
// to public. |
|
544 |
// |
|
22219
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
545 |
// We'll check for the method name first, as that's most likely |
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
546 |
// to be false (so we'll short-circuit out of these tests). |
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
547 |
if (sel_method->name() == vmSymbols::clone_name() && |
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
548 |
sel_klass() == SystemDictionary::Object_klass() && |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33602
diff
changeset
|
549 |
resolved_klass->is_array_klass()) { |
1 | 550 |
// We need to change "protected" to "public". |
22219
4bfd5df70189
8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents:
22218
diff
changeset
|
551 |
assert(flags.is_protected(), "clone not protected?"); |
1 | 552 |
jint new_flags = flags.as_int(); |
553 |
new_flags = new_flags & (~JVM_ACC_PROTECTED); |
|
554 |
new_flags = new_flags | JVM_ACC_PUBLIC; |
|
555 |
flags.set_flags(new_flags); |
|
556 |
} |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
557 |
// assert(extra_arg_result_or_null != NULL, "must be able to return extra argument"); |
1 | 558 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
559 |
if (!Reflection::verify_field_access(ref_klass(), |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
560 |
resolved_klass(), |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
561 |
sel_klass(), |
1 | 562 |
flags, |
563 |
true)) { |
|
564 |
ResourceMark rm(THREAD); |
|
565 |
Exceptions::fthrow( |
|
566 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
567 |
vmSymbols::java_lang_IllegalAccessError(), |
1 | 568 |
"tried to access method %s.%s%s from class %s", |
569 |
sel_klass->external_name(), |
|
570 |
sel_method->name()->as_C_string(), |
|
571 |
sel_method->signature()->as_C_string(), |
|
572 |
ref_klass->external_name() |
|
573 |
); |
|
574 |
return; |
|
575 |
} |
|
576 |
} |
|
577 |
||
31019 | 578 |
methodHandle LinkResolver::resolve_method_statically(Bytecodes::Code code, |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
579 |
const constantPoolHandle& pool, int index, TRAPS) { |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
580 |
// This method is used only |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
581 |
// (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
582 |
// and |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
583 |
// (2) in Bytecode_invoke::static_target |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
584 |
// It appears to fail when applied to an invokeinterface call site. |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
585 |
// FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. |
1 | 586 |
// resolve klass |
31019 | 587 |
KlassHandle resolved_klass; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
588 |
if (code == Bytecodes::_invokedynamic) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
589 |
resolved_klass = SystemDictionary::MethodHandle_klass(); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
590 |
Symbol* method_name = vmSymbols::invoke_name(); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
591 |
Symbol* method_signature = pool->signature_ref_at(index); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
592 |
KlassHandle current_klass(THREAD, pool->pool_holder()); |
31019 | 593 |
LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass); |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
594 |
return resolve_method(link_info, code, THREAD); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
595 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
596 |
|
39421
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
597 |
LinkInfo link_info(pool, index, methodHandle(), CHECK_NULL); |
31019 | 598 |
resolved_klass = link_info.resolved_klass(); |
1 | 599 |
|
10008
d84de97ad847
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
9967
diff
changeset
|
600 |
if (pool->has_preresolution() |
d84de97ad847
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
9967
diff
changeset
|
601 |
|| (resolved_klass() == SystemDictionary::MethodHandle_klass() && |
31019 | 602 |
MethodHandles::is_signature_polymorphic_name(resolved_klass(), link_info.name()))) { |
603 |
Method* result = ConstantPool::method_at_if_loaded(pool, index); |
|
604 |
if (result != NULL) { |
|
605 |
return methodHandle(THREAD, result); |
|
10008
d84de97ad847
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
9967
diff
changeset
|
606 |
} |
d84de97ad847
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
9967
diff
changeset
|
607 |
} |
d84de97ad847
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
9967
diff
changeset
|
608 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
609 |
if (code == Bytecodes::_invokeinterface) { |
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
610 |
return resolve_interface_method(link_info, code, THREAD); |
20685
2feadfa49bb7
8026299: invokespecial gets ICCE when it should get AME.
acorn
parents:
20391
diff
changeset
|
611 |
} else if (code == Bytecodes::_invokevirtual) { |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
612 |
return resolve_method(link_info, code, THREAD); |
21912 | 613 |
} else if (!resolved_klass->is_interface()) { |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
614 |
return resolve_method(link_info, code, THREAD); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
615 |
} else { |
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
616 |
return resolve_interface_method(link_info, code, THREAD); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
617 |
} |
1 | 618 |
} |
619 |
||
31019 | 620 |
// Check and print a loader constraint violation message for method or interface method |
621 |
void LinkResolver::check_method_loader_constraints(const LinkInfo& link_info, |
|
622 |
const methodHandle& resolved_method, |
|
623 |
const char* method_type, TRAPS) { |
|
624 |
Handle current_loader(THREAD, link_info.current_klass()->class_loader()); |
|
625 |
Handle resolved_loader(THREAD, resolved_method->method_holder()->class_loader()); |
|
626 |
||
627 |
ResourceMark rm(THREAD); |
|
628 |
Symbol* failed_type_symbol = |
|
629 |
SystemDictionary::check_signature_loaders(link_info.signature(), current_loader, |
|
630 |
resolved_loader, true, CHECK); |
|
631 |
if (failed_type_symbol != NULL) { |
|
632 |
const char* msg = "loader constraint violation: when resolving %s" |
|
633 |
" \"%s\" the class loader (instance of %s) of the current class, %s," |
|
634 |
" and the class loader (instance of %s) for the method's defining class, %s, have" |
|
635 |
" different Class objects for the type %s used in the signature"; |
|
636 |
char* sig = link_info.method_string(); |
|
637 |
const char* loader1_name = SystemDictionary::loader_name(current_loader()); |
|
638 |
char* current = link_info.current_klass()->name()->as_C_string(); |
|
639 |
const char* loader2_name = SystemDictionary::loader_name(resolved_loader()); |
|
640 |
char* target = resolved_method->method_holder()->name()->as_C_string(); |
|
641 |
char* failed_type_name = failed_type_symbol->as_C_string(); |
|
642 |
size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1_name) + |
|
643 |
strlen(current) + strlen(loader2_name) + strlen(target) + |
|
644 |
strlen(failed_type_name) + strlen(method_type) + 1; |
|
645 |
char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); |
|
646 |
jio_snprintf(buf, buflen, msg, method_type, sig, loader1_name, current, loader2_name, |
|
647 |
target, failed_type_name); |
|
648 |
THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
|
649 |
} |
|
650 |
} |
|
651 |
||
652 |
void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig, |
|
653 |
KlassHandle current_klass, |
|
654 |
KlassHandle sel_klass, TRAPS) { |
|
655 |
Handle ref_loader(THREAD, current_klass->class_loader()); |
|
656 |
Handle sel_loader(THREAD, sel_klass->class_loader()); |
|
657 |
||
658 |
ResourceMark rm(THREAD); // needed for check_signature_loaders |
|
659 |
Symbol* failed_type_symbol = |
|
660 |
SystemDictionary::check_signature_loaders(sig, |
|
661 |
ref_loader, sel_loader, |
|
662 |
false, |
|
663 |
CHECK); |
|
664 |
if (failed_type_symbol != NULL) { |
|
665 |
const char* msg = "loader constraint violation: when resolving field" |
|
666 |
" \"%s\" the class loader (instance of %s) of the referring class, " |
|
667 |
"%s, and the class loader (instance of %s) for the field's resolved " |
|
668 |
"type, %s, have different Class objects for that type"; |
|
669 |
char* field_name = field->as_C_string(); |
|
670 |
const char* loader1_name = SystemDictionary::loader_name(ref_loader()); |
|
671 |
char* sel = sel_klass->name()->as_C_string(); |
|
672 |
const char* loader2_name = SystemDictionary::loader_name(sel_loader()); |
|
673 |
char* failed_type_name = failed_type_symbol->as_C_string(); |
|
674 |
size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1_name) + |
|
675 |
strlen(sel) + strlen(loader2_name) + strlen(failed_type_name) + 1; |
|
676 |
char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); |
|
677 |
jio_snprintf(buf, buflen, msg, field_name, loader1_name, sel, loader2_name, |
|
678 |
failed_type_name); |
|
679 |
THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
|
680 |
} |
|
681 |
} |
|
682 |
||
683 |
methodHandle LinkResolver::resolve_method(const LinkInfo& link_info, |
|
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
684 |
Bytecodes::Code code, TRAPS) { |
1 | 685 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
686 |
Handle nested_exception; |
31019 | 687 |
KlassHandle resolved_klass = link_info.resolved_klass(); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
688 |
|
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
689 |
// 1. For invokevirtual, cannot call an interface method |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
690 |
if (code == Bytecodes::_invokevirtual && resolved_klass->is_interface()) { |
20685
2feadfa49bb7
8026299: invokespecial gets ICCE when it should get AME.
acorn
parents:
20391
diff
changeset
|
691 |
ResourceMark rm(THREAD); |
2feadfa49bb7
8026299: invokespecial gets ICCE when it should get AME.
acorn
parents:
20391
diff
changeset
|
692 |
char buf[200]; |
2feadfa49bb7
8026299: invokespecial gets ICCE when it should get AME.
acorn
parents:
20391
diff
changeset
|
693 |
jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", |
2feadfa49bb7
8026299: invokespecial gets ICCE when it should get AME.
acorn
parents:
20391
diff
changeset
|
694 |
resolved_klass()->external_name()); |
31019 | 695 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
20685
2feadfa49bb7
8026299: invokespecial gets ICCE when it should get AME.
acorn
parents:
20391
diff
changeset
|
696 |
} |
2feadfa49bb7
8026299: invokespecial gets ICCE when it should get AME.
acorn
parents:
20391
diff
changeset
|
697 |
|
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
698 |
// 2. check constant pool tag for called method - must be JVM_CONSTANT_Methodref |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
699 |
if (!link_info.tag().is_invalid() && !link_info.tag().is_method()) { |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
700 |
ResourceMark rm(THREAD); |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
701 |
char buf[200]; |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
702 |
jio_snprintf(buf, sizeof(buf), "Method %s must be Methodref constant", link_info.method_string()); |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
703 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
704 |
} |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
705 |
|
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
706 |
|
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
707 |
// 3. lookup method in resolved klass and its super klasses |
31019 | 708 |
methodHandle resolved_method = lookup_method_in_klasses(link_info, true, false, CHECK_NULL); |
1 | 709 |
|
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
710 |
// 4. lookup method in all the interfaces implemented by the resolved klass |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33602
diff
changeset
|
711 |
if (resolved_method.is_null() && !resolved_klass->is_array_klass()) { // not found in the class hierarchy |
31019 | 712 |
resolved_method = lookup_method_in_interfaces(link_info, CHECK_NULL); |
1 | 713 |
|
714 |
if (resolved_method.is_null()) { |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
715 |
// JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc |
31019 | 716 |
resolved_method = lookup_polymorphic_method(link_info, (Handle*)NULL, (Handle*)NULL, THREAD); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
717 |
if (HAS_PENDING_EXCEPTION) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
718 |
nested_exception = Handle(THREAD, PENDING_EXCEPTION); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
719 |
CLEAR_PENDING_EXCEPTION; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
720 |
} |
2534 | 721 |
} |
27020 | 722 |
} |
2534 | 723 |
|
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
724 |
// 5. method lookup failed |
27020 | 725 |
if (resolved_method.is_null()) { |
726 |
ResourceMark rm(THREAD); |
|
31019 | 727 |
THROW_MSG_CAUSE_(vmSymbols::java_lang_NoSuchMethodError(), |
27020 | 728 |
Method::name_and_sig_as_C_string(resolved_klass(), |
31019 | 729 |
link_info.name(), |
730 |
link_info.signature()), |
|
731 |
nested_exception, NULL); |
|
1 | 732 |
} |
733 |
||
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
734 |
// 6. access checks, access checking may be turned off when calling from within the VM. |
31019 | 735 |
KlassHandle current_klass = link_info.current_klass(); |
736 |
if (link_info.check_access()) { |
|
1 | 737 |
assert(current_klass.not_null() , "current_klass should not be null"); |
738 |
||
739 |
// check if method can be accessed by the referring class |
|
740 |
check_method_accessability(current_klass, |
|
741 |
resolved_klass, |
|
742 |
KlassHandle(THREAD, resolved_method->method_holder()), |
|
743 |
resolved_method, |
|
31019 | 744 |
CHECK_NULL); |
1 | 745 |
|
746 |
// check loader constraints |
|
31019 | 747 |
check_method_loader_constraints(link_info, resolved_method, "method", CHECK_NULL); |
1 | 748 |
} |
31019 | 749 |
|
750 |
return resolved_method; |
|
1 | 751 |
} |
752 |
||
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
753 |
static void trace_method_resolution(const char* prefix, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
754 |
KlassHandle klass, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
755 |
KlassHandle resolved_klass, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
756 |
const methodHandle& method, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
757 |
bool logitables, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
758 |
int index = -1) { |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
759 |
#ifndef PRODUCT |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
760 |
ResourceMark rm; |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
761 |
outputStream* st; |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
762 |
if (logitables) { |
37242 | 763 |
st = Log(itables)::trace_stream(); |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
764 |
} else { |
37242 | 765 |
st = Log(vtables)::trace_stream(); |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
766 |
} |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
767 |
st->print("%s%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ", |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
768 |
prefix, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
769 |
(klass.is_null() ? "<NULL>" : klass->internal_name()), |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
770 |
(resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
771 |
Method::name_and_sig_as_C_string(resolved_klass(), |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
772 |
method->name(), |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
773 |
method->signature()), |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
774 |
method->method_holder()->internal_name()); |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
775 |
method->print_linkage_flags(st); |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
776 |
if (index != -1) { |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
777 |
st->print("vtable_index:%d", index); |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
778 |
} |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
779 |
st->cr(); |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
780 |
#endif // PRODUCT |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
781 |
} |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
782 |
|
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
783 |
// Do linktime resolution of a method in the interface within the context of the specied bytecode. |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
784 |
methodHandle LinkResolver::resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS) { |
31019 | 785 |
|
786 |
KlassHandle resolved_klass = link_info.resolved_klass(); |
|
1 | 787 |
|
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
788 |
// check if klass is interface |
1 | 789 |
if (!resolved_klass->is_interface()) { |
9425
6da66b869573
6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents:
9116
diff
changeset
|
790 |
ResourceMark rm(THREAD); |
1 | 791 |
char buf[200]; |
14488 | 792 |
jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass()->external_name()); |
31019 | 793 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
1 | 794 |
} |
795 |
||
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
796 |
// check constant pool tag for called method - must be JVM_CONSTANT_InterfaceMethodref |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
797 |
if (!link_info.tag().is_invalid() && !link_info.tag().is_interface_method()) { |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
798 |
ResourceMark rm(THREAD); |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
799 |
char buf[200]; |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
800 |
jio_snprintf(buf, sizeof(buf), "Method %s must be InterfaceMethodref constant", link_info.method_string()); |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
801 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
802 |
} |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
803 |
|
1 | 804 |
// lookup method in this interface or its super, java.lang.Object |
21912 | 805 |
// JDK8: also look for static methods |
31019 | 806 |
methodHandle resolved_method = lookup_method_in_klasses(link_info, false, true, CHECK_NULL); |
1 | 807 |
|
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33602
diff
changeset
|
808 |
if (resolved_method.is_null() && !resolved_klass->is_array_klass()) { |
1 | 809 |
// lookup method in all the super-interfaces |
31019 | 810 |
resolved_method = lookup_method_in_interfaces(link_info, CHECK_NULL); |
27020 | 811 |
} |
812 |
||
813 |
if (resolved_method.is_null()) { |
|
814 |
// no method found |
|
815 |
ResourceMark rm(THREAD); |
|
31019 | 816 |
THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), |
817 |
Method::name_and_sig_as_C_string(resolved_klass(), |
|
818 |
link_info.name(), |
|
819 |
link_info.signature())); |
|
1 | 820 |
} |
821 |
||
31019 | 822 |
if (link_info.check_access()) { |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
823 |
// JDK8 adds non-public interface methods, and accessability check requirement |
31019 | 824 |
KlassHandle current_klass = link_info.current_klass(); |
825 |
||
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
826 |
assert(current_klass.not_null() , "current_klass should not be null"); |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
827 |
|
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
828 |
// check if method can be accessed by the referring class |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
829 |
check_method_accessability(current_klass, |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
830 |
resolved_klass, |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
831 |
KlassHandle(THREAD, resolved_method->method_holder()), |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
832 |
resolved_method, |
31019 | 833 |
CHECK_NULL); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
834 |
|
31019 | 835 |
check_method_loader_constraints(link_info, resolved_method, "interface method", CHECK_NULL); |
1 | 836 |
} |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
837 |
|
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
838 |
if (code != Bytecodes::_invokestatic && resolved_method->is_static()) { |
22521
5387725ea99d
8031045: Access checks should precede additional per-instruction checks
hseigel
parents:
22232
diff
changeset
|
839 |
ResourceMark rm(THREAD); |
5387725ea99d
8031045: Access checks should precede additional per-instruction checks
hseigel
parents:
22232
diff
changeset
|
840 |
char buf[200]; |
5387725ea99d
8031045: Access checks should precede additional per-instruction checks
hseigel
parents:
22232
diff
changeset
|
841 |
jio_snprintf(buf, sizeof(buf), "Expected instance not static method %s", |
5387725ea99d
8031045: Access checks should precede additional per-instruction checks
hseigel
parents:
22232
diff
changeset
|
842 |
Method::name_and_sig_as_C_string(resolved_klass(), |
5387725ea99d
8031045: Access checks should precede additional per-instruction checks
hseigel
parents:
22232
diff
changeset
|
843 |
resolved_method->name(), resolved_method->signature())); |
31019 | 844 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
22521
5387725ea99d
8031045: Access checks should precede additional per-instruction checks
hseigel
parents:
22232
diff
changeset
|
845 |
} |
5387725ea99d
8031045: Access checks should precede additional per-instruction checks
hseigel
parents:
22232
diff
changeset
|
846 |
|
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
847 |
if (code == Bytecodes::_invokeinterface && resolved_method->is_private()) { |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
848 |
ResourceMark rm(THREAD); |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
849 |
char buf[200]; |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
850 |
|
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
851 |
KlassHandle current_klass = link_info.current_klass(); |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
852 |
jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s, caller-class:%s", |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
853 |
Method::name_and_sig_as_C_string(resolved_klass(), |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
854 |
resolved_method->name(), |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
855 |
resolved_method->signature()), |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
856 |
(current_klass.is_null() ? "<NULL>" : current_klass->internal_name())); |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
857 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
858 |
} |
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
859 |
|
35901
f5028c67e7cb
8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents:
35900
diff
changeset
|
860 |
if (log_develop_is_enabled(Trace, itables)) { |
31019 | 861 |
trace_method_resolution("invokeinterface resolved method: caller-class", |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
862 |
link_info.current_klass(), resolved_klass, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
863 |
resolved_method, true); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
864 |
} |
31019 | 865 |
|
866 |
return resolved_method; |
|
1 | 867 |
} |
868 |
||
869 |
//------------------------------------------------------------------------------------------------------------------------ |
|
870 |
// Field resolution |
|
871 |
||
872 |
void LinkResolver::check_field_accessability(KlassHandle ref_klass, |
|
873 |
KlassHandle resolved_klass, |
|
874 |
KlassHandle sel_klass, |
|
31019 | 875 |
const fieldDescriptor& fd, |
1 | 876 |
TRAPS) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
877 |
if (!Reflection::verify_field_access(ref_klass(), |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
878 |
resolved_klass(), |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
879 |
sel_klass(), |
1 | 880 |
fd.access_flags(), |
881 |
true)) { |
|
882 |
ResourceMark rm(THREAD); |
|
883 |
Exceptions::fthrow( |
|
884 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
885 |
vmSymbols::java_lang_IllegalAccessError(), |
1 | 886 |
"tried to access field %s.%s from class %s", |
887 |
sel_klass->external_name(), |
|
888 |
fd.name()->as_C_string(), |
|
889 |
ref_klass->external_name() |
|
890 |
); |
|
891 |
return; |
|
892 |
} |
|
893 |
} |
|
894 |
||
39421
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
895 |
void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) { |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
896 |
LinkInfo link_info(pool, index, method, CHECK); |
31019 | 897 |
resolve_field(fd, link_info, byte, true, CHECK); |
1 | 898 |
} |
899 |
||
31019 | 900 |
void LinkResolver::resolve_field(fieldDescriptor& fd, |
901 |
const LinkInfo& link_info, |
|
902 |
Bytecodes::Code byte, bool initialize_class, |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
903 |
TRAPS) { |
1 | 904 |
assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
905 |
byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || |
30117
cce2cdac56dc
8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents:
29081
diff
changeset
|
906 |
byte == Bytecodes::_nofast_getfield || byte == Bytecodes::_nofast_putfield || |
31019 | 907 |
(byte == Bytecodes::_nop && !link_info.check_access()), "bad field access bytecode"); |
1 | 908 |
|
909 |
bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); |
|
30117
cce2cdac56dc
8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents:
29081
diff
changeset
|
910 |
bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield); |
1 | 911 |
// Check if there's a resolved klass containing the field |
31019 | 912 |
KlassHandle resolved_klass = link_info.resolved_klass(); |
913 |
Symbol* field = link_info.name(); |
|
914 |
Symbol* sig = link_info.signature(); |
|
915 |
||
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
916 |
if (resolved_klass.is_null()) { |
1 | 917 |
ResourceMark rm(THREAD); |
918 |
THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
|
919 |
} |
|
920 |
||
921 |
// Resolve instance field |
|
27020 | 922 |
KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd)); |
1 | 923 |
// check if field exists; i.e., if a klass containing the field def has been selected |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
924 |
if (sel_klass.is_null()) { |
1 | 925 |
ResourceMark rm(THREAD); |
926 |
THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
|
927 |
} |
|
928 |
||
31019 | 929 |
if (!link_info.check_access()) |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
930 |
// Access checking may be turned off when calling from within the VM. |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
931 |
return; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
932 |
|
1 | 933 |
// check access |
31019 | 934 |
KlassHandle current_klass = link_info.current_klass(); |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
935 |
check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); |
1 | 936 |
|
937 |
// check for errors |
|
938 |
if (is_static != fd.is_static()) { |
|
9425
6da66b869573
6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents:
9116
diff
changeset
|
939 |
ResourceMark rm(THREAD); |
1 | 940 |
char msg[200]; |
14488 | 941 |
jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); |
1 | 942 |
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); |
943 |
} |
|
944 |
||
39421
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
945 |
// A final field can be modified only |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
946 |
// (1) by methods declared in the class declaring the field and |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
947 |
// (2) by the <clinit> method (in case of a static field) |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
948 |
// or by the <init> method (in case of an instance field). |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
949 |
if (is_put && fd.access_flags().is_final()) { |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
950 |
ResourceMark rm(THREAD); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
951 |
stringStream ss; |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
952 |
|
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
953 |
if (sel_klass() != current_klass()) { |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
954 |
ss.print("Update to %s final field %s.%s attempted from a different class (%s) than the field's declaring class", |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
955 |
is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(), |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
956 |
current_klass()->external_name()); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
957 |
THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string()); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
958 |
} |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
959 |
|
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
960 |
if (fd.constants()->pool_holder()->major_version() >= 53) { |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
961 |
methodHandle m = link_info.current_method(); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
962 |
assert(!m.is_null(), "information about the current method must be available for 'put' bytecodes"); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
963 |
bool is_initialized_static_final_update = (byte == Bytecodes::_putstatic && |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
964 |
fd.is_static() && |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
965 |
!m()->is_static_initializer()); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
966 |
bool is_initialized_instance_final_update = ((byte == Bytecodes::_putfield || byte == Bytecodes::_nofast_putfield) && |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
967 |
!fd.is_static() && |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
968 |
!m->is_object_initializer()); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
969 |
|
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
970 |
if (is_initialized_static_final_update || is_initialized_instance_final_update) { |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
971 |
ss.print("Update to %s final field %s.%s attempted from a different method (%s) than the initializer method %s ", |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
972 |
is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(), |
39699
7a2a49fd5ee0
8160527: Check for final instance field updates can be omitted
zmajo
parents:
39421
diff
changeset
|
973 |
m()->name()->as_C_string(), |
39421
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
974 |
is_static ? "<clinit>" : "<init>"); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
975 |
THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string()); |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
976 |
} |
a9652c919db8
8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents:
38939
diff
changeset
|
977 |
} |
1 | 978 |
} |
979 |
||
980 |
// initialize resolved_klass if necessary |
|
981 |
// note 1: the klass which declared the field must be initialized (i.e, sel_klass) |
|
982 |
// according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) |
|
983 |
// |
|
984 |
// note 2: we don't want to force initialization if we are just checking |
|
985 |
// if the field access is legal; e.g., during compilation |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
986 |
if (is_static && initialize_class) { |
1 | 987 |
sel_klass->initialize(CHECK); |
988 |
} |
|
989 |
||
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
990 |
if (sel_klass() != current_klass()) { |
31019 | 991 |
check_field_loader_constraints(field, sig, current_klass, sel_klass, CHECK); |
1 | 992 |
} |
993 |
||
994 |
// return information. note that the klass is set to the actual klass containing the |
|
995 |
// field, otherwise access of static fields in superclasses will not work. |
|
996 |
} |
|
997 |
||
998 |
||
999 |
//------------------------------------------------------------------------------------------------------------------------ |
|
1000 |
// Invoke resolution |
|
1001 |
// |
|
1002 |
// Naming conventions: |
|
1003 |
// |
|
1004 |
// resolved_method the specified method (i.e., static receiver specified via constant pool index) |
|
1005 |
// sel_method the selected method (selected via run-time lookup; e.g., based on dynamic receiver class) |
|
1006 |
// resolved_klass the specified klass (i.e., specified via constant pool index) |
|
1007 |
// recv_klass the receiver klass |
|
1008 |
||
1009 |
||
31019 | 1010 |
void LinkResolver::resolve_static_call(CallInfo& result, |
1011 |
const LinkInfo& link_info, |
|
1012 |
bool initialize_class, TRAPS) { |
|
1013 |
methodHandle resolved_method = linktime_resolve_static_method(link_info, CHECK); |
|
1 | 1014 |
|
31019 | 1015 |
// The resolved class can change as a result of this resolution. |
38939
c1b1d1d0e89b
8158397: Crash: assert(save_resolved_method == resolved_method()) failed: does this change?
coleenp
parents:
38719
diff
changeset
|
1016 |
KlassHandle resolved_klass(THREAD, resolved_method->method_holder()); |
31019 | 1017 |
|
1 | 1018 |
// Initialize klass (this should only happen if everything is ok) |
1019 |
if (initialize_class && resolved_klass->should_be_initialized()) { |
|
1020 |
resolved_klass->initialize(CHECK); |
|
38939
c1b1d1d0e89b
8158397: Crash: assert(save_resolved_method == resolved_method()) failed: does this change?
coleenp
parents:
38719
diff
changeset
|
1021 |
// Use updated LinkInfo to reresolve with resolved method holder |
31019 | 1022 |
LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(), |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
1023 |
link_info.current_klass(), |
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
1024 |
link_info.check_access() ? LinkInfo::needs_access_check : LinkInfo::skip_access_check); |
31019 | 1025 |
resolved_method = linktime_resolve_static_method(new_info, CHECK); |
1 | 1026 |
} |
1027 |
||
1028 |
// setup result |
|
1029 |
result.set_static(resolved_klass, resolved_method, CHECK); |
|
1030 |
} |
|
1031 |
||
1032 |
// throws linktime exceptions |
|
31019 | 1033 |
methodHandle LinkResolver::linktime_resolve_static_method(const LinkInfo& link_info, TRAPS) { |
1 | 1034 |
|
31019 | 1035 |
KlassHandle resolved_klass = link_info.resolved_klass(); |
1036 |
methodHandle resolved_method; |
|
21912 | 1037 |
if (!resolved_klass->is_interface()) { |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
1038 |
resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK_NULL); |
21912 | 1039 |
} else { |
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
1040 |
resolved_method = resolve_interface_method(link_info, Bytecodes::_invokestatic, CHECK_NULL); |
21912 | 1041 |
} |
1 | 1042 |
assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier"); |
1043 |
||
1044 |
// check if static |
|
1045 |
if (!resolved_method->is_static()) { |
|
9425
6da66b869573
6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents:
9116
diff
changeset
|
1046 |
ResourceMark rm(THREAD); |
1 | 1047 |
char buf[200]; |
14488 | 1048 |
jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass(), |
1 | 1049 |
resolved_method->name(), |
1050 |
resolved_method->signature())); |
|
31019 | 1051 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
1 | 1052 |
} |
31019 | 1053 |
return resolved_method; |
1 | 1054 |
} |
1055 |
||
1056 |
||
31019 | 1057 |
void LinkResolver::resolve_special_call(CallInfo& result, |
1058 |
const LinkInfo& link_info, |
|
1059 |
TRAPS) { |
|
1060 |
methodHandle resolved_method = linktime_resolve_special_method(link_info, CHECK); |
|
1061 |
runtime_resolve_special_method(result, resolved_method, |
|
1062 |
link_info.resolved_klass(), |
|
1063 |
link_info.current_klass(), |
|
1064 |
link_info.check_access(), CHECK); |
|
1 | 1065 |
} |
1066 |
||
1067 |
// throws linktime exceptions |
|
31019 | 1068 |
methodHandle LinkResolver::linktime_resolve_special_method(const LinkInfo& link_info, |
1069 |
TRAPS) { |
|
1 | 1070 |
|
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1071 |
// Invokespecial is called for multiple special reasons: |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1072 |
// <init> |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1073 |
// local private method invocation, for classes and interfaces |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1074 |
// superclass.method, which can also resolve to a default method |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1075 |
// and the selected method is recalculated relative to the direct superclass |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1076 |
// superinterface.method, which explicitly does not check shadowing |
31019 | 1077 |
KlassHandle resolved_klass = link_info.resolved_klass(); |
1078 |
methodHandle resolved_method; |
|
14385 | 1079 |
|
21912 | 1080 |
if (!resolved_klass->is_interface()) { |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
1081 |
resolved_method = resolve_method(link_info, Bytecodes::_invokespecial, CHECK_NULL); |
21912 | 1082 |
} else { |
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
1083 |
resolved_method = resolve_interface_method(link_info, Bytecodes::_invokespecial, CHECK_NULL); |
21912 | 1084 |
} |
1 | 1085 |
|
1086 |
// check if method name is <init>, that it is found in same klass as static type |
|
1087 |
if (resolved_method->name() == vmSymbols::object_initializer_name() && |
|
1088 |
resolved_method->method_holder() != resolved_klass()) { |
|
1089 |
ResourceMark rm(THREAD); |
|
1090 |
Exceptions::fthrow( |
|
1091 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
1092 |
vmSymbols::java_lang_NoSuchMethodError(), |
1 | 1093 |
"%s: method %s%s not found", |
1094 |
resolved_klass->external_name(), |
|
1095 |
resolved_method->name()->as_C_string(), |
|
1096 |
resolved_method->signature()->as_C_string() |
|
1097 |
); |
|
31019 | 1098 |
return NULL; |
1 | 1099 |
} |
1100 |
||
21768
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1101 |
// check if invokespecial's interface method reference is in an indirect superinterface |
31019 | 1102 |
KlassHandle current_klass = link_info.current_klass(); |
21768
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1103 |
if (!current_klass.is_null() && resolved_klass->is_interface()) { |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1104 |
Klass *klass_to_check = !InstanceKlass::cast(current_klass())->is_anonymous() ? |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1105 |
current_klass() : |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1106 |
InstanceKlass::cast(current_klass())->host_klass(); |
25057 | 1107 |
// Disable verification for the dynamically-generated reflection bytecodes. |
1108 |
bool is_reflect = klass_to_check->is_subclass_of( |
|
22218
71cff6a30ec1
8029415: java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java fails on all platforms with hs25-b61
hseigel
parents:
21913
diff
changeset
|
1109 |
SystemDictionary::reflect_MagicAccessorImpl_klass()); |
21768
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1110 |
|
22218
71cff6a30ec1
8029415: java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java fails on all platforms with hs25-b61
hseigel
parents:
21913
diff
changeset
|
1111 |
if (!is_reflect && |
71cff6a30ec1
8029415: java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java fails on all platforms with hs25-b61
hseigel
parents:
21913
diff
changeset
|
1112 |
!InstanceKlass::cast(klass_to_check)->is_same_or_direct_interface(resolved_klass())) { |
21768
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1113 |
ResourceMark rm(THREAD); |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1114 |
char buf[200]; |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1115 |
jio_snprintf(buf, sizeof(buf), |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1116 |
"Interface method reference: %s, is in an indirect superinterface of %s", |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1117 |
Method::name_and_sig_as_C_string(resolved_klass(), |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1118 |
resolved_method->name(), |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1119 |
resolved_method->signature()), |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1120 |
current_klass->external_name()); |
31019 | 1121 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
21768
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1122 |
} |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1123 |
} |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
21556
diff
changeset
|
1124 |
|
1 | 1125 |
// check if not static |
1126 |
if (resolved_method->is_static()) { |
|
9425
6da66b869573
6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents:
9116
diff
changeset
|
1127 |
ResourceMark rm(THREAD); |
1 | 1128 |
char buf[200]; |
1129 |
jio_snprintf(buf, sizeof(buf), |
|
1130 |
"Expecting non-static method %s", |
|
14488 | 1131 |
Method::name_and_sig_as_C_string(resolved_klass(), |
31019 | 1132 |
resolved_method->name(), |
1133 |
resolved_method->signature())); |
|
1134 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
|
1 | 1135 |
} |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
1136 |
|
35901
f5028c67e7cb
8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents:
35900
diff
changeset
|
1137 |
if (log_develop_is_enabled(Trace, itables)) { |
31019 | 1138 |
trace_method_resolution("invokespecial resolved method: caller-class:", |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
1139 |
current_klass, resolved_klass, resolved_method, true); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1140 |
} |
31019 | 1141 |
|
1142 |
return resolved_method; |
|
1 | 1143 |
} |
1144 |
||
1145 |
// throws runtime exceptions |
|
31019 | 1146 |
void LinkResolver::runtime_resolve_special_method(CallInfo& result, |
1147 |
const methodHandle& resolved_method, |
|
1148 |
KlassHandle resolved_klass, |
|
1149 |
KlassHandle current_klass, |
|
1150 |
bool check_access, TRAPS) { |
|
1 | 1151 |
|
1152 |
// resolved method is selected method unless we have an old-style lookup |
|
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1153 |
// for a superclass method |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1154 |
// Invokespecial for a superinterface, resolved method is selected method, |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1155 |
// no checks for shadowing |
1 | 1156 |
methodHandle sel_method(THREAD, resolved_method()); |
1157 |
||
1158 |
// check if this is an old-style super call and do a new lookup if so |
|
1159 |
{ KlassHandle method_klass = KlassHandle(THREAD, |
|
1160 |
resolved_method->method_holder()); |
|
1161 |
||
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1162 |
if (check_access && |
1 | 1163 |
// a) check if ACC_SUPER flag is set for the current class |
15918 | 1164 |
(current_klass->is_super() || !AllowNonVirtualCalls) && |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1165 |
// b) check if the class of the resolved_klass is a superclass |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1166 |
// (not supertype in order to exclude interface classes) of the current class. |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1167 |
// This check is not performed for super.invoke for interface methods |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1168 |
// in super interfaces. |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1169 |
current_klass->is_subclass_of(resolved_klass()) && |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1170 |
current_klass() != resolved_klass() && |
1 | 1171 |
// c) check if the method is not <init> |
1172 |
resolved_method->name() != vmSymbols::object_initializer_name()) { |
|
1173 |
// Lookup super method |
|
1174 |
KlassHandle super_klass(THREAD, current_klass->super()); |
|
31019 | 1175 |
sel_method = lookup_instance_method_in_klasses(super_klass, |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
1176 |
resolved_method->name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
1177 |
resolved_method->signature(), CHECK); |
1 | 1178 |
// check if found |
1179 |
if (sel_method.is_null()) { |
|
1180 |
ResourceMark rm(THREAD); |
|
1181 |
THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
|
14488 | 1182 |
Method::name_and_sig_as_C_string(resolved_klass(), |
1 | 1183 |
resolved_method->name(), |
1184 |
resolved_method->signature())); |
|
1185 |
} |
|
1186 |
} |
|
1187 |
} |
|
1188 |
||
1189 |
// check if not static |
|
1190 |
if (sel_method->is_static()) { |
|
9425
6da66b869573
6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents:
9116
diff
changeset
|
1191 |
ResourceMark rm(THREAD); |
1 | 1192 |
char buf[200]; |
14488 | 1193 |
jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), |
1 | 1194 |
resolved_method->name(), |
1195 |
resolved_method->signature())); |
|
1196 |
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
|
1197 |
} |
|
1198 |
||
1199 |
// check if abstract |
|
1200 |
if (sel_method->is_abstract()) { |
|
1201 |
ResourceMark rm(THREAD); |
|
1202 |
THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
|
14488 | 1203 |
Method::name_and_sig_as_C_string(resolved_klass(), |
31019 | 1204 |
sel_method->name(), |
1205 |
sel_method->signature())); |
|
1 | 1206 |
} |
1207 |
||
35901
f5028c67e7cb
8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents:
35900
diff
changeset
|
1208 |
if (log_develop_is_enabled(Trace, itables)) { |
31019 | 1209 |
trace_method_resolution("invokespecial selected method: resolved-class:", |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
1210 |
resolved_klass, resolved_klass, sel_method, true); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1211 |
} |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1212 |
|
1 | 1213 |
// setup result |
1214 |
result.set_static(resolved_klass, sel_method, CHECK); |
|
1215 |
} |
|
1216 |
||
31019 | 1217 |
void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, |
1218 |
const LinkInfo& link_info, |
|
1219 |
bool check_null_and_abstract, TRAPS) { |
|
1220 |
methodHandle resolved_method = linktime_resolve_virtual_method(link_info, CHECK); |
|
1221 |
runtime_resolve_virtual_method(result, resolved_method, |
|
1222 |
link_info.resolved_klass(), |
|
1223 |
recv, receiver_klass, |
|
1224 |
check_null_and_abstract, CHECK); |
|
1 | 1225 |
} |
1226 |
||
1227 |
// throws linktime exceptions |
|
31019 | 1228 |
methodHandle LinkResolver::linktime_resolve_virtual_method(const LinkInfo& link_info, |
1229 |
TRAPS) { |
|
1 | 1230 |
// normal method resolution |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
1231 |
methodHandle resolved_method = resolve_method(link_info, Bytecodes::_invokevirtual, CHECK_NULL); |
1 | 1232 |
|
1233 |
assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); |
|
1234 |
assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); |
|
1235 |
||
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1236 |
// check if private interface method |
31019 | 1237 |
KlassHandle resolved_klass = link_info.resolved_klass(); |
1238 |
KlassHandle current_klass = link_info.current_klass(); |
|
1239 |
||
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
1240 |
// This is impossible, if resolve_klass is an interface, we've thrown icce in resolve_method |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1241 |
if (resolved_klass->is_interface() && resolved_method->is_private()) { |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1242 |
ResourceMark rm(THREAD); |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1243 |
char buf[200]; |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1244 |
jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokevirtual: method %s, caller-class:%s", |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1245 |
Method::name_and_sig_as_C_string(resolved_klass(), |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1246 |
resolved_method->name(), |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1247 |
resolved_method->signature()), |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1248 |
(current_klass.is_null() ? "<NULL>" : current_klass->internal_name())); |
31019 | 1249 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1250 |
} |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1251 |
|
1 | 1252 |
// check if not static |
1253 |
if (resolved_method->is_static()) { |
|
9425
6da66b869573
6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents:
9116
diff
changeset
|
1254 |
ResourceMark rm(THREAD); |
1 | 1255 |
char buf[200]; |
14488 | 1256 |
jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), |
1 | 1257 |
resolved_method->name(), |
1258 |
resolved_method->signature())); |
|
31019 | 1259 |
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
1 | 1260 |
} |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1261 |
|
35901
f5028c67e7cb
8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents:
35900
diff
changeset
|
1262 |
if (log_develop_is_enabled(Trace, vtables)) { |
31019 | 1263 |
trace_method_resolution("invokevirtual resolved method: caller-class:", |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
1264 |
current_klass, resolved_klass, resolved_method, false); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
1265 |
} |
31019 | 1266 |
|
1267 |
return resolved_method; |
|
1 | 1268 |
} |
1269 |
||
1270 |
// throws runtime exceptions |
|
1271 |
void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, |
|
31019 | 1272 |
const methodHandle& resolved_method, |
1 | 1273 |
KlassHandle resolved_klass, |
1274 |
Handle recv, |
|
1275 |
KlassHandle recv_klass, |
|
1276 |
bool check_null_and_abstract, |
|
1277 |
TRAPS) { |
|
1278 |
||
1279 |
// setup default return values |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1280 |
int vtable_index = Method::invalid_vtable_index; |
1 | 1281 |
methodHandle selected_method; |
1282 |
||
1283 |
assert(recv.is_null() || recv->is_oop(), "receiver is not an oop"); |
|
1284 |
||
1285 |
// runtime method resolution |
|
1286 |
if (check_null_and_abstract && recv.is_null()) { // check if receiver exists |
|
1287 |
THROW(vmSymbols::java_lang_NullPointerException()); |
|
1288 |
} |
|
1289 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1290 |
// Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s |
1 | 1291 |
// has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since |
1292 |
// a missing receiver might result in a bogus lookup. |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
14385
diff
changeset
|
1293 |
assert(resolved_method->method_holder()->is_linked(), "must be linked"); |
1 | 1294 |
|
1295 |
// do lookup based on receiver klass using the vtable index |
|
32189
5264b560ab1b
8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents:
31019
diff
changeset
|
1296 |
if (resolved_method->method_holder()->is_interface()) { // default or miranda method |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20284
diff
changeset
|
1297 |
vtable_index = vtable_index_of_interface_method(resolved_klass, |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1298 |
resolved_method); |
1 | 1299 |
assert(vtable_index >= 0 , "we should have valid vtable index at this point"); |
1300 |
||
35900 | 1301 |
selected_method = methodHandle(THREAD, recv_klass->method_at_vtable(vtable_index)); |
1 | 1302 |
} else { |
1303 |
// at this point we are sure that resolved_method is virtual and not |
|
32189
5264b560ab1b
8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents:
31019
diff
changeset
|
1304 |
// a default or miranda method; therefore, it must have a valid vtable index. |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
1305 |
assert(!resolved_method->has_itable_index(), ""); |
1 | 1306 |
vtable_index = resolved_method->vtable_index(); |
1307 |
// We could get a negative vtable_index for final methods, |
|
1308 |
// because as an optimization they are they are never put in the vtable, |
|
1309 |
// unless they override an existing method. |
|
1310 |
// If we do get a negative, it means the resolved method is the the selected |
|
1311 |
// method, and it can never be changed by an override. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1312 |
if (vtable_index == Method::nonvirtual_vtable_index) { |
1 | 1313 |
assert(resolved_method->can_be_statically_bound(), "cannot override this method"); |
1314 |
selected_method = resolved_method; |
|
1315 |
} else { |
|
35900 | 1316 |
selected_method = methodHandle(THREAD, recv_klass->method_at_vtable(vtable_index)); |
1 | 1317 |
} |
1318 |
} |
|
1319 |
||
1320 |
// check if method exists |
|
1321 |
if (selected_method.is_null()) { |
|
1322 |
ResourceMark rm(THREAD); |
|
1323 |
THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
|
14488 | 1324 |
Method::name_and_sig_as_C_string(resolved_klass(), |
1 | 1325 |
resolved_method->name(), |
1326 |
resolved_method->signature())); |
|
1327 |
} |
|
1328 |
||
1329 |
// check if abstract |
|
1330 |
if (check_null_and_abstract && selected_method->is_abstract()) { |
|
1331 |
ResourceMark rm(THREAD); |
|
1332 |
THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
|
14488 | 1333 |
Method::name_and_sig_as_C_string(resolved_klass(), |
1 | 1334 |
selected_method->name(), |
1335 |
selected_method->signature())); |
|
1336 |
} |
|
1337 |
||
35901
f5028c67e7cb
8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents:
35900
diff
changeset
|
1338 |
if (log_develop_is_enabled(Trace, vtables)) { |
31019 | 1339 |
trace_method_resolution("invokevirtual selected method: receiver-class:", |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
1340 |
recv_klass, resolved_klass, selected_method, |
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
1341 |
false, vtable_index); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1342 |
} |
1 | 1343 |
// setup result |
1344 |
result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK); |
|
1345 |
} |
|
1346 |
||
31019 | 1347 |
void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, |
1348 |
const LinkInfo& link_info, |
|
1349 |
bool check_null_and_abstract, TRAPS) { |
|
1350 |
// throws linktime exceptions |
|
1351 |
methodHandle resolved_method = linktime_resolve_interface_method(link_info, CHECK); |
|
1352 |
runtime_resolve_interface_method(result, resolved_method,link_info.resolved_klass(), |
|
1353 |
recv, recv_klass, check_null_and_abstract, CHECK); |
|
1 | 1354 |
} |
1355 |
||
31019 | 1356 |
methodHandle LinkResolver::linktime_resolve_interface_method(const LinkInfo& link_info, |
1357 |
TRAPS) { |
|
1 | 1358 |
// normal interface method resolution |
38034
f22f68545fd5
8153115: Move private interface check to linktime
iveresov
parents:
37267
diff
changeset
|
1359 |
methodHandle resolved_method = resolve_interface_method(link_info, Bytecodes::_invokeinterface, CHECK_NULL); |
1 | 1360 |
assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); |
1361 |
assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); |
|
31019 | 1362 |
|
1363 |
return resolved_method; |
|
1 | 1364 |
} |
1365 |
||
1366 |
// throws runtime exceptions |
|
31019 | 1367 |
void LinkResolver::runtime_resolve_interface_method(CallInfo& result, |
1368 |
const methodHandle& resolved_method, |
|
1369 |
KlassHandle resolved_klass, |
|
1370 |
Handle recv, |
|
1371 |
KlassHandle recv_klass, |
|
1372 |
bool check_null_and_abstract, TRAPS) { |
|
1 | 1373 |
// check if receiver exists |
1374 |
if (check_null_and_abstract && recv.is_null()) { |
|
1375 |
THROW(vmSymbols::java_lang_NullPointerException()); |
|
1376 |
} |
|
1377 |
||
1378 |
// check if receiver klass implements the resolved interface |
|
1379 |
if (!recv_klass->is_subtype_of(resolved_klass())) { |
|
9425
6da66b869573
6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents:
9116
diff
changeset
|
1380 |
ResourceMark rm(THREAD); |
1 | 1381 |
char buf[200]; |
1382 |
jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", |
|
14488 | 1383 |
recv_klass()->external_name(), |
1384 |
resolved_klass()->external_name()); |
|
1 | 1385 |
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
1386 |
} |
|
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
1387 |
|
1 | 1388 |
// do lookup based on receiver klass |
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
1389 |
// This search must match the linktime preparation search for itable initialization |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
22219
diff
changeset
|
1390 |
// to correctly enforce loader constraints for interface method inheritance |
31019 | 1391 |
methodHandle sel_method = lookup_instance_method_in_klasses(recv_klass, |
1392 |
resolved_method->name(), |
|
1393 |
resolved_method->signature(), CHECK); |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
1394 |
if (sel_method.is_null() && !check_null_and_abstract) { |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
1395 |
// In theory this is a harmless placeholder value, but |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
1396 |
// in practice leaving in null affects the nsk default method tests. |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
1397 |
// This needs further study. |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
1398 |
sel_method = resolved_method; |
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
17024
diff
changeset
|
1399 |
} |
1 | 1400 |
// check if method exists |
1401 |
if (sel_method.is_null()) { |
|
1402 |
ResourceMark rm(THREAD); |
|
1403 |
THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
|
31019 | 1404 |
Method::name_and_sig_as_C_string(recv_klass(), |
1405 |
resolved_method->name(), |
|
1406 |
resolved_method->signature())); |
|
1 | 1407 |
} |
17024
49cbeca23983
8006267: InterfaceMethod_ref should allow invokestatic and invokespecial
bharadwaj
parents:
16691
diff
changeset
|
1408 |
// check access |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1409 |
// Throw Illegal Access Error if sel_method is not public. |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1410 |
if (!sel_method->is_public()) { |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1411 |
ResourceMark rm(THREAD); |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1412 |
THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1413 |
Method::name_and_sig_as_C_string(recv_klass(), |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1414 |
sel_method->name(), |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1415 |
sel_method->signature())); |
17024
49cbeca23983
8006267: InterfaceMethod_ref should allow invokestatic and invokespecial
bharadwaj
parents:
16691
diff
changeset
|
1416 |
} |
1 | 1417 |
// check if abstract |
1418 |
if (check_null_and_abstract && sel_method->is_abstract()) { |
|
1419 |
ResourceMark rm(THREAD); |
|
1420 |
THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
|
14488 | 1421 |
Method::name_and_sig_as_C_string(recv_klass(), |
1 | 1422 |
sel_method->name(), |
1423 |
sel_method->signature())); |
|
1424 |
} |
|
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1425 |
|
35901
f5028c67e7cb
8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents:
35900
diff
changeset
|
1426 |
if (log_develop_is_enabled(Trace, itables)) { |
31019 | 1427 |
trace_method_resolution("invokeinterface selected method: receiver-class", |
35463
b32e362563bb
8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents:
34666
diff
changeset
|
1428 |
recv_klass, resolved_klass, sel_method, true); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
20282
diff
changeset
|
1429 |
} |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1430 |
// setup result |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1431 |
if (!resolved_method->has_itable_index()) { |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1432 |
int vtable_index = resolved_method->vtable_index(); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1433 |
assert(vtable_index == sel_method->vtable_index(), "sanity check"); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1434 |
result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1435 |
} else { |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1436 |
int itable_index = resolved_method()->itable_index(); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1437 |
result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21078
diff
changeset
|
1438 |
} |
1 | 1439 |
} |
1440 |
||
1441 |
||
1442 |
methodHandle LinkResolver::linktime_resolve_interface_method_or_null( |
|
31019 | 1443 |
const LinkInfo& link_info) { |
1 | 1444 |
EXCEPTION_MARK; |
31019 | 1445 |
methodHandle method_result = linktime_resolve_interface_method(link_info, THREAD); |
1 | 1446 |
if (HAS_PENDING_EXCEPTION) { |
1447 |
CLEAR_PENDING_EXCEPTION; |
|
1448 |
return methodHandle(); |
|
1449 |
} else { |
|
1450 |
return method_result; |
|
1451 |
} |
|
1452 |
} |
|
1453 |
||
1454 |
methodHandle LinkResolver::linktime_resolve_virtual_method_or_null( |
|
31019 | 1455 |
const LinkInfo& link_info) { |
1 | 1456 |
EXCEPTION_MARK; |
31019 | 1457 |
methodHandle method_result = linktime_resolve_virtual_method(link_info, THREAD); |
1 | 1458 |
if (HAS_PENDING_EXCEPTION) { |
1459 |
CLEAR_PENDING_EXCEPTION; |
|
1460 |
return methodHandle(); |
|
1461 |
} else { |
|
1462 |
return method_result; |
|
1463 |
} |
|
1464 |
} |
|
1465 |
||
1466 |
methodHandle LinkResolver::resolve_virtual_call_or_null( |
|
1467 |
KlassHandle receiver_klass, |
|
31019 | 1468 |
const LinkInfo& link_info) { |
1 | 1469 |
EXCEPTION_MARK; |
1470 |
CallInfo info; |
|
31019 | 1471 |
resolve_virtual_call(info, Handle(), receiver_klass, link_info, false, THREAD); |
1 | 1472 |
if (HAS_PENDING_EXCEPTION) { |
1473 |
CLEAR_PENDING_EXCEPTION; |
|
1474 |
return methodHandle(); |
|
1475 |
} |
|
1476 |
return info.selected_method(); |
|
1477 |
} |
|
1478 |
||
1479 |
methodHandle LinkResolver::resolve_interface_call_or_null( |
|
1480 |
KlassHandle receiver_klass, |
|
31019 | 1481 |
const LinkInfo& link_info) { |
1 | 1482 |
EXCEPTION_MARK; |
1483 |
CallInfo info; |
|
31019 | 1484 |
resolve_interface_call(info, Handle(), receiver_klass, link_info, false, THREAD); |
1 | 1485 |
if (HAS_PENDING_EXCEPTION) { |
1486 |
CLEAR_PENDING_EXCEPTION; |
|
1487 |
return methodHandle(); |
|
1488 |
} |
|
1489 |
return info.selected_method(); |
|
1490 |
} |
|
1491 |
||
31019 | 1492 |
int LinkResolver::resolve_virtual_vtable_index(KlassHandle receiver_klass, |
1493 |
const LinkInfo& link_info) { |
|
1 | 1494 |
EXCEPTION_MARK; |
1495 |
CallInfo info; |
|
31019 | 1496 |
resolve_virtual_call(info, Handle(), receiver_klass, link_info, |
1497 |
/*check_null_or_abstract*/false, THREAD); |
|
1 | 1498 |
if (HAS_PENDING_EXCEPTION) { |
1499 |
CLEAR_PENDING_EXCEPTION; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1500 |
return Method::invalid_vtable_index; |
1 | 1501 |
} |
1502 |
return info.vtable_index(); |
|
1503 |
} |
|
1504 |
||
31019 | 1505 |
methodHandle LinkResolver::resolve_static_call_or_null(const LinkInfo& link_info) { |
1 | 1506 |
EXCEPTION_MARK; |
1507 |
CallInfo info; |
|
31019 | 1508 |
resolve_static_call(info, link_info, /*initialize_class*/false, THREAD); |
1 | 1509 |
if (HAS_PENDING_EXCEPTION) { |
1510 |
CLEAR_PENDING_EXCEPTION; |
|
1511 |
return methodHandle(); |
|
1512 |
} |
|
1513 |
return info.selected_method(); |
|
1514 |
} |
|
1515 |
||
31019 | 1516 |
methodHandle LinkResolver::resolve_special_call_or_null(const LinkInfo& link_info) { |
1 | 1517 |
EXCEPTION_MARK; |
1518 |
CallInfo info; |
|
31019 | 1519 |
resolve_special_call(info, link_info, THREAD); |
1 | 1520 |
if (HAS_PENDING_EXCEPTION) { |
1521 |
CLEAR_PENDING_EXCEPTION; |
|
1522 |
return methodHandle(); |
|
1523 |
} |
|
1524 |
return info.selected_method(); |
|
1525 |
} |
|
1526 |
||
1527 |
||
1528 |
||
1529 |
//------------------------------------------------------------------------------------------------------------------------ |
|
1530 |
// ConstantPool entries |
|
1531 |
||
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
1532 |
void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, const constantPoolHandle& pool, int index, Bytecodes::Code byte, TRAPS) { |
1 | 1533 |
switch (byte) { |
1534 |
case Bytecodes::_invokestatic : resolve_invokestatic (result, pool, index, CHECK); break; |
|
1535 |
case Bytecodes::_invokespecial : resolve_invokespecial (result, pool, index, CHECK); break; |
|
1536 |
case Bytecodes::_invokevirtual : resolve_invokevirtual (result, recv, pool, index, CHECK); break; |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1537 |
case Bytecodes::_invokehandle : resolve_invokehandle (result, pool, index, CHECK); break; |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
1538 |
case Bytecodes::_invokedynamic : resolve_invokedynamic (result, pool, index, CHECK); break; |
1 | 1539 |
case Bytecodes::_invokeinterface: resolve_invokeinterface(result, recv, pool, index, CHECK); break; |
1540 |
} |
|
1541 |
return; |
|
1542 |
} |
|
1543 |
||
35086
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1544 |
void LinkResolver::resolve_invoke(CallInfo& result, Handle& recv, |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1545 |
const methodHandle& attached_method, |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1546 |
Bytecodes::Code byte, TRAPS) { |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1547 |
KlassHandle defc = attached_method->method_holder(); |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1548 |
Symbol* name = attached_method->name(); |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1549 |
Symbol* type = attached_method->signature(); |
38719
133bf85c3f36
8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents:
38139
diff
changeset
|
1550 |
LinkInfo link_info(defc, name, type); |
35086
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1551 |
switch(byte) { |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1552 |
case Bytecodes::_invokevirtual: |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1553 |
resolve_virtual_call(result, recv, recv->klass(), link_info, |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1554 |
/*check_null_and_abstract=*/true, CHECK); |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1555 |
break; |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1556 |
case Bytecodes::_invokeinterface: |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1557 |
resolve_interface_call(result, recv, recv->klass(), link_info, |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1558 |
/*check_null_and_abstract=*/true, CHECK); |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1559 |
break; |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1560 |
case Bytecodes::_invokestatic: |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1561 |
resolve_static_call(result, link_info, /*initialize_class=*/false, CHECK); |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1562 |
break; |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1563 |
case Bytecodes::_invokespecial: |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1564 |
resolve_special_call(result, link_info, CHECK); |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1565 |
break; |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1566 |
default: |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1567 |
fatal("bad call: %s", Bytecodes::name(byte)); |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1568 |
} |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1569 |
} |
bbf32241d851
8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents:
34238
diff
changeset
|
1570 |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
1571 |
void LinkResolver::resolve_invokestatic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { |
31019 | 1572 |
LinkInfo link_info(pool, index, CHECK); |
1573 |
resolve_static_call(result, link_info, /*initialize_class*/true, CHECK); |
|
1 | 1574 |
} |
1575 |
||
1576 |
||
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
1577 |
void LinkResolver::resolve_invokespecial(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { |
31019 | 1578 |
LinkInfo link_info(pool, index, CHECK); |
1579 |
resolve_special_call(result, link_info, CHECK); |
|
1 | 1580 |
} |
1581 |
||
1582 |
||
1583 |
void LinkResolver::resolve_invokevirtual(CallInfo& result, Handle recv, |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
1584 |
const constantPoolHandle& pool, int index, |
1 | 1585 |
TRAPS) { |
1586 |
||
31019 | 1587 |
LinkInfo link_info(pool, index, CHECK); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1588 |
KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass()); |
31019 | 1589 |
resolve_virtual_call(result, recv, recvrKlass, link_info, /*check_null_or_abstract*/true, CHECK); |
1 | 1590 |
} |
1591 |
||
1592 |
||
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
1593 |
void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, const constantPoolHandle& pool, int index, TRAPS) { |
31019 | 1594 |
LinkInfo link_info(pool, index, CHECK); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1595 |
KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass()); |
31019 | 1596 |
resolve_interface_call(result, recv, recvrKlass, link_info, true, CHECK); |
1 | 1597 |
} |
1598 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
1599 |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
1600 |
void LinkResolver::resolve_invokehandle(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1601 |
// This guy is reached from InterpreterRuntime::resolve_invokehandle. |
31019 | 1602 |
LinkInfo link_info(pool, index, CHECK); |
16691 | 1603 |
if (TraceMethodHandles) { |
1604 |
ResourceMark rm(THREAD); |
|
31019 | 1605 |
tty->print_cr("resolve_invokehandle %s %s", link_info.name()->as_C_string(), |
1606 |
link_info.signature()->as_C_string()); |
|
16691 | 1607 |
} |
31019 | 1608 |
resolve_handle_call(result, link_info, CHECK); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1609 |
} |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
1610 |
|
31019 | 1611 |
void LinkResolver::resolve_handle_call(CallInfo& result, |
1612 |
const LinkInfo& link_info, |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1613 |
TRAPS) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1614 |
// JSR 292: this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar |
36819 | 1615 |
KlassHandle resolved_klass = link_info.resolved_klass(); |
1616 |
assert(resolved_klass() == SystemDictionary::MethodHandle_klass() || |
|
1617 |
resolved_klass() == SystemDictionary::VarHandle_klass(), ""); |
|
31019 | 1618 |
assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), ""); |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
1619 |
Handle resolved_appendix; |
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
1620 |
Handle resolved_method_type; |
31019 | 1621 |
methodHandle resolved_method = lookup_polymorphic_method(link_info, |
1622 |
&resolved_appendix, &resolved_method_type, CHECK); |
|
36819 | 1623 |
result.set_handle(resolved_klass, resolved_method, resolved_appendix, resolved_method_type, CHECK); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1624 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1625 |
|
30746
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1626 |
static void wrap_invokedynamic_exception(TRAPS) { |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1627 |
if (HAS_PENDING_EXCEPTION) { |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1628 |
if (TraceMethodHandles) { |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1629 |
tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION)); |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1630 |
PENDING_EXCEPTION->print(); |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1631 |
} |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1632 |
if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) { |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1633 |
// throw these guys, since they are already wrapped |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1634 |
return; |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1635 |
} |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1636 |
if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1637 |
// intercept only LinkageErrors which might have failed to wrap |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1638 |
return; |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1639 |
} |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1640 |
// See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS. |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1641 |
Handle nested_exception(THREAD, PENDING_EXCEPTION); |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1642 |
CLEAR_PENDING_EXCEPTION; |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1643 |
THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception) |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1644 |
} |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1645 |
} |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1646 |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33198
diff
changeset
|
1647 |
void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1648 |
Symbol* method_name = pool->name_ref_at(index); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1649 |
Symbol* method_signature = pool->signature_ref_at(index); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1650 |
KlassHandle current_klass = KlassHandle(THREAD, pool->pool_holder()); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
1651 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1652 |
// Resolve the bootstrap specifier (BSM + optional arguments). |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1653 |
Handle bootstrap_specifier; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1654 |
// Check if CallSite has been bound already: |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1655 |
ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1656 |
if (cpce->is_f1_null()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1657 |
int pool_index = cpce->constant_pool_index(); |
30746
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1658 |
oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, THREAD); |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1659 |
wrap_invokedynamic_exception(CHECK); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1660 |
assert(bsm_info != NULL, ""); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1661 |
// FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_InvokeDynamic. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1662 |
bootstrap_specifier = Handle(THREAD, bsm_info); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1663 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1664 |
if (!cpce->is_f1_null()) { |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
1665 |
methodHandle method( THREAD, cpce->f1_as_method()); |
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
1666 |
Handle appendix( THREAD, cpce->appendix_if_resolved(pool)); |
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
1667 |
Handle method_type(THREAD, cpce->method_type_if_resolved(pool)); |
30746
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1668 |
result.set_handle(method, appendix, method_type, THREAD); |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1669 |
wrap_invokedynamic_exception(CHECK); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1670 |
return; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1671 |
} |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
1672 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1673 |
if (TraceMethodHandles) { |
35543
0961315f4016
8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents:
35135
diff
changeset
|
1674 |
ResourceMark rm(THREAD); |
0961315f4016
8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents:
35135
diff
changeset
|
1675 |
tty->print_cr("resolve_invokedynamic #%d %s %s in %s", |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13396
diff
changeset
|
1676 |
ConstantPool::decode_invokedynamic_index(index), |
35543
0961315f4016
8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents:
35135
diff
changeset
|
1677 |
method_name->as_C_string(), method_signature->as_C_string(), |
0961315f4016
8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents:
35135
diff
changeset
|
1678 |
current_klass->name()->as_C_string()); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1679 |
tty->print(" BSM info: "); bootstrap_specifier->print(); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1680 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1681 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1682 |
resolve_dynamic_call(result, bootstrap_specifier, method_name, method_signature, current_klass, CHECK); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1683 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1684 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1685 |
void LinkResolver::resolve_dynamic_call(CallInfo& result, |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1686 |
Handle bootstrap_specifier, |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1687 |
Symbol* method_name, Symbol* method_signature, |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1688 |
KlassHandle current_klass, |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1689 |
TRAPS) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1690 |
// JSR 292: this must resolve to an implicitly generated method MH.linkToCallSite(*...) |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1691 |
// The appendix argument is likely to be a freshly-created CallSite. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1692 |
Handle resolved_appendix; |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
1693 |
Handle resolved_method_type; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1694 |
methodHandle resolved_method = |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1695 |
SystemDictionary::find_dynamic_call_site_invoker(current_klass, |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1696 |
bootstrap_specifier, |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1697 |
method_name, method_signature, |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
10565
diff
changeset
|
1698 |
&resolved_appendix, |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13732
diff
changeset
|
1699 |
&resolved_method_type, |
13732
a9865f5514fc
7196120: NPG: JSR 2292 test fails because missing fix for 7188911
twisti
parents:
13728
diff
changeset
|
1700 |
THREAD); |
30746
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1701 |
wrap_invokedynamic_exception(CHECK); |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1702 |
result.set_handle(resolved_method, resolved_appendix, resolved_method_type, THREAD); |
dfce1db72058
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
30227
diff
changeset
|
1703 |
wrap_invokedynamic_exception(CHECK); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
1704 |
} |