Mercurial > hg > graal-compiler
annotate src/share/vm/classfile/defaultMethods.cpp @ 12213:42863137168c
8024647: Default method resolution with private superclass method
Reviewed-by: kamg, minqi
author | acorn |
---|---|
date | Mon, 16 Sep 2013 17:57:56 -0400 |
parents | 915cc4f3fb15 |
children | 36b97be47bde f2512d89ad0c |
rev | line source |
---|---|
6934 | 1 /* |
8031 | 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
6934 | 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 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 #include "precompiled.hpp" | |
26 #include "classfile/bytecodeAssembler.hpp" | |
27 #include "classfile/defaultMethods.hpp" | |
28 #include "classfile/symbolTable.hpp" | |
29 #include "memory/allocation.hpp" | |
30 #include "memory/metadataFactory.hpp" | |
31 #include "memory/resourceArea.hpp" | |
32 #include "runtime/signature.hpp" | |
33 #include "runtime/thread.hpp" | |
34 #include "oops/instanceKlass.hpp" | |
35 #include "oops/klass.hpp" | |
36 #include "oops/method.hpp" | |
37 #include "utilities/accessFlags.hpp" | |
38 #include "utilities/exceptions.hpp" | |
39 #include "utilities/ostream.hpp" | |
40 #include "utilities/pair.hpp" | |
41 #include "utilities/resourceHash.hpp" | |
42 | |
43 typedef enum { QUALIFIED, DISQUALIFIED } QualifiedState; | |
44 | |
45 // Because we use an iterative algorithm when iterating over the type | |
46 // hierarchy, we can't use traditional scoped objects which automatically do | |
47 // cleanup in the destructor when the scope is exited. PseudoScope (and | |
48 // PseudoScopeMark) provides a similar functionality, but for when you want a | |
49 // scoped object in non-stack memory (such as in resource memory, as we do | |
50 // here). You've just got to remember to call 'destroy()' on the scope when | |
51 // leaving it (and marks have to be explicitly added). | |
52 class PseudoScopeMark : public ResourceObj { | |
53 public: | |
54 virtual void destroy() = 0; | |
55 }; | |
56 | |
57 class PseudoScope : public ResourceObj { | |
58 private: | |
59 GrowableArray<PseudoScopeMark*> _marks; | |
60 public: | |
61 | |
62 static PseudoScope* cast(void* data) { | |
63 return static_cast<PseudoScope*>(data); | |
64 } | |
65 | |
66 void add_mark(PseudoScopeMark* psm) { | |
67 _marks.append(psm); | |
68 } | |
69 | |
70 void destroy() { | |
71 for (int i = 0; i < _marks.length(); ++i) { | |
72 _marks.at(i)->destroy(); | |
73 } | |
74 } | |
75 }; | |
76 | |
77 #ifndef PRODUCT | |
78 static void print_slot(outputStream* str, Symbol* name, Symbol* signature) { | |
79 ResourceMark rm; | |
80 str->print("%s%s", name->as_C_string(), signature->as_C_string()); | |
81 } | |
82 | |
83 static void print_method(outputStream* str, Method* mo, bool with_class=true) { | |
84 ResourceMark rm; | |
85 if (with_class) { | |
86 str->print("%s.", mo->klass_name()->as_C_string()); | |
87 } | |
88 print_slot(str, mo->name(), mo->signature()); | |
89 } | |
90 #endif // ndef PRODUCT | |
91 | |
92 /** | |
93 * Perform a depth-first iteration over the class hierarchy, applying | |
94 * algorithmic logic as it goes. | |
95 * | |
96 * This class is one half of the inheritance hierarchy analysis mechanism. | |
97 * It is meant to be used in conjunction with another class, the algorithm, | |
98 * which is indicated by the ALGO template parameter. This class can be | |
99 * paired with any algorithm class that provides the required methods. | |
100 * | |
101 * This class contains all the mechanics for iterating over the class hierarchy | |
102 * starting at a particular root, without recursing (thus limiting stack growth | |
103 * from this point). It visits each superclass (if present) and superinterface | |
104 * in a depth-first manner, with callbacks to the ALGO class as each class is | |
105 * encountered (visit()), The algorithm can cut-off further exploration of a | |
106 * particular branch by returning 'false' from a visit() call. | |
107 * | |
108 * The ALGO class, must provide a visit() method, which each of which will be | |
109 * called once for each node in the inheritance tree during the iteration. In | |
110 * addition, it can provide a memory block via new_node_data(InstanceKlass*), | |
111 * which it can use for node-specific storage (and access via the | |
112 * current_data() and data_at_depth(int) methods). | |
113 * | |
114 * Bare minimum needed to be an ALGO class: | |
115 * class Algo : public HierarchyVisitor<Algo> { | |
116 * void* new_node_data(InstanceKlass* cls) { return NULL; } | |
117 * void free_node_data(void* data) { return; } | |
118 * bool visit() { return true; } | |
119 * }; | |
120 */ | |
121 template <class ALGO> | |
122 class HierarchyVisitor : StackObj { | |
123 private: | |
124 | |
125 class Node : public ResourceObj { | |
126 public: | |
127 InstanceKlass* _class; | |
128 bool _super_was_visited; | |
129 int _interface_index; | |
130 void* _algorithm_data; | |
131 | |
132 Node(InstanceKlass* cls, void* data, bool visit_super) | |
133 : _class(cls), _super_was_visited(!visit_super), | |
134 _interface_index(0), _algorithm_data(data) {} | |
135 | |
136 int number_of_interfaces() { return _class->local_interfaces()->length(); } | |
137 int interface_index() { return _interface_index; } | |
138 void set_super_visited() { _super_was_visited = true; } | |
139 void increment_visited_interface() { ++_interface_index; } | |
140 void set_all_interfaces_visited() { | |
141 _interface_index = number_of_interfaces(); | |
142 } | |
143 bool has_visited_super() { return _super_was_visited; } | |
144 bool has_visited_all_interfaces() { | |
145 return interface_index() >= number_of_interfaces(); | |
146 } | |
147 InstanceKlass* interface_at(int index) { | |
148 return InstanceKlass::cast(_class->local_interfaces()->at(index)); | |
149 } | |
150 InstanceKlass* next_super() { return _class->java_super(); } | |
151 InstanceKlass* next_interface() { | |
152 return interface_at(interface_index()); | |
153 } | |
154 }; | |
155 | |
156 bool _cancelled; | |
157 GrowableArray<Node*> _path; | |
158 | |
159 Node* current_top() const { return _path.top(); } | |
160 bool has_more_nodes() const { return !_path.is_empty(); } | |
161 void push(InstanceKlass* cls, void* data) { | |
162 assert(cls != NULL, "Requires a valid instance class"); | |
163 Node* node = new Node(cls, data, has_super(cls)); | |
164 _path.push(node); | |
165 } | |
166 void pop() { _path.pop(); } | |
167 | |
168 void reset_iteration() { | |
169 _cancelled = false; | |
170 _path.clear(); | |
171 } | |
172 bool is_cancelled() const { return _cancelled; } | |
173 | |
174 static bool has_super(InstanceKlass* cls) { | |
175 return cls->super() != NULL && !cls->is_interface(); | |
176 } | |
177 | |
178 Node* node_at_depth(int i) const { | |
179 return (i >= _path.length()) ? NULL : _path.at(_path.length() - i - 1); | |
180 } | |
181 | |
182 protected: | |
183 | |
184 // Accessors available to the algorithm | |
185 int current_depth() const { return _path.length() - 1; } | |
186 | |
187 InstanceKlass* class_at_depth(int i) { | |
188 Node* n = node_at_depth(i); | |
189 return n == NULL ? NULL : n->_class; | |
190 } | |
191 InstanceKlass* current_class() { return class_at_depth(0); } | |
192 | |
193 void* data_at_depth(int i) { | |
194 Node* n = node_at_depth(i); | |
195 return n == NULL ? NULL : n->_algorithm_data; | |
196 } | |
197 void* current_data() { return data_at_depth(0); } | |
198 | |
199 void cancel_iteration() { _cancelled = true; } | |
200 | |
201 public: | |
202 | |
203 void run(InstanceKlass* root) { | |
204 ALGO* algo = static_cast<ALGO*>(this); | |
205 | |
206 reset_iteration(); | |
207 | |
208 void* algo_data = algo->new_node_data(root); | |
209 push(root, algo_data); | |
210 bool top_needs_visit = true; | |
211 | |
212 do { | |
213 Node* top = current_top(); | |
214 if (top_needs_visit) { | |
215 if (algo->visit() == false) { | |
216 // algorithm does not want to continue along this path. Arrange | |
217 // it so that this state is immediately popped off the stack | |
218 top->set_super_visited(); | |
219 top->set_all_interfaces_visited(); | |
220 } | |
221 top_needs_visit = false; | |
222 } | |
223 | |
224 if (top->has_visited_super() && top->has_visited_all_interfaces()) { | |
225 algo->free_node_data(top->_algorithm_data); | |
226 pop(); | |
227 } else { | |
228 InstanceKlass* next = NULL; | |
229 if (top->has_visited_super() == false) { | |
230 next = top->next_super(); | |
231 top->set_super_visited(); | |
232 } else { | |
233 next = top->next_interface(); | |
234 top->increment_visited_interface(); | |
235 } | |
236 assert(next != NULL, "Otherwise we shouldn't be here"); | |
237 algo_data = algo->new_node_data(next); | |
238 push(next, algo_data); | |
239 top_needs_visit = true; | |
240 } | |
241 } while (!is_cancelled() && has_more_nodes()); | |
242 } | |
243 }; | |
244 | |
245 #ifndef PRODUCT | |
246 class PrintHierarchy : public HierarchyVisitor<PrintHierarchy> { | |
247 public: | |
248 | |
249 bool visit() { | |
250 InstanceKlass* cls = current_class(); | |
251 streamIndentor si(tty, current_depth() * 2); | |
252 tty->indent().print_cr("%s", cls->name()->as_C_string()); | |
253 return true; | |
254 } | |
255 | |
256 void* new_node_data(InstanceKlass* cls) { return NULL; } | |
257 void free_node_data(void* data) { return; } | |
258 }; | |
259 #endif // ndef PRODUCT | |
260 | |
261 // Used to register InstanceKlass objects and all related metadata structures | |
262 // (Methods, ConstantPools) as "in-use" by the current thread so that they can't | |
263 // be deallocated by class redefinition while we're using them. The classes are | |
264 // de-registered when this goes out of scope. | |
265 // | |
266 // Once a class is registered, we need not bother with methodHandles or | |
267 // constantPoolHandles for it's associated metadata. | |
268 class KeepAliveRegistrar : public StackObj { | |
269 private: | |
270 Thread* _thread; | |
271 GrowableArray<ConstantPool*> _keep_alive; | |
272 | |
273 public: | |
274 KeepAliveRegistrar(Thread* thread) : _thread(thread), _keep_alive(20) { | |
275 assert(thread == Thread::current(), "Must be current thread"); | |
276 } | |
277 | |
278 ~KeepAliveRegistrar() { | |
279 for (int i = _keep_alive.length() - 1; i >= 0; --i) { | |
280 ConstantPool* cp = _keep_alive.at(i); | |
281 int idx = _thread->metadata_handles()->find_from_end(cp); | |
282 assert(idx > 0, "Must be in the list"); | |
283 _thread->metadata_handles()->remove_at(idx); | |
284 } | |
285 } | |
286 | |
287 // Register a class as 'in-use' by the thread. It's fine to register a class | |
288 // multiple times (though perhaps inefficient) | |
289 void register_class(InstanceKlass* ik) { | |
290 ConstantPool* cp = ik->constants(); | |
291 _keep_alive.push(cp); | |
292 _thread->metadata_handles()->push(cp); | |
293 } | |
294 }; | |
295 | |
296 class KeepAliveVisitor : public HierarchyVisitor<KeepAliveVisitor> { | |
297 private: | |
298 KeepAliveRegistrar* _registrar; | |
299 | |
300 public: | |
301 KeepAliveVisitor(KeepAliveRegistrar* registrar) : _registrar(registrar) {} | |
302 | |
303 void* new_node_data(InstanceKlass* cls) { return NULL; } | |
304 void free_node_data(void* data) { return; } | |
305 | |
306 bool visit() { | |
307 _registrar->register_class(current_class()); | |
308 return true; | |
309 } | |
310 }; | |
311 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
312 |
6934 | 313 // A method family contains a set of all methods that implement a single |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
314 // erased method. As members of the set are collected while walking over the |
6934 | 315 // hierarchy, they are tagged with a qualification state. The qualification |
316 // state for an erased method is set to disqualified if there exists a path | |
317 // from the root of hierarchy to the method that contains an interleaving | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
318 // erased method defined in an interface. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
319 |
6934 | 320 class MethodFamily : public ResourceObj { |
321 private: | |
322 | |
323 GrowableArray<Pair<Method*,QualifiedState> > _members; | |
324 ResourceHashtable<Method*, int> _member_index; | |
325 | |
326 Method* _selected_target; // Filled in later, if a unique target exists | |
327 Symbol* _exception_message; // If no unique target is found | |
328 | |
329 bool contains_method(Method* method) { | |
330 int* lookup = _member_index.get(method); | |
331 return lookup != NULL; | |
332 } | |
333 | |
334 void add_method(Method* method, QualifiedState state) { | |
335 Pair<Method*,QualifiedState> entry(method, state); | |
336 _member_index.put(method, _members.length()); | |
337 _members.append(entry); | |
338 } | |
339 | |
340 void disqualify_method(Method* method) { | |
341 int* index = _member_index.get(method); | |
8778
653d0346aa80
8009578: [parfait] Null pointer deference in hotspot/src/share/vm/classfile/defaultMethods.cpp
morris
parents:
8031
diff
changeset
|
342 guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); |
6934 | 343 _members.at(*index).second = DISQUALIFIED; |
344 } | |
345 | |
346 Symbol* generate_no_defaults_message(TRAPS) const; | |
347 Symbol* generate_abstract_method_message(Method* method, TRAPS) const; | |
348 Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const; | |
349 | |
350 public: | |
351 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
352 MethodFamily() |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
353 : _selected_target(NULL), _exception_message(NULL) {} |
6934 | 354 |
355 void set_target_if_empty(Method* m) { | |
356 if (_selected_target == NULL && !m->is_overpass()) { | |
357 _selected_target = m; | |
358 } | |
359 } | |
360 | |
361 void record_qualified_method(Method* m) { | |
362 // If the method already exists in the set as qualified, this operation is | |
363 // redundant. If it already exists as disqualified, then we leave it as | |
364 // disqualfied. Thus we only add to the set if it's not already in the | |
365 // set. | |
366 if (!contains_method(m)) { | |
367 add_method(m, QUALIFIED); | |
368 } | |
369 } | |
370 | |
371 void record_disqualified_method(Method* m) { | |
372 // If not in the set, add it as disqualified. If it's already in the set, | |
373 // then set the state to disqualified no matter what the previous state was. | |
374 if (!contains_method(m)) { | |
375 add_method(m, DISQUALIFIED); | |
376 } else { | |
377 disqualify_method(m); | |
378 } | |
379 } | |
380 | |
381 bool has_target() const { return _selected_target != NULL; } | |
382 bool throws_exception() { return _exception_message != NULL; } | |
383 | |
384 Method* get_selected_target() { return _selected_target; } | |
385 Symbol* get_exception_message() { return _exception_message; } | |
386 | |
387 // Either sets the target or the exception error message | |
388 void determine_target(InstanceKlass* root, TRAPS) { | |
389 if (has_target() || throws_exception()) { | |
390 return; | |
391 } | |
392 | |
393 GrowableArray<Method*> qualified_methods; | |
394 for (int i = 0; i < _members.length(); ++i) { | |
395 Pair<Method*,QualifiedState> entry = _members.at(i); | |
396 if (entry.second == QUALIFIED) { | |
397 qualified_methods.append(entry.first); | |
398 } | |
399 } | |
400 | |
401 if (qualified_methods.length() == 0) { | |
402 _exception_message = generate_no_defaults_message(CHECK); | |
403 } else if (qualified_methods.length() == 1) { | |
404 Method* method = qualified_methods.at(0); | |
405 if (method->is_abstract()) { | |
406 _exception_message = generate_abstract_method_message(method, CHECK); | |
407 } else { | |
408 _selected_target = qualified_methods.at(0); | |
409 } | |
410 } else { | |
411 _exception_message = generate_conflicts_message(&qualified_methods,CHECK); | |
412 } | |
413 | |
414 assert((has_target() ^ throws_exception()) == 1, | |
415 "One and only one must be true"); | |
416 } | |
417 | |
418 bool contains_signature(Symbol* query) { | |
419 for (int i = 0; i < _members.length(); ++i) { | |
420 if (query == _members.at(i).first->signature()) { | |
421 return true; | |
422 } | |
423 } | |
424 return false; | |
425 } | |
426 | |
427 #ifndef PRODUCT | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
428 void print_sig_on(outputStream* str, Symbol* signature, int indent) const { |
6934 | 429 streamIndentor si(str, indent * 2); |
430 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
431 str->indent().print_cr("Logical Method %s:", signature->as_C_string()); |
6934 | 432 |
433 streamIndentor si2(str); | |
434 for (int i = 0; i < _members.length(); ++i) { | |
435 str->indent(); | |
436 print_method(str, _members.at(i).first); | |
437 if (_members.at(i).second == DISQUALIFIED) { | |
438 str->print(" (disqualified)"); | |
439 } | |
440 str->print_cr(""); | |
441 } | |
442 | |
443 if (_selected_target != NULL) { | |
444 print_selected(str, 1); | |
445 } | |
446 } | |
447 | |
448 void print_selected(outputStream* str, int indent) const { | |
449 assert(has_target(), "Should be called otherwise"); | |
450 streamIndentor si(str, indent * 2); | |
451 str->indent().print("Selected method: "); | |
452 print_method(str, _selected_target); | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
453 Klass* method_holder = _selected_target->method_holder(); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
454 if (!method_holder->is_interface()) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
455 tty->print(" : in superclass"); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
456 } |
6934 | 457 str->print_cr(""); |
458 } | |
459 | |
460 void print_exception(outputStream* str, int indent) { | |
461 assert(throws_exception(), "Should be called otherwise"); | |
462 streamIndentor si(str, indent * 2); | |
463 str->indent().print_cr("%s", _exception_message->as_C_string()); | |
464 } | |
465 #endif // ndef PRODUCT | |
466 }; | |
467 | |
468 Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { | |
469 return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL); | |
470 } | |
471 | |
472 Symbol* MethodFamily::generate_abstract_method_message(Method* method, TRAPS) const { | |
473 Symbol* klass = method->klass_name(); | |
474 Symbol* name = method->name(); | |
475 Symbol* sig = method->signature(); | |
476 stringStream ss; | |
477 ss.print("Method "); | |
478 ss.write((const char*)klass->bytes(), klass->utf8_length()); | |
479 ss.print("."); | |
480 ss.write((const char*)name->bytes(), name->utf8_length()); | |
481 ss.write((const char*)sig->bytes(), sig->utf8_length()); | |
482 ss.print(" is abstract"); | |
483 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); | |
484 } | |
485 | |
486 Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { | |
487 stringStream ss; | |
488 ss.print("Conflicting default methods:"); | |
489 for (int i = 0; i < methods->length(); ++i) { | |
490 Method* method = methods->at(i); | |
491 Symbol* klass = method->klass_name(); | |
492 Symbol* name = method->name(); | |
493 ss.print(" "); | |
494 ss.write((const char*)klass->bytes(), klass->utf8_length()); | |
495 ss.print("."); | |
496 ss.write((const char*)name->bytes(), name->utf8_length()); | |
497 } | |
498 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); | |
499 } | |
500 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
501 |
6934 | 502 class StateRestorer; |
503 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
504 // StatefulMethodFamily is a wrapper around a MethodFamily that maintains the |
6934 | 505 // qualification state during hierarchy visitation, and applies that state |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
506 // when adding members to the MethodFamily |
6934 | 507 class StatefulMethodFamily : public ResourceObj { |
508 friend class StateRestorer; | |
509 private: | |
510 QualifiedState _qualification_state; | |
511 | |
512 void set_qualification_state(QualifiedState state) { | |
513 _qualification_state = state; | |
514 } | |
515 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
516 protected: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
517 MethodFamily* _method_family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
518 |
6934 | 519 public: |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
520 StatefulMethodFamily() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
521 _method_family = new MethodFamily(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
522 _qualification_state = QUALIFIED; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
523 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
524 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
525 StatefulMethodFamily(MethodFamily* mf) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
526 _method_family = mf; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
527 _qualification_state = QUALIFIED; |
6934 | 528 } |
529 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
530 void set_target_if_empty(Method* m) { _method_family->set_target_if_empty(m); } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
531 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
532 MethodFamily* get_method_family() { return _method_family; } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
533 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
534 StateRestorer* record_method_and_dq_further(Method* mo); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
535 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
536 |
6934 | 537 class StateRestorer : public PseudoScopeMark { |
538 private: | |
539 StatefulMethodFamily* _method; | |
540 QualifiedState _state_to_restore; | |
541 public: | |
542 StateRestorer(StatefulMethodFamily* dm, QualifiedState state) | |
543 : _method(dm), _state_to_restore(state) {} | |
544 ~StateRestorer() { destroy(); } | |
545 void restore_state() { _method->set_qualification_state(_state_to_restore); } | |
546 virtual void destroy() { restore_state(); } | |
547 }; | |
548 | |
549 StateRestorer* StatefulMethodFamily::record_method_and_dq_further(Method* mo) { | |
550 StateRestorer* mark = new StateRestorer(this, _qualification_state); | |
551 if (_qualification_state == QUALIFIED) { | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
552 _method_family->record_qualified_method(mo); |
6934 | 553 } else { |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
554 _method_family->record_disqualified_method(mo); |
6934 | 555 } |
556 // Everything found "above"??? this method in the hierarchy walk is set to | |
557 // disqualified | |
558 set_qualification_state(DISQUALIFIED); | |
559 return mark; | |
560 } | |
561 | |
562 // Represents a location corresponding to a vtable slot for methods that | |
563 // neither the class nor any of it's ancestors provide an implementaion. | |
564 // Default methods may be present to fill this slot. | |
565 class EmptyVtableSlot : public ResourceObj { | |
566 private: | |
567 Symbol* _name; | |
568 Symbol* _signature; | |
569 int _size_of_parameters; | |
570 MethodFamily* _binding; | |
571 | |
572 public: | |
573 EmptyVtableSlot(Method* method) | |
574 : _name(method->name()), _signature(method->signature()), | |
575 _size_of_parameters(method->size_of_parameters()), _binding(NULL) {} | |
576 | |
577 Symbol* name() const { return _name; } | |
578 Symbol* signature() const { return _signature; } | |
579 int size_of_parameters() const { return _size_of_parameters; } | |
580 | |
581 void bind_family(MethodFamily* lm) { _binding = lm; } | |
582 bool is_bound() { return _binding != NULL; } | |
583 MethodFamily* get_binding() { return _binding; } | |
584 | |
585 #ifndef PRODUCT | |
586 void print_on(outputStream* str) const { | |
587 print_slot(str, name(), signature()); | |
588 } | |
589 #endif // ndef PRODUCT | |
590 }; | |
591 | |
592 static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( | |
593 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { | |
594 | |
595 assert(klass != NULL, "Must be valid class"); | |
596 | |
597 GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); | |
598 | |
599 // All miranda methods are obvious candidates | |
600 for (int i = 0; i < mirandas->length(); ++i) { | |
601 EmptyVtableSlot* slot = new EmptyVtableSlot(mirandas->at(i)); | |
602 slots->append(slot); | |
603 } | |
604 | |
605 // Also any overpasses in our superclasses, that we haven't implemented. | |
606 // (can't use the vtable because it is not guaranteed to be initialized yet) | |
607 InstanceKlass* super = klass->java_super(); | |
608 while (super != NULL) { | |
609 for (int i = 0; i < super->methods()->length(); ++i) { | |
610 Method* m = super->methods()->at(i); | |
611 if (m->is_overpass()) { | |
612 // m is a method that would have been a miranda if not for the | |
613 // default method processing that occurred on behalf of our superclass, | |
614 // so it's a method we want to re-examine in this new context. That is, | |
615 // unless we have a real implementation of it in the current class. | |
616 Method* impl = klass->lookup_method(m->name(), m->signature()); | |
617 if (impl == NULL || impl->is_overpass()) { | |
618 slots->append(new EmptyVtableSlot(m)); | |
619 } | |
620 } | |
621 } | |
622 super = super->java_super(); | |
623 } | |
624 | |
625 #ifndef PRODUCT | |
626 if (TraceDefaultMethods) { | |
627 tty->print_cr("Slots that need filling:"); | |
628 streamIndentor si(tty); | |
629 for (int i = 0; i < slots->length(); ++i) { | |
630 tty->indent(); | |
631 slots->at(i)->print_on(tty); | |
632 tty->print_cr(""); | |
633 } | |
634 } | |
635 #endif // ndef PRODUCT | |
636 return slots; | |
637 } | |
638 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
639 // Iterates over the superinterface type hierarchy looking for all methods |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
640 // with a specific erased signature. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
641 class FindMethodsByErasedSig : public HierarchyVisitor<FindMethodsByErasedSig> { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
642 private: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
643 // Context data |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
644 Symbol* _method_name; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
645 Symbol* _method_signature; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
646 StatefulMethodFamily* _family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
647 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
648 public: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
649 FindMethodsByErasedSig(Symbol* name, Symbol* signature) : |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
650 _method_name(name), _method_signature(signature), |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
651 _family(NULL) {} |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
652 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
653 void get_discovered_family(MethodFamily** family) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
654 if (_family != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
655 *family = _family->get_method_family(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
656 } else { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
657 *family = NULL; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
658 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
659 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
660 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
661 void* new_node_data(InstanceKlass* cls) { return new PseudoScope(); } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
662 void free_node_data(void* node_data) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
663 PseudoScope::cast(node_data)->destroy(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
664 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
665 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
666 // Find all methods on this hierarchy that match this |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
667 // method's erased (name, signature) |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
668 bool visit() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
669 PseudoScope* scope = PseudoScope::cast(current_data()); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
670 InstanceKlass* iklass = current_class(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
671 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
672 Method* m = iklass->find_method(_method_name, _method_signature); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
673 if (m != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
674 if (_family == NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
675 _family = new StatefulMethodFamily(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
676 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
677 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
678 if (iklass->is_interface()) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
679 StateRestorer* restorer = _family->record_method_and_dq_further(m); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
680 scope->add_mark(restorer); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
681 } else { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
682 // This is the rule that methods in classes "win" (bad word) over |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
683 // methods in interfaces. This works because of single inheritance |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
684 _family->set_target_if_empty(m); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
685 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
686 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
687 return true; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
688 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
689 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
690 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
691 |
6934 | 692 |
693 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
694 static void create_overpasses( |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
695 GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
696 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
697 static void generate_erased_defaults( |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
698 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
699 EmptyVtableSlot* slot, TRAPS) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
700 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
701 // sets up a set of methods with the same exact erased signature |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
702 FindMethodsByErasedSig visitor(slot->name(), slot->signature()); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
703 visitor.run(klass); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
704 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
705 MethodFamily* family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
706 visitor.get_discovered_family(&family); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
707 if (family != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
708 family->determine_target(klass, CHECK); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
709 slot->bind_family(family); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
710 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
711 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
712 |
6934 | 713 static void merge_in_new_methods(InstanceKlass* klass, |
714 GrowableArray<Method*>* new_methods, TRAPS); | |
715 | |
716 // This is the guts of the default methods implementation. This is called just | |
717 // after the classfile has been parsed if some ancestor has default methods. | |
718 // | |
719 // First if finds any name/signature slots that need any implementation (either | |
720 // because they are miranda or a superclass's implementation is an overpass | |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
721 // itself). For each slot, iterate over the hierarchy, to see if they contain a |
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
722 // signature that matches the slot we are looking at. |
6934 | 723 // |
724 // For each slot filled, we generate an overpass method that either calls the | |
725 // unique default method candidate using invokespecial, or throws an exception | |
726 // (in the case of no default method candidates, or more than one valid | |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
727 // candidate). These methods are then added to the class's method list. |
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
728 // The JVM does not create bridges nor handle generic signatures here. |
6934 | 729 void DefaultMethods::generate_default_methods( |
730 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { | |
731 | |
732 // This resource mark is the bound for all memory allocation that takes | |
733 // place during default method processing. After this goes out of scope, | |
734 // all (Resource) objects' memory will be reclaimed. Be careful if adding an | |
735 // embedded resource mark under here as that memory can't be used outside | |
736 // whatever scope it's in. | |
737 ResourceMark rm(THREAD); | |
738 | |
739 // Keep entire hierarchy alive for the duration of the computation | |
740 KeepAliveRegistrar keepAlive(THREAD); | |
741 KeepAliveVisitor loadKeepAlive(&keepAlive); | |
742 loadKeepAlive.run(klass); | |
743 | |
744 #ifndef PRODUCT | |
745 if (TraceDefaultMethods) { | |
746 ResourceMark rm; // be careful with these! | |
747 tty->print_cr("Class %s requires default method processing", | |
748 klass->name()->as_klass_external_name()); | |
749 PrintHierarchy printer; | |
750 printer.run(klass); | |
751 } | |
752 #endif // ndef PRODUCT | |
753 | |
754 GrowableArray<EmptyVtableSlot*>* empty_slots = | |
755 find_empty_vtable_slots(klass, mirandas, CHECK); | |
756 | |
757 for (int i = 0; i < empty_slots->length(); ++i) { | |
758 EmptyVtableSlot* slot = empty_slots->at(i); | |
759 #ifndef PRODUCT | |
760 if (TraceDefaultMethods) { | |
761 streamIndentor si(tty, 2); | |
762 tty->indent().print("Looking for default methods for slot "); | |
763 slot->print_on(tty); | |
764 tty->print_cr(""); | |
765 } | |
766 #endif // ndef PRODUCT | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
767 |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
768 generate_erased_defaults(klass, empty_slots, slot, CHECK); |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
769 } |
6934 | 770 #ifndef PRODUCT |
771 if (TraceDefaultMethods) { | |
772 tty->print_cr("Creating overpasses..."); | |
773 } | |
774 #endif // ndef PRODUCT | |
775 | |
776 create_overpasses(empty_slots, klass, CHECK); | |
777 | |
778 #ifndef PRODUCT | |
779 if (TraceDefaultMethods) { | |
780 tty->print_cr("Default method processing complete"); | |
781 } | |
782 #endif // ndef PRODUCT | |
783 } | |
784 | |
785 /** | |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
786 * Interface inheritance rules were used to find a unique default method |
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
787 * candidate for the resolved class. This |
6934 | 788 * method is only viable if it would also be in the set of default method |
789 * candidates if we ran a full analysis on the current class. | |
790 * | |
791 * The only reason that the method would not be in the set of candidates for | |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
792 * the current class is if that there's another matching method |
6934 | 793 * which is "more specific" than the found method -- i.e., one could find a |
794 * path in the interface hierarchy in which the matching method appears | |
795 * before we get to '_target'. | |
796 * | |
797 * In order to determine this, we examine all of the implemented | |
798 * interfaces. If we find path that leads to the '_target' interface, then | |
799 * we examine that path to see if there are any methods that would shadow | |
800 * the selected method along that path. | |
801 */ | |
802 class ShadowChecker : public HierarchyVisitor<ShadowChecker> { | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
803 protected: |
6934 | 804 Thread* THREAD; |
805 | |
806 InstanceKlass* _target; | |
807 | |
808 Symbol* _method_name; | |
809 InstanceKlass* _method_holder; | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
810 bool _found_shadow; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
811 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
812 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
813 public: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
814 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
815 ShadowChecker(Thread* thread, Symbol* name, InstanceKlass* holder, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
816 InstanceKlass* target) |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
817 : THREAD(thread), _method_name(name), _method_holder(holder), |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
818 _target(target), _found_shadow(false) {} |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
819 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
820 void* new_node_data(InstanceKlass* cls) { return NULL; } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
821 void free_node_data(void* data) { return; } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
822 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
823 bool visit() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
824 InstanceKlass* ik = current_class(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
825 if (ik == _target && current_depth() == 1) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
826 return false; // This was the specified super -- no need to search it |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
827 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
828 if (ik == _method_holder || ik == _target) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
829 // We found a path that should be examined to see if it shadows _method |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
830 if (path_has_shadow()) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
831 _found_shadow = true; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
832 cancel_iteration(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
833 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
834 return false; // no need to continue up hierarchy |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
835 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
836 return true; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
837 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
838 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
839 virtual bool path_has_shadow() = 0; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
840 bool found_shadow() { return _found_shadow; } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
841 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
842 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
843 // Used for Invokespecial. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
844 // Invokespecial is allowed to invoke a concrete interface method |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
845 // and can be used to disambuiguate among qualified candidates, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
846 // which are methods in immediate superinterfaces, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
847 // but may not be used to invoke a candidate that would be shadowed |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
848 // from the perspective of the caller. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
849 // Invokespecial is also used in the overpass generation today |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
850 // We re-run the shadowchecker because we can't distinguish this case, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
851 // but it should return the same answer, since the overpass target |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
852 // is now the invokespecial caller. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
853 class ErasedShadowChecker : public ShadowChecker { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
854 private: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
855 bool path_has_shadow() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
856 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
857 for (int i = current_depth() - 1; i > 0; --i) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
858 InstanceKlass* ik = class_at_depth(i); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
859 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
860 if (ik->is_interface()) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
861 int end; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
862 int start = ik->find_method_by_name(_method_name, &end); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
863 if (start != -1) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
864 return true; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
865 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
866 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
867 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
868 return false; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
869 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
870 public: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
871 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
872 ErasedShadowChecker(Thread* thread, Symbol* name, InstanceKlass* holder, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
873 InstanceKlass* target) |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
874 : ShadowChecker(thread, name, holder, target) {} |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
875 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
876 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
877 // Find the unique qualified candidate from the perspective of the super_class |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
878 // which is the resolved_klass, which must be an immediate superinterface |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
879 // of klass |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
880 Method* find_erased_super_default(InstanceKlass* current_class, InstanceKlass* super_class, Symbol* method_name, Symbol* sig, TRAPS) { |
6934 | 881 |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
882 FindMethodsByErasedSig visitor(method_name, sig); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
883 visitor.run(super_class); // find candidates from resolved_klass |
6934 | 884 |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
885 MethodFamily* family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
886 visitor.get_discovered_family(&family); |
6934 | 887 |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
888 if (family != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
889 family->determine_target(current_class, CHECK_NULL); // get target from current_class |
6934 | 890 |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
891 if (family->has_target()) { |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
892 Method* target = family->get_selected_target(); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
893 InstanceKlass* holder = InstanceKlass::cast(target->method_holder()); |
6934 | 894 |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
895 // Verify that the identified method is valid from the context of |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
896 // the current class, which is the caller class for invokespecial |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
897 // link resolution, i.e. ensure there it is not shadowed. |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
898 // You can use invokespecial to disambiguate interface methods, but |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
899 // you can not use it to skip over an interface method that would shadow it. |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
900 ErasedShadowChecker checker(THREAD, target->name(), holder, super_class); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
901 checker.run(current_class); |
6934 | 902 |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
903 if (checker.found_shadow()) { |
6934 | 904 #ifndef PRODUCT |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
905 if (TraceDefaultMethods) { |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
906 tty->print_cr(" Only candidate found was shadowed."); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
907 } |
6934 | 908 #endif // ndef PRODUCT |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
909 THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(), |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
910 "Accessible default method not found", NULL); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
911 } else { |
6934 | 912 #ifndef PRODUCT |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
913 if (TraceDefaultMethods) { |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
914 family->print_sig_on(tty, target->signature(), 1); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
915 } |
6934 | 916 #endif // ndef PRODUCT |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
917 return target; |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
918 } |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
919 } else { |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
920 assert(family->throws_exception(), "must have target or throw"); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
921 THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(), |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
922 family->get_exception_message()->as_C_string(), NULL); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
923 } |
6934 | 924 } else { |
12140
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
925 // no method found |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
926 ResourceMark rm(THREAD); |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
927 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
928 Method::name_and_sig_as_C_string(current_class, |
915cc4f3fb15
8020489: VM crash when non-existent interface called by invokespecial
acorn
parents:
12131
diff
changeset
|
929 method_name, sig), NULL); |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
930 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
931 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
932 // This is called during linktime when we find an invokespecial call that |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
933 // refers to a direct superinterface. It indicates that we should find the |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
934 // default method in the hierarchy of that superinterface, and if that method |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
935 // would have been a candidate from the point of view of 'this' class, then we |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
936 // return that method. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
937 // This logic assumes that the super is a direct superclass of the caller |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
938 Method* DefaultMethods::find_super_default( |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
939 Klass* cls, Klass* super, Symbol* method_name, Symbol* sig, TRAPS) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
940 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
941 ResourceMark rm(THREAD); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
942 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
943 assert(cls != NULL && super != NULL, "Need real classes"); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
944 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
945 InstanceKlass* current_class = InstanceKlass::cast(cls); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
946 InstanceKlass* super_class = InstanceKlass::cast(super); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
947 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
948 // Keep entire hierarchy alive for the duration of the computation |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
949 KeepAliveRegistrar keepAlive(THREAD); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
950 KeepAliveVisitor loadKeepAlive(&keepAlive); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
951 loadKeepAlive.run(current_class); // get hierarchy from current class |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
952 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
953 #ifndef PRODUCT |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
954 if (TraceDefaultMethods) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
955 tty->print_cr("Finding super default method %s.%s%s from %s", |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
956 super_class->name()->as_C_string(), |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
957 method_name->as_C_string(), sig->as_C_string(), |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
958 current_class->name()->as_C_string()); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
959 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
960 #endif // ndef PRODUCT |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
961 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
962 assert(super_class->is_interface(), "only call for default methods"); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
963 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
964 Method* target = NULL; |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
965 target = find_erased_super_default(current_class, super_class, |
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
966 method_name, sig, CHECK_NULL); |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
967 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
968 #ifndef PRODUCT |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
969 if (target != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
970 if (TraceDefaultMethods) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
971 tty->print(" Returning "); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
972 print_method(tty, target, true); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
973 tty->print_cr(""); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
974 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
975 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
976 #endif // ndef PRODUCT |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
977 return target; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
978 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
979 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
980 #ifndef PRODUCT |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
981 // Return true is broad type is a covariant return of narrow type |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
982 static bool covariant_return_type(BasicType narrow, BasicType broad) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
983 if (narrow == broad) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
984 return true; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
985 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
986 if (broad == T_OBJECT) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
987 return true; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
988 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
989 return false; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
990 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
991 #endif // ndef PRODUCT |
6934 | 992 |
993 static int assemble_redirect( | |
994 BytecodeConstantPool* cp, BytecodeBuffer* buffer, | |
995 Symbol* incoming, Method* target, TRAPS) { | |
996 | |
997 BytecodeAssembler assem(buffer, cp); | |
998 | |
999 SignatureStream in(incoming, true); | |
1000 SignatureStream out(target->signature(), true); | |
1001 u2 parameter_count = 0; | |
1002 | |
1003 assem.aload(parameter_count++); // load 'this' | |
1004 | |
1005 while (!in.at_return_type()) { | |
1006 assert(!out.at_return_type(), "Parameter counts do not match"); | |
1007 BasicType bt = in.type(); | |
1008 assert(out.type() == bt, "Parameter types are not compatible"); | |
1009 assem.load(bt, parameter_count); | |
1010 if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) { | |
1011 assem.checkcast(out.as_symbol(THREAD)); | |
1012 } else if (bt == T_LONG || bt == T_DOUBLE) { | |
1013 ++parameter_count; // longs and doubles use two slots | |
1014 } | |
1015 ++parameter_count; | |
1016 in.next(); | |
1017 out.next(); | |
1018 } | |
1019 assert(out.at_return_type(), "Parameter counts do not match"); | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1020 assert(covariant_return_type(out.type(), in.type()), "Return types are not compatible"); |
6934 | 1021 |
1022 if (parameter_count == 1 && (in.type() == T_LONG || in.type() == T_DOUBLE)) { | |
1023 ++parameter_count; // need room for return value | |
1024 } | |
1025 if (target->method_holder()->is_interface()) { | |
1026 assem.invokespecial(target); | |
1027 } else { | |
1028 assem.invokevirtual(target); | |
1029 } | |
1030 | |
1031 if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) { | |
1032 assem.checkcast(in.as_symbol(THREAD)); | |
1033 } | |
1034 assem._return(in.type()); | |
1035 return parameter_count; | |
1036 } | |
1037 | |
1038 static int assemble_abstract_method_error( | |
1039 BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* message, TRAPS) { | |
1040 | |
1041 Symbol* errorName = vmSymbols::java_lang_AbstractMethodError(); | |
1042 Symbol* init = vmSymbols::object_initializer_name(); | |
1043 Symbol* sig = vmSymbols::string_void_signature(); | |
1044 | |
1045 BytecodeAssembler assem(buffer, cp); | |
1046 | |
1047 assem._new(errorName); | |
1048 assem.dup(); | |
1049 assem.load_string(message); | |
1050 assem.invokespecial(errorName, init, sig); | |
1051 assem.athrow(); | |
1052 | |
1053 return 3; // max stack size: [ exception, exception, string ] | |
1054 } | |
1055 | |
1056 static Method* new_method( | |
1057 BytecodeConstantPool* cp, BytecodeBuffer* bytecodes, Symbol* name, | |
1058 Symbol* sig, AccessFlags flags, int max_stack, int params, | |
1059 ConstMethod::MethodType mt, TRAPS) { | |
1060 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1061 address code_start = 0; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1062 int code_length = 0; |
8031 | 1063 InlineTableSizes sizes; |
6934 | 1064 |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1065 if (bytecodes != NULL && bytecodes->length() > 0) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1066 code_start = static_cast<address>(bytecodes->adr_at(0)); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1067 code_length = bytecodes->length(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1068 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
1069 |
6934 | 1070 Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), |
8031 | 1071 code_length, flags, &sizes, |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7183
diff
changeset
|
1072 mt, CHECK_NULL); |
6934 | 1073 |
1074 m->set_constants(NULL); // This will get filled in later | |
1075 m->set_name_index(cp->utf8(name)); | |
1076 m->set_signature_index(cp->utf8(sig)); | |
1077 #ifdef CC_INTERP | |
1078 ResultTypeFinder rtf(sig); | |
1079 m->set_result_index(rtf.type()); | |
1080 #endif | |
1081 m->set_size_of_parameters(params); | |
1082 m->set_max_stack(max_stack); | |
1083 m->set_max_locals(params); | |
1084 m->constMethod()->set_stackmap_data(NULL); | |
1085 m->set_code(code_start); | |
1086 m->set_force_inline(true); | |
1087 | |
1088 return m; | |
1089 } | |
1090 | |
1091 static void switchover_constant_pool(BytecodeConstantPool* bpool, | |
1092 InstanceKlass* klass, GrowableArray<Method*>* new_methods, TRAPS) { | |
1093 | |
1094 if (new_methods->length() > 0) { | |
1095 ConstantPool* cp = bpool->create_constant_pool(CHECK); | |
1096 if (cp != klass->constants()) { | |
1097 klass->class_loader_data()->add_to_deallocate_list(klass->constants()); | |
1098 klass->set_constants(cp); | |
1099 cp->set_pool_holder(klass); | |
1100 | |
1101 for (int i = 0; i < new_methods->length(); ++i) { | |
1102 new_methods->at(i)->set_constants(cp); | |
1103 } | |
1104 for (int i = 0; i < klass->methods()->length(); ++i) { | |
1105 Method* mo = klass->methods()->at(i); | |
1106 mo->set_constants(cp); | |
1107 } | |
1108 } | |
1109 } | |
1110 } | |
1111 | |
1112 // A "bridge" is a method created by javac to bridge the gap between | |
1113 // an implementation and a generically-compatible, but different, signature. | |
1114 // Bridges have actual bytecode implementation in classfiles. | |
1115 // An "overpass", on the other hand, performs the same function as a bridge | |
1116 // but does not occur in a classfile; the VM creates overpass itself, | |
1117 // when it needs a path to get from a call site to an default method, and | |
1118 // a bridge doesn't exist. | |
1119 static void create_overpasses( | |
1120 GrowableArray<EmptyVtableSlot*>* slots, | |
1121 InstanceKlass* klass, TRAPS) { | |
1122 | |
1123 GrowableArray<Method*> overpasses; | |
1124 BytecodeConstantPool bpool(klass->constants()); | |
1125 | |
1126 for (int i = 0; i < slots->length(); ++i) { | |
1127 EmptyVtableSlot* slot = slots->at(i); | |
1128 | |
1129 if (slot->is_bound()) { | |
1130 MethodFamily* method = slot->get_binding(); | |
1131 int max_stack = 0; | |
1132 BytecodeBuffer buffer; | |
1133 | |
1134 #ifndef PRODUCT | |
1135 if (TraceDefaultMethods) { | |
1136 tty->print("for slot: "); | |
1137 slot->print_on(tty); | |
1138 tty->print_cr(""); | |
1139 if (method->has_target()) { | |
1140 method->print_selected(tty, 1); | |
1141 } else { | |
1142 method->print_exception(tty, 1); | |
1143 } | |
1144 } | |
1145 #endif // ndef PRODUCT | |
1146 if (method->has_target()) { | |
1147 Method* selected = method->get_selected_target(); | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1148 if (selected->method_holder()->is_interface()) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1149 max_stack = assemble_redirect( |
6934 | 1150 &bpool, &buffer, slot->signature(), selected, CHECK); |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1151 } |
6934 | 1152 } else if (method->throws_exception()) { |
1153 max_stack = assemble_abstract_method_error( | |
1154 &bpool, &buffer, method->get_exception_message(), CHECK); | |
1155 } | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1156 if (max_stack != 0) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1157 AccessFlags flags = accessFlags_from( |
6934 | 1158 JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1159 Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), |
6934 | 1160 flags, max_stack, slot->size_of_parameters(), |
1161 ConstMethod::OVERPASS, CHECK); | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1162 if (m != NULL) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1163 overpasses.push(m); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
1164 } |
6934 | 1165 } |
1166 } | |
1167 } | |
1168 | |
1169 #ifndef PRODUCT | |
1170 if (TraceDefaultMethods) { | |
1171 tty->print_cr("Created %d overpass methods", overpasses.length()); | |
1172 } | |
1173 #endif // ndef PRODUCT | |
1174 | |
1175 switchover_constant_pool(&bpool, klass, &overpasses, CHECK); | |
1176 merge_in_new_methods(klass, &overpasses, CHECK); | |
1177 } | |
1178 | |
1179 static void sort_methods(GrowableArray<Method*>* methods) { | |
1180 // Note that this must sort using the same key as is used for sorting | |
1181 // methods in InstanceKlass. | |
1182 bool sorted = true; | |
1183 for (int i = methods->length() - 1; i > 0; --i) { | |
1184 for (int j = 0; j < i; ++j) { | |
1185 Method* m1 = methods->at(j); | |
1186 Method* m2 = methods->at(j + 1); | |
1187 if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) { | |
1188 methods->at_put(j, m2); | |
1189 methods->at_put(j + 1, m1); | |
1190 sorted = false; | |
1191 } | |
1192 } | |
1193 if (sorted) break; | |
1194 sorted = true; | |
1195 } | |
1196 #ifdef ASSERT | |
1197 uintptr_t prev = 0; | |
1198 for (int i = 0; i < methods->length(); ++i) { | |
1199 Method* mh = methods->at(i); | |
1200 uintptr_t nv = (uintptr_t)mh->name(); | |
1201 assert(nv >= prev, "Incorrect overpass method ordering"); | |
1202 prev = nv; | |
1203 } | |
1204 #endif | |
1205 } | |
1206 | |
1207 static void merge_in_new_methods(InstanceKlass* klass, | |
1208 GrowableArray<Method*>* new_methods, TRAPS) { | |
1209 | |
1210 enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS }; | |
1211 | |
1212 Array<Method*>* original_methods = klass->methods(); | |
1213 Array<int>* original_ordering = klass->method_ordering(); | |
1214 Array<int>* merged_ordering = Universe::the_empty_int_array(); | |
1215 | |
1216 int new_size = klass->methods()->length() + new_methods->length(); | |
1217 | |
1218 Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>( | |
1219 klass->class_loader_data(), new_size, NULL, CHECK); | |
8031 | 1220 |
6934 | 1221 if (original_ordering != NULL && original_ordering->length() > 0) { |
1222 merged_ordering = MetadataFactory::new_array<int>( | |
1223 klass->class_loader_data(), new_size, CHECK); | |
1224 } | |
1225 int method_order_index = klass->methods()->length(); | |
1226 | |
1227 sort_methods(new_methods); | |
1228 | |
1229 // Perform grand merge of existing methods and new methods | |
1230 int orig_idx = 0; | |
1231 int new_idx = 0; | |
1232 | |
1233 for (int i = 0; i < new_size; ++i) { | |
1234 Method* orig_method = NULL; | |
1235 Method* new_method = NULL; | |
1236 if (orig_idx < original_methods->length()) { | |
1237 orig_method = original_methods->at(orig_idx); | |
1238 } | |
1239 if (new_idx < new_methods->length()) { | |
1240 new_method = new_methods->at(new_idx); | |
1241 } | |
1242 | |
1243 if (orig_method != NULL && | |
1244 (new_method == NULL || orig_method->name() < new_method->name())) { | |
1245 merged_methods->at_put(i, orig_method); | |
1246 original_methods->at_put(orig_idx, NULL); | |
1247 if (merged_ordering->length() > 0) { | |
1248 merged_ordering->at_put(i, original_ordering->at(orig_idx)); | |
1249 } | |
1250 ++orig_idx; | |
1251 } else { | |
1252 merged_methods->at_put(i, new_method); | |
1253 if (merged_ordering->length() > 0) { | |
1254 merged_ordering->at_put(i, method_order_index++); | |
1255 } | |
1256 ++new_idx; | |
1257 } | |
1258 // update idnum for new location | |
1259 merged_methods->at(i)->set_method_idnum(i); | |
1260 } | |
1261 | |
1262 // Verify correct order | |
1263 #ifdef ASSERT | |
1264 uintptr_t prev = 0; | |
1265 for (int i = 0; i < merged_methods->length(); ++i) { | |
1266 Method* mo = merged_methods->at(i); | |
1267 uintptr_t nv = (uintptr_t)mo->name(); | |
1268 assert(nv >= prev, "Incorrect method ordering"); | |
1269 prev = nv; | |
1270 } | |
1271 #endif | |
1272 | |
1273 // Replace klass methods with new merged lists | |
1274 klass->set_methods(merged_methods); | |
10377
fe00365c8f31
8015436: compiler/ciReplay/TestSA.sh fails with assert() index is out of bounds
sspitsyn
parents:
8778
diff
changeset
|
1275 klass->set_initial_method_idnum(new_size); |
6934 | 1276 |
1277 ClassLoaderData* cld = klass->class_loader_data(); | |
1278 MetadataFactory::free_array(cld, original_methods); | |
1279 if (original_ordering->length() > 0) { | |
1280 klass->set_method_ordering(merged_ordering); | |
1281 MetadataFactory::free_array(cld, original_ordering); | |
1282 } | |
1283 } | |
1284 |