Mercurial > hg > graal-jvmci-8
annotate src/share/vm/classfile/defaultMethods.cpp @ 22672:1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Thu, 08 Oct 2015 17:28:41 -0700 |
parents | 12dcf5ba8b34 |
children | dd9cc155639c |
rev | line source |
---|---|
6934 | 1 /* |
14249
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
2 * Copyright (c) 2012, 2014, 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 | |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
174 // This code used to skip interface classes because their only |
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
175 // superclass was j.l.Object which would be also covered by class |
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
176 // superclass hierarchy walks. Now that the starting point can be |
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
177 // an interface, we must ensure we catch j.l.Object as the super. |
6934 | 178 static bool has_super(InstanceKlass* cls) { |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
179 return cls->super() != NULL; |
6934 | 180 } |
181 | |
182 Node* node_at_depth(int i) const { | |
183 return (i >= _path.length()) ? NULL : _path.at(_path.length() - i - 1); | |
184 } | |
185 | |
186 protected: | |
187 | |
188 // Accessors available to the algorithm | |
189 int current_depth() const { return _path.length() - 1; } | |
190 | |
191 InstanceKlass* class_at_depth(int i) { | |
192 Node* n = node_at_depth(i); | |
193 return n == NULL ? NULL : n->_class; | |
194 } | |
195 InstanceKlass* current_class() { return class_at_depth(0); } | |
196 | |
197 void* data_at_depth(int i) { | |
198 Node* n = node_at_depth(i); | |
199 return n == NULL ? NULL : n->_algorithm_data; | |
200 } | |
201 void* current_data() { return data_at_depth(0); } | |
202 | |
203 void cancel_iteration() { _cancelled = true; } | |
204 | |
205 public: | |
206 | |
207 void run(InstanceKlass* root) { | |
208 ALGO* algo = static_cast<ALGO*>(this); | |
209 | |
210 reset_iteration(); | |
211 | |
212 void* algo_data = algo->new_node_data(root); | |
213 push(root, algo_data); | |
214 bool top_needs_visit = true; | |
215 | |
216 do { | |
217 Node* top = current_top(); | |
218 if (top_needs_visit) { | |
219 if (algo->visit() == false) { | |
220 // algorithm does not want to continue along this path. Arrange | |
221 // it so that this state is immediately popped off the stack | |
222 top->set_super_visited(); | |
223 top->set_all_interfaces_visited(); | |
224 } | |
225 top_needs_visit = false; | |
226 } | |
227 | |
228 if (top->has_visited_super() && top->has_visited_all_interfaces()) { | |
229 algo->free_node_data(top->_algorithm_data); | |
230 pop(); | |
231 } else { | |
232 InstanceKlass* next = NULL; | |
233 if (top->has_visited_super() == false) { | |
234 next = top->next_super(); | |
235 top->set_super_visited(); | |
236 } else { | |
237 next = top->next_interface(); | |
238 top->increment_visited_interface(); | |
239 } | |
240 assert(next != NULL, "Otherwise we shouldn't be here"); | |
241 algo_data = algo->new_node_data(next); | |
242 push(next, algo_data); | |
243 top_needs_visit = true; | |
244 } | |
245 } while (!is_cancelled() && has_more_nodes()); | |
246 } | |
247 }; | |
248 | |
249 #ifndef PRODUCT | |
250 class PrintHierarchy : public HierarchyVisitor<PrintHierarchy> { | |
251 public: | |
252 | |
253 bool visit() { | |
254 InstanceKlass* cls = current_class(); | |
255 streamIndentor si(tty, current_depth() * 2); | |
256 tty->indent().print_cr("%s", cls->name()->as_C_string()); | |
257 return true; | |
258 } | |
259 | |
260 void* new_node_data(InstanceKlass* cls) { return NULL; } | |
261 void free_node_data(void* data) { return; } | |
262 }; | |
263 #endif // ndef PRODUCT | |
264 | |
265 // Used to register InstanceKlass objects and all related metadata structures | |
266 // (Methods, ConstantPools) as "in-use" by the current thread so that they can't | |
267 // be deallocated by class redefinition while we're using them. The classes are | |
268 // de-registered when this goes out of scope. | |
269 // | |
270 // Once a class is registered, we need not bother with methodHandles or | |
271 // constantPoolHandles for it's associated metadata. | |
272 class KeepAliveRegistrar : public StackObj { | |
273 private: | |
274 Thread* _thread; | |
275 GrowableArray<ConstantPool*> _keep_alive; | |
276 | |
277 public: | |
278 KeepAliveRegistrar(Thread* thread) : _thread(thread), _keep_alive(20) { | |
279 assert(thread == Thread::current(), "Must be current thread"); | |
280 } | |
281 | |
282 ~KeepAliveRegistrar() { | |
283 for (int i = _keep_alive.length() - 1; i >= 0; --i) { | |
284 ConstantPool* cp = _keep_alive.at(i); | |
285 int idx = _thread->metadata_handles()->find_from_end(cp); | |
286 assert(idx > 0, "Must be in the list"); | |
287 _thread->metadata_handles()->remove_at(idx); | |
288 } | |
289 } | |
290 | |
291 // Register a class as 'in-use' by the thread. It's fine to register a class | |
292 // multiple times (though perhaps inefficient) | |
293 void register_class(InstanceKlass* ik) { | |
294 ConstantPool* cp = ik->constants(); | |
295 _keep_alive.push(cp); | |
296 _thread->metadata_handles()->push(cp); | |
297 } | |
298 }; | |
299 | |
300 class KeepAliveVisitor : public HierarchyVisitor<KeepAliveVisitor> { | |
301 private: | |
302 KeepAliveRegistrar* _registrar; | |
303 | |
304 public: | |
305 KeepAliveVisitor(KeepAliveRegistrar* registrar) : _registrar(registrar) {} | |
306 | |
307 void* new_node_data(InstanceKlass* cls) { return NULL; } | |
308 void free_node_data(void* data) { return; } | |
309 | |
310 bool visit() { | |
311 _registrar->register_class(current_class()); | |
312 return true; | |
313 } | |
314 }; | |
315 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
316 |
6934 | 317 // 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
|
318 // erased method. As members of the set are collected while walking over the |
6934 | 319 // hierarchy, they are tagged with a qualification state. The qualification |
320 // state for an erased method is set to disqualified if there exists a path | |
321 // 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
|
322 // erased method defined in an interface. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
323 |
6934 | 324 class MethodFamily : public ResourceObj { |
325 private: | |
326 | |
327 GrowableArray<Pair<Method*,QualifiedState> > _members; | |
328 ResourceHashtable<Method*, int> _member_index; | |
329 | |
330 Method* _selected_target; // Filled in later, if a unique target exists | |
331 Symbol* _exception_message; // If no unique target is found | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
332 Symbol* _exception_name; // If no unique target is found |
6934 | 333 |
334 bool contains_method(Method* method) { | |
335 int* lookup = _member_index.get(method); | |
336 return lookup != NULL; | |
337 } | |
338 | |
339 void add_method(Method* method, QualifiedState state) { | |
340 Pair<Method*,QualifiedState> entry(method, state); | |
341 _member_index.put(method, _members.length()); | |
342 _members.append(entry); | |
343 } | |
344 | |
345 void disqualify_method(Method* method) { | |
346 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
|
347 guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); |
6934 | 348 _members.at(*index).second = DISQUALIFIED; |
349 } | |
350 | |
351 Symbol* generate_no_defaults_message(TRAPS) const; | |
14221
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
352 Symbol* generate_method_message(Symbol *klass_name, Method* method, TRAPS) const; |
6934 | 353 Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const; |
354 | |
355 public: | |
356 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
357 MethodFamily() |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
358 : _selected_target(NULL), _exception_message(NULL), _exception_name(NULL) {} |
6934 | 359 |
360 void set_target_if_empty(Method* m) { | |
361 if (_selected_target == NULL && !m->is_overpass()) { | |
362 _selected_target = m; | |
363 } | |
364 } | |
365 | |
366 void record_qualified_method(Method* m) { | |
367 // If the method already exists in the set as qualified, this operation is | |
368 // redundant. If it already exists as disqualified, then we leave it as | |
369 // disqualfied. Thus we only add to the set if it's not already in the | |
370 // set. | |
371 if (!contains_method(m)) { | |
372 add_method(m, QUALIFIED); | |
373 } | |
374 } | |
375 | |
376 void record_disqualified_method(Method* m) { | |
377 // If not in the set, add it as disqualified. If it's already in the set, | |
378 // then set the state to disqualified no matter what the previous state was. | |
379 if (!contains_method(m)) { | |
380 add_method(m, DISQUALIFIED); | |
381 } else { | |
382 disqualify_method(m); | |
383 } | |
384 } | |
385 | |
386 bool has_target() const { return _selected_target != NULL; } | |
387 bool throws_exception() { return _exception_message != NULL; } | |
388 | |
389 Method* get_selected_target() { return _selected_target; } | |
390 Symbol* get_exception_message() { return _exception_message; } | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
391 Symbol* get_exception_name() { return _exception_name; } |
6934 | 392 |
393 // Either sets the target or the exception error message | |
394 void determine_target(InstanceKlass* root, TRAPS) { | |
395 if (has_target() || throws_exception()) { | |
396 return; | |
397 } | |
398 | |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
399 // Qualified methods are maximally-specific methods |
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
400 // These include public, instance concrete (=default) and abstract methods |
6934 | 401 GrowableArray<Method*> qualified_methods; |
13035
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
402 int num_defaults = 0; |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
403 int default_index = -1; |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
404 int qualified_index = -1; |
6934 | 405 for (int i = 0; i < _members.length(); ++i) { |
406 Pair<Method*,QualifiedState> entry = _members.at(i); | |
407 if (entry.second == QUALIFIED) { | |
408 qualified_methods.append(entry.first); | |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
409 qualified_index++; |
13035
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
410 if (entry.first->is_default_method()) { |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
411 num_defaults++; |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
412 default_index = qualified_index; |
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
413 |
13035
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
414 } |
6934 | 415 } |
416 } | |
417 | |
14221
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
418 if (num_defaults == 0) { |
14249
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
419 // If the root klass has a static method with matching name and signature |
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
420 // then do not generate an overpass method because it will hide the |
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
421 // static method during resolution. |
17889
386dd1c71858
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
14249
diff
changeset
|
422 if (qualified_methods.length() == 0) { |
386dd1c71858
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
14249
diff
changeset
|
423 _exception_message = generate_no_defaults_message(CHECK); |
386dd1c71858
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
14249
diff
changeset
|
424 } else { |
386dd1c71858
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
14249
diff
changeset
|
425 assert(root != NULL, "Null root class"); |
386dd1c71858
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
14249
diff
changeset
|
426 _exception_message = generate_method_message(root->name(), qualified_methods.at(0), CHECK); |
14221
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
427 } |
17889
386dd1c71858
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
14249
diff
changeset
|
428 _exception_name = vmSymbols::java_lang_AbstractMethodError(); |
14249
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
429 |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
430 // If only one qualified method is default, select that |
13035
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
431 } else if (num_defaults == 1) { |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
432 _selected_target = qualified_methods.at(default_index); |
14249
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
433 |
17889
386dd1c71858
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
14249
diff
changeset
|
434 } else if (num_defaults > 1) { |
14249
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
435 _exception_message = generate_conflicts_message(&qualified_methods,CHECK); |
78468e5dc6fc
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
14222
diff
changeset
|
436 _exception_name = vmSymbols::java_lang_IncompatibleClassChangeError(); |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
437 if (TraceDefaultMethods) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
438 _exception_message->print_value_on(tty); |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17889
diff
changeset
|
439 tty->cr(); |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
440 } |
6934 | 441 } |
442 } | |
443 | |
444 bool contains_signature(Symbol* query) { | |
445 for (int i = 0; i < _members.length(); ++i) { | |
446 if (query == _members.at(i).first->signature()) { | |
447 return true; | |
448 } | |
449 } | |
450 return false; | |
451 } | |
452 | |
453 #ifndef PRODUCT | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
454 void print_sig_on(outputStream* str, Symbol* signature, int indent) const { |
6934 | 455 streamIndentor si(str, indent * 2); |
456 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
457 str->indent().print_cr("Logical Method %s:", signature->as_C_string()); |
6934 | 458 |
459 streamIndentor si2(str); | |
460 for (int i = 0; i < _members.length(); ++i) { | |
461 str->indent(); | |
462 print_method(str, _members.at(i).first); | |
463 if (_members.at(i).second == DISQUALIFIED) { | |
464 str->print(" (disqualified)"); | |
465 } | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17889
diff
changeset
|
466 str->cr(); |
6934 | 467 } |
468 | |
469 if (_selected_target != NULL) { | |
470 print_selected(str, 1); | |
471 } | |
472 } | |
473 | |
474 void print_selected(outputStream* str, int indent) const { | |
475 assert(has_target(), "Should be called otherwise"); | |
476 streamIndentor si(str, indent * 2); | |
477 str->indent().print("Selected method: "); | |
478 print_method(str, _selected_target); | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
479 Klass* method_holder = _selected_target->method_holder(); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
480 if (!method_holder->is_interface()) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
481 tty->print(" : in superclass"); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
482 } |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17889
diff
changeset
|
483 str->cr(); |
6934 | 484 } |
485 | |
486 void print_exception(outputStream* str, int indent) { | |
487 assert(throws_exception(), "Should be called otherwise"); | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
488 assert(_exception_name != NULL, "exception_name should be set"); |
6934 | 489 streamIndentor si(str, indent * 2); |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
490 str->indent().print_cr("%s: %s", _exception_name->as_C_string(), _exception_message->as_C_string()); |
6934 | 491 } |
492 #endif // ndef PRODUCT | |
493 }; | |
494 | |
495 Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { | |
496 return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL); | |
497 } | |
498 | |
14221
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
499 Symbol* MethodFamily::generate_method_message(Symbol *klass_name, Method* method, TRAPS) const { |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
500 stringStream ss; |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
501 ss.print("Method "); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
502 Symbol* name = method->name(); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
503 Symbol* signature = method->signature(); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
504 ss.write((const char*)klass_name->bytes(), klass_name->utf8_length()); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
505 ss.print("."); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
506 ss.write((const char*)name->bytes(), name->utf8_length()); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
507 ss.write((const char*)signature->bytes(), signature->utf8_length()); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
508 ss.print(" is abstract"); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
509 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
510 } |
2353011244bd
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
13414
diff
changeset
|
511 |
6934 | 512 Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { |
513 stringStream ss; | |
514 ss.print("Conflicting default methods:"); | |
515 for (int i = 0; i < methods->length(); ++i) { | |
516 Method* method = methods->at(i); | |
517 Symbol* klass = method->klass_name(); | |
518 Symbol* name = method->name(); | |
519 ss.print(" "); | |
520 ss.write((const char*)klass->bytes(), klass->utf8_length()); | |
521 ss.print("."); | |
522 ss.write((const char*)name->bytes(), name->utf8_length()); | |
523 } | |
524 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); | |
525 } | |
526 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
527 |
6934 | 528 class StateRestorer; |
529 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
530 // StatefulMethodFamily is a wrapper around a MethodFamily that maintains the |
6934 | 531 // 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
|
532 // when adding members to the MethodFamily |
6934 | 533 class StatefulMethodFamily : public ResourceObj { |
534 friend class StateRestorer; | |
535 private: | |
536 QualifiedState _qualification_state; | |
537 | |
538 void set_qualification_state(QualifiedState state) { | |
539 _qualification_state = state; | |
540 } | |
541 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
542 protected: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
543 MethodFamily* _method_family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
544 |
6934 | 545 public: |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
546 StatefulMethodFamily() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
547 _method_family = new MethodFamily(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
548 _qualification_state = QUALIFIED; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
549 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
550 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
551 StatefulMethodFamily(MethodFamily* mf) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
552 _method_family = mf; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
553 _qualification_state = QUALIFIED; |
6934 | 554 } |
555 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
556 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
|
557 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
558 MethodFamily* get_method_family() { return _method_family; } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
559 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
560 StateRestorer* record_method_and_dq_further(Method* mo); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
561 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
562 |
6934 | 563 class StateRestorer : public PseudoScopeMark { |
564 private: | |
565 StatefulMethodFamily* _method; | |
566 QualifiedState _state_to_restore; | |
567 public: | |
568 StateRestorer(StatefulMethodFamily* dm, QualifiedState state) | |
569 : _method(dm), _state_to_restore(state) {} | |
570 ~StateRestorer() { destroy(); } | |
571 void restore_state() { _method->set_qualification_state(_state_to_restore); } | |
572 virtual void destroy() { restore_state(); } | |
573 }; | |
574 | |
575 StateRestorer* StatefulMethodFamily::record_method_and_dq_further(Method* mo) { | |
576 StateRestorer* mark = new StateRestorer(this, _qualification_state); | |
577 if (_qualification_state == QUALIFIED) { | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
578 _method_family->record_qualified_method(mo); |
6934 | 579 } else { |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
580 _method_family->record_disqualified_method(mo); |
6934 | 581 } |
582 // Everything found "above"??? this method in the hierarchy walk is set to | |
583 // disqualified | |
584 set_qualification_state(DISQUALIFIED); | |
585 return mark; | |
586 } | |
587 | |
588 // Represents a location corresponding to a vtable slot for methods that | |
589 // neither the class nor any of it's ancestors provide an implementaion. | |
590 // Default methods may be present to fill this slot. | |
591 class EmptyVtableSlot : public ResourceObj { | |
592 private: | |
593 Symbol* _name; | |
594 Symbol* _signature; | |
595 int _size_of_parameters; | |
596 MethodFamily* _binding; | |
597 | |
598 public: | |
599 EmptyVtableSlot(Method* method) | |
600 : _name(method->name()), _signature(method->signature()), | |
601 _size_of_parameters(method->size_of_parameters()), _binding(NULL) {} | |
602 | |
603 Symbol* name() const { return _name; } | |
604 Symbol* signature() const { return _signature; } | |
605 int size_of_parameters() const { return _size_of_parameters; } | |
606 | |
607 void bind_family(MethodFamily* lm) { _binding = lm; } | |
608 bool is_bound() { return _binding != NULL; } | |
609 MethodFamily* get_binding() { return _binding; } | |
610 | |
611 #ifndef PRODUCT | |
612 void print_on(outputStream* str) const { | |
613 print_slot(str, name(), signature()); | |
614 } | |
615 #endif // ndef PRODUCT | |
616 }; | |
617 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
618 static bool already_in_vtable_slots(GrowableArray<EmptyVtableSlot*>* slots, Method* m) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
619 bool found = false; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
620 for (int j = 0; j < slots->length(); ++j) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
621 if (slots->at(j)->name() == m->name() && |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
622 slots->at(j)->signature() == m->signature() ) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
623 found = true; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
624 break; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
625 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
626 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
627 return found; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
628 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
629 |
6934 | 630 static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( |
631 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { | |
632 | |
633 assert(klass != NULL, "Must be valid class"); | |
634 | |
635 GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); | |
636 | |
637 // All miranda methods are obvious candidates | |
638 for (int i = 0; i < mirandas->length(); ++i) { | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
639 Method* m = mirandas->at(i); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
640 if (!already_in_vtable_slots(slots, m)) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
641 slots->append(new EmptyVtableSlot(m)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
642 } |
6934 | 643 } |
644 | |
645 // Also any overpasses in our superclasses, that we haven't implemented. | |
646 // (can't use the vtable because it is not guaranteed to be initialized yet) | |
647 InstanceKlass* super = klass->java_super(); | |
648 while (super != NULL) { | |
649 for (int i = 0; i < super->methods()->length(); ++i) { | |
650 Method* m = super->methods()->at(i); | |
13414
379f11bc04fc
8028438: static superclass method masks default methods
acorn
parents:
13055
diff
changeset
|
651 if (m->is_overpass() || m->is_static()) { |
6934 | 652 // m is a method that would have been a miranda if not for the |
653 // default method processing that occurred on behalf of our superclass, | |
654 // so it's a method we want to re-examine in this new context. That is, | |
655 // unless we have a real implementation of it in the current class. | |
656 Method* impl = klass->lookup_method(m->name(), m->signature()); | |
13414
379f11bc04fc
8028438: static superclass method masks default methods
acorn
parents:
13055
diff
changeset
|
657 if (impl == NULL || impl->is_overpass() || impl->is_static()) { |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
658 if (!already_in_vtable_slots(slots, m)) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
659 slots->append(new EmptyVtableSlot(m)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
660 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
661 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
662 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
663 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
664 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
665 // also any default methods in our superclasses |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
666 if (super->default_methods() != NULL) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
667 for (int i = 0; i < super->default_methods()->length(); ++i) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
668 Method* m = super->default_methods()->at(i); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
669 // m is a method that would have been a miranda if not for the |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
670 // default method processing that occurred on behalf of our superclass, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
671 // so it's a method we want to re-examine in this new context. That is, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
672 // unless we have a real implementation of it in the current class. |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
673 Method* impl = klass->lookup_method(m->name(), m->signature()); |
13414
379f11bc04fc
8028438: static superclass method masks default methods
acorn
parents:
13055
diff
changeset
|
674 if (impl == NULL || impl->is_overpass() || impl->is_static()) { |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
675 if (!already_in_vtable_slots(slots, m)) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
676 slots->append(new EmptyVtableSlot(m)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
677 } |
6934 | 678 } |
679 } | |
680 } | |
681 super = super->java_super(); | |
682 } | |
683 | |
684 #ifndef PRODUCT | |
685 if (TraceDefaultMethods) { | |
686 tty->print_cr("Slots that need filling:"); | |
687 streamIndentor si(tty); | |
688 for (int i = 0; i < slots->length(); ++i) { | |
689 tty->indent(); | |
690 slots->at(i)->print_on(tty); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17889
diff
changeset
|
691 tty->cr(); |
6934 | 692 } |
693 } | |
694 #endif // ndef PRODUCT | |
695 return slots; | |
696 } | |
697 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
698 // 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
|
699 // with a specific erased signature. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
700 class FindMethodsByErasedSig : public HierarchyVisitor<FindMethodsByErasedSig> { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
701 private: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
702 // Context data |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
703 Symbol* _method_name; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
704 Symbol* _method_signature; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
705 StatefulMethodFamily* _family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
706 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
707 public: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
708 FindMethodsByErasedSig(Symbol* name, Symbol* signature) : |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
709 _method_name(name), _method_signature(signature), |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
710 _family(NULL) {} |
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 void get_discovered_family(MethodFamily** family) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
713 if (_family != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
714 *family = _family->get_method_family(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
715 } else { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
716 *family = NULL; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
717 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
718 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
719 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
720 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
|
721 void free_node_data(void* node_data) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
722 PseudoScope::cast(node_data)->destroy(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
723 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
724 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
725 // 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
|
726 // method's erased (name, signature) |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
727 bool visit() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
728 PseudoScope* scope = PseudoScope::cast(current_data()); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
729 InstanceKlass* iklass = current_class(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
730 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
731 Method* m = iklass->find_method(_method_name, _method_signature); |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
732 // private interface methods are not candidates for default methods |
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
733 // invokespecial to private interface methods doesn't use default method logic |
21829 | 734 // private class methods are not candidates for default methods, |
735 // private methods do not override default methods, so need to perform | |
736 // default method inheritance without including private methods | |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
737 // The overpasses are your supertypes' errors, we do not include them |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
738 // future: take access controls into account for superclass methods |
21829 | 739 if (m != NULL && !m->is_static() && !m->is_overpass() && !m->is_private()) { |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
740 if (_family == NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
741 _family = new StatefulMethodFamily(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
742 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
743 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
744 if (iklass->is_interface()) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
745 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
|
746 scope->add_mark(restorer); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
747 } else { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
748 // 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
|
749 // methods in interfaces. This works because of single inheritance |
21829 | 750 // private methods in classes do not "win", they will be found |
751 // first on searching, but overriding for invokevirtual needs | |
752 // to find default method candidates for the same signature | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
753 _family->set_target_if_empty(m); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
754 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
755 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
756 return true; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
757 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
758 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
759 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
760 |
6934 | 761 |
762 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
763 static void create_defaults_and_exceptions( |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
764 GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
765 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
766 static void generate_erased_defaults( |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
767 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
768 EmptyVtableSlot* slot, TRAPS) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
769 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
770 // 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
|
771 FindMethodsByErasedSig visitor(slot->name(), slot->signature()); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
772 visitor.run(klass); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
773 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
774 MethodFamily* family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
775 visitor.get_discovered_family(&family); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
776 if (family != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
777 family->determine_target(klass, CHECK); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
778 slot->bind_family(family); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
779 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
780 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
781 |
6934 | 782 static void merge_in_new_methods(InstanceKlass* klass, |
783 GrowableArray<Method*>* new_methods, TRAPS); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
784 static void create_default_methods( InstanceKlass* klass, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
785 GrowableArray<Method*>* new_methods, TRAPS); |
6934 | 786 |
787 // This is the guts of the default methods implementation. This is called just | |
788 // after the classfile has been parsed if some ancestor has default methods. | |
789 // | |
790 // First if finds any name/signature slots that need any implementation (either | |
791 // 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
|
792 // 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
|
793 // signature that matches the slot we are looking at. |
6934 | 794 // |
795 // For each slot filled, we generate an overpass method that either calls the | |
796 // unique default method candidate using invokespecial, or throws an exception | |
797 // (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
|
798 // 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
|
799 // The JVM does not create bridges nor handle generic signatures here. |
6934 | 800 void DefaultMethods::generate_default_methods( |
801 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { | |
802 | |
803 // This resource mark is the bound for all memory allocation that takes | |
804 // place during default method processing. After this goes out of scope, | |
805 // all (Resource) objects' memory will be reclaimed. Be careful if adding an | |
806 // embedded resource mark under here as that memory can't be used outside | |
807 // whatever scope it's in. | |
808 ResourceMark rm(THREAD); | |
809 | |
810 // Keep entire hierarchy alive for the duration of the computation | |
811 KeepAliveRegistrar keepAlive(THREAD); | |
812 KeepAliveVisitor loadKeepAlive(&keepAlive); | |
813 loadKeepAlive.run(klass); | |
814 | |
815 #ifndef PRODUCT | |
816 if (TraceDefaultMethods) { | |
817 ResourceMark rm; // be careful with these! | |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
818 tty->print_cr("%s %s requires default method processing", |
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
819 klass->is_interface() ? "Interface" : "Class", |
6934 | 820 klass->name()->as_klass_external_name()); |
821 PrintHierarchy printer; | |
822 printer.run(klass); | |
823 } | |
824 #endif // ndef PRODUCT | |
825 | |
826 GrowableArray<EmptyVtableSlot*>* empty_slots = | |
827 find_empty_vtable_slots(klass, mirandas, CHECK); | |
828 | |
829 for (int i = 0; i < empty_slots->length(); ++i) { | |
830 EmptyVtableSlot* slot = empty_slots->at(i); | |
831 #ifndef PRODUCT | |
832 if (TraceDefaultMethods) { | |
833 streamIndentor si(tty, 2); | |
834 tty->indent().print("Looking for default methods for slot "); | |
835 slot->print_on(tty); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17889
diff
changeset
|
836 tty->cr(); |
6934 | 837 } |
838 #endif // ndef PRODUCT | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
839 |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
840 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
|
841 } |
6934 | 842 #ifndef PRODUCT |
843 if (TraceDefaultMethods) { | |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
844 tty->print_cr("Creating defaults and overpasses..."); |
6934 | 845 } |
846 #endif // ndef PRODUCT | |
847 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
848 create_defaults_and_exceptions(empty_slots, klass, CHECK); |
6934 | 849 |
850 #ifndef PRODUCT | |
851 if (TraceDefaultMethods) { | |
852 tty->print_cr("Default method processing complete"); | |
853 } | |
854 #endif // ndef PRODUCT | |
855 } | |
856 | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
857 static int assemble_method_error( |
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
858 BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) { |
6934 | 859 |
860 Symbol* init = vmSymbols::object_initializer_name(); | |
861 Symbol* sig = vmSymbols::string_void_signature(); | |
862 | |
863 BytecodeAssembler assem(buffer, cp); | |
864 | |
865 assem._new(errorName); | |
866 assem.dup(); | |
867 assem.load_string(message); | |
868 assem.invokespecial(errorName, init, sig); | |
869 assem.athrow(); | |
870 | |
871 return 3; // max stack size: [ exception, exception, string ] | |
872 } | |
873 | |
874 static Method* new_method( | |
875 BytecodeConstantPool* cp, BytecodeBuffer* bytecodes, Symbol* name, | |
876 Symbol* sig, AccessFlags flags, int max_stack, int params, | |
877 ConstMethod::MethodType mt, TRAPS) { | |
878 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
879 address code_start = 0; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
880 int code_length = 0; |
8031 | 881 InlineTableSizes sizes; |
6934 | 882 |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
883 if (bytecodes != NULL && bytecodes->length() > 0) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
884 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
|
885 code_length = bytecodes->length(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
886 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
887 |
6934 | 888 Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), |
8031 | 889 code_length, flags, &sizes, |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7183
diff
changeset
|
890 mt, CHECK_NULL); |
6934 | 891 |
892 m->set_constants(NULL); // This will get filled in later | |
893 m->set_name_index(cp->utf8(name)); | |
894 m->set_signature_index(cp->utf8(sig)); | |
895 #ifdef CC_INTERP | |
896 ResultTypeFinder rtf(sig); | |
897 m->set_result_index(rtf.type()); | |
898 #endif | |
899 m->set_size_of_parameters(params); | |
900 m->set_max_stack(max_stack); | |
901 m->set_max_locals(params); | |
902 m->constMethod()->set_stackmap_data(NULL); | |
903 m->set_code(code_start); | |
904 | |
905 return m; | |
906 } | |
907 | |
908 static void switchover_constant_pool(BytecodeConstantPool* bpool, | |
909 InstanceKlass* klass, GrowableArray<Method*>* new_methods, TRAPS) { | |
910 | |
911 if (new_methods->length() > 0) { | |
912 ConstantPool* cp = bpool->create_constant_pool(CHECK); | |
913 if (cp != klass->constants()) { | |
914 klass->class_loader_data()->add_to_deallocate_list(klass->constants()); | |
915 klass->set_constants(cp); | |
916 cp->set_pool_holder(klass); | |
917 | |
918 for (int i = 0; i < new_methods->length(); ++i) { | |
919 new_methods->at(i)->set_constants(cp); | |
920 } | |
921 for (int i = 0; i < klass->methods()->length(); ++i) { | |
922 Method* mo = klass->methods()->at(i); | |
923 mo->set_constants(cp); | |
924 } | |
925 } | |
926 } | |
927 } | |
928 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
929 // Create default_methods list for the current class. |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
930 // With the VM only processing erased signatures, the VM only |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
931 // creates an overpass in a conflict case or a case with no candidates. |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
932 // This allows virtual methods to override the overpass, but ensures |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
933 // that a local method search will find the exception rather than an abstract |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
934 // or default method that is not a valid candidate. |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
935 static void create_defaults_and_exceptions( |
6934 | 936 GrowableArray<EmptyVtableSlot*>* slots, |
937 InstanceKlass* klass, TRAPS) { | |
938 | |
939 GrowableArray<Method*> overpasses; | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
940 GrowableArray<Method*> defaults; |
6934 | 941 BytecodeConstantPool bpool(klass->constants()); |
942 | |
943 for (int i = 0; i < slots->length(); ++i) { | |
944 EmptyVtableSlot* slot = slots->at(i); | |
945 | |
946 if (slot->is_bound()) { | |
947 MethodFamily* method = slot->get_binding(); | |
948 BytecodeBuffer buffer; | |
949 | |
950 #ifndef PRODUCT | |
951 if (TraceDefaultMethods) { | |
952 tty->print("for slot: "); | |
953 slot->print_on(tty); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17889
diff
changeset
|
954 tty->cr(); |
6934 | 955 if (method->has_target()) { |
956 method->print_selected(tty, 1); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
957 } else if (method->throws_exception()) { |
6934 | 958 method->print_exception(tty, 1); |
959 } | |
960 } | |
961 #endif // ndef PRODUCT | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
962 |
6934 | 963 if (method->has_target()) { |
964 Method* selected = method->get_selected_target(); | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
965 if (selected->method_holder()->is_interface()) { |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
966 defaults.push(selected); |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
967 } |
6934 | 968 } else if (method->throws_exception()) { |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
969 int max_stack = assemble_method_error(&bpool, &buffer, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
970 method->get_exception_name(), method->get_exception_message(), CHECK); |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
971 AccessFlags flags = accessFlags_from( |
6934 | 972 JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
973 Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), |
6934 | 974 flags, max_stack, slot->size_of_parameters(), |
975 ConstMethod::OVERPASS, CHECK); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
976 // We push to the methods list: |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
977 // overpass methods which are exception throwing methods |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
978 if (m != NULL) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
979 overpasses.push(m); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
980 } |
6934 | 981 } |
982 } | |
983 } | |
984 | |
985 #ifndef PRODUCT | |
986 if (TraceDefaultMethods) { | |
987 tty->print_cr("Created %d overpass methods", overpasses.length()); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
988 tty->print_cr("Created %d default methods", defaults.length()); |
6934 | 989 } |
990 #endif // ndef PRODUCT | |
991 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
992 if (overpasses.length() > 0) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
993 switchover_constant_pool(&bpool, klass, &overpasses, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
994 merge_in_new_methods(klass, &overpasses, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
995 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
996 if (defaults.length() > 0) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
997 create_default_methods(klass, &defaults, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
998 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
999 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1000 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1001 static void create_default_methods( InstanceKlass* klass, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1002 GrowableArray<Method*>* new_methods, TRAPS) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1003 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1004 int new_size = new_methods->length(); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1005 Array<Method*>* total_default_methods = MetadataFactory::new_array<Method*>( |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1006 klass->class_loader_data(), new_size, NULL, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1007 for (int index = 0; index < new_size; index++ ) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1008 total_default_methods->at_put(index, new_methods->at(index)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1009 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1010 Method::sort_methods(total_default_methods, false, false); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1011 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
1012 klass->set_default_methods(total_default_methods); |
6934 | 1013 } |
1014 | |
1015 static void sort_methods(GrowableArray<Method*>* methods) { | |
1016 // Note that this must sort using the same key as is used for sorting | |
1017 // methods in InstanceKlass. | |
1018 bool sorted = true; | |
1019 for (int i = methods->length() - 1; i > 0; --i) { | |
1020 for (int j = 0; j < i; ++j) { | |
1021 Method* m1 = methods->at(j); | |
1022 Method* m2 = methods->at(j + 1); | |
1023 if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) { | |
1024 methods->at_put(j, m2); | |
1025 methods->at_put(j + 1, m1); | |
1026 sorted = false; | |
1027 } | |
1028 } | |
1029 if (sorted) break; | |
1030 sorted = true; | |
1031 } | |
1032 #ifdef ASSERT | |
1033 uintptr_t prev = 0; | |
1034 for (int i = 0; i < methods->length(); ++i) { | |
1035 Method* mh = methods->at(i); | |
1036 uintptr_t nv = (uintptr_t)mh->name(); | |
1037 assert(nv >= prev, "Incorrect overpass method ordering"); | |
1038 prev = nv; | |
1039 } | |
1040 #endif | |
1041 } | |
1042 | |
1043 static void merge_in_new_methods(InstanceKlass* klass, | |
1044 GrowableArray<Method*>* new_methods, TRAPS) { | |
1045 | |
1046 enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS }; | |
1047 | |
1048 Array<Method*>* original_methods = klass->methods(); | |
1049 Array<int>* original_ordering = klass->method_ordering(); | |
1050 Array<int>* merged_ordering = Universe::the_empty_int_array(); | |
1051 | |
1052 int new_size = klass->methods()->length() + new_methods->length(); | |
1053 | |
1054 Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>( | |
1055 klass->class_loader_data(), new_size, NULL, CHECK); | |
8031 | 1056 |
14222
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1057 // original_ordering might be empty if this class has no methods of its own |
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1058 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
6934 | 1059 merged_ordering = MetadataFactory::new_array<int>( |
1060 klass->class_loader_data(), new_size, CHECK); | |
1061 } | |
1062 int method_order_index = klass->methods()->length(); | |
1063 | |
1064 sort_methods(new_methods); | |
1065 | |
1066 // Perform grand merge of existing methods and new methods | |
1067 int orig_idx = 0; | |
1068 int new_idx = 0; | |
1069 | |
1070 for (int i = 0; i < new_size; ++i) { | |
1071 Method* orig_method = NULL; | |
1072 Method* new_method = NULL; | |
1073 if (orig_idx < original_methods->length()) { | |
1074 orig_method = original_methods->at(orig_idx); | |
1075 } | |
1076 if (new_idx < new_methods->length()) { | |
1077 new_method = new_methods->at(new_idx); | |
1078 } | |
1079 | |
1080 if (orig_method != NULL && | |
1081 (new_method == NULL || orig_method->name() < new_method->name())) { | |
1082 merged_methods->at_put(i, orig_method); | |
1083 original_methods->at_put(orig_idx, NULL); | |
1084 if (merged_ordering->length() > 0) { | |
14222
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1085 assert(original_ordering != NULL && original_ordering->length() > 0, |
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1086 "should have original order information for this method"); |
6934 | 1087 merged_ordering->at_put(i, original_ordering->at(orig_idx)); |
1088 } | |
1089 ++orig_idx; | |
1090 } else { | |
1091 merged_methods->at_put(i, new_method); | |
1092 if (merged_ordering->length() > 0) { | |
1093 merged_ordering->at_put(i, method_order_index++); | |
1094 } | |
1095 ++new_idx; | |
1096 } | |
1097 // update idnum for new location | |
1098 merged_methods->at(i)->set_method_idnum(i); | |
1099 } | |
1100 | |
1101 // Verify correct order | |
1102 #ifdef ASSERT | |
1103 uintptr_t prev = 0; | |
1104 for (int i = 0; i < merged_methods->length(); ++i) { | |
1105 Method* mo = merged_methods->at(i); | |
1106 uintptr_t nv = (uintptr_t)mo->name(); | |
1107 assert(nv >= prev, "Incorrect method ordering"); | |
1108 prev = nv; | |
1109 } | |
1110 #endif | |
1111 | |
1112 // Replace klass methods with new merged lists | |
1113 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
|
1114 klass->set_initial_method_idnum(new_size); |
14222
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1115 klass->set_method_ordering(merged_ordering); |
6934 | 1116 |
14222
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1117 // Free metadata |
6934 | 1118 ClassLoaderData* cld = klass->class_loader_data(); |
14222
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1119 if (original_methods->length() > 0) { |
13055
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
1120 MetadataFactory::free_array(cld, original_methods); |
fce21ac5968d
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
13035
diff
changeset
|
1121 } |
14222
e9b6b2aa5125
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
14221
diff
changeset
|
1122 if (original_ordering != NULL && original_ordering->length() > 0) { |
6934 | 1123 MetadataFactory::free_array(cld, original_ordering); |
1124 } | |
1125 } |