Mercurial > hg > truffle
annotate src/share/vm/classfile/defaultMethods.cpp @ 13035:fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
Reviewed-by: hseigel, zgu
author | acorn |
---|---|
date | Wed, 30 Oct 2013 09:11:04 -0700 |
parents | f50418dfb1b7 |
children | fce21ac5968d |
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 | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
328 Symbol* _exception_name; // If no unique target is found |
6934 | 329 |
330 bool contains_method(Method* method) { | |
331 int* lookup = _member_index.get(method); | |
332 return lookup != NULL; | |
333 } | |
334 | |
335 void add_method(Method* method, QualifiedState state) { | |
336 Pair<Method*,QualifiedState> entry(method, state); | |
337 _member_index.put(method, _members.length()); | |
338 _members.append(entry); | |
339 } | |
340 | |
341 void disqualify_method(Method* method) { | |
342 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
|
343 guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); |
6934 | 344 _members.at(*index).second = DISQUALIFIED; |
345 } | |
346 | |
347 Symbol* generate_no_defaults_message(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() |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
353 : _selected_target(NULL), _exception_message(NULL), _exception_name(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; } | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
386 Symbol* get_exception_name() { return _exception_name; } |
6934 | 387 |
388 // Either sets the target or the exception error message | |
389 void determine_target(InstanceKlass* root, TRAPS) { | |
390 if (has_target() || throws_exception()) { | |
391 return; | |
392 } | |
393 | |
394 GrowableArray<Method*> qualified_methods; | |
13035
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
395 int num_defaults = 0; |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
396 int default_index = -1; |
6934 | 397 for (int i = 0; i < _members.length(); ++i) { |
398 Pair<Method*,QualifiedState> entry = _members.at(i); | |
399 if (entry.second == QUALIFIED) { | |
400 qualified_methods.append(entry.first); | |
13035
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
401 default_index++; |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
402 if (entry.first->is_default_method()) { |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
403 num_defaults++; |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
404 } |
6934 | 405 } |
406 } | |
407 | |
408 if (qualified_methods.length() == 0) { | |
409 _exception_message = generate_no_defaults_message(CHECK); | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
410 _exception_name = vmSymbols::java_lang_AbstractMethodError(); |
6934 | 411 } else if (qualified_methods.length() == 1) { |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
412 // leave abstract methods alone, they will be found via normal search path |
6934 | 413 Method* method = qualified_methods.at(0); |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
414 if (!method->is_abstract()) { |
6934 | 415 _selected_target = qualified_methods.at(0); |
416 } | |
13035
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
417 // If only one qualified method is default, select that |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
418 } else if (num_defaults == 1) { |
fdd464c8d62e
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
12883
diff
changeset
|
419 _selected_target = qualified_methods.at(default_index); |
6934 | 420 } else { |
421 _exception_message = generate_conflicts_message(&qualified_methods,CHECK); | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
422 _exception_name = vmSymbols::java_lang_IncompatibleClassChangeError(); |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
423 if (TraceDefaultMethods) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
424 _exception_message->print_value_on(tty); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
425 tty->print_cr(""); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
426 } |
6934 | 427 } |
428 } | |
429 | |
430 bool contains_signature(Symbol* query) { | |
431 for (int i = 0; i < _members.length(); ++i) { | |
432 if (query == _members.at(i).first->signature()) { | |
433 return true; | |
434 } | |
435 } | |
436 return false; | |
437 } | |
438 | |
439 #ifndef PRODUCT | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
440 void print_sig_on(outputStream* str, Symbol* signature, int indent) const { |
6934 | 441 streamIndentor si(str, indent * 2); |
442 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
443 str->indent().print_cr("Logical Method %s:", signature->as_C_string()); |
6934 | 444 |
445 streamIndentor si2(str); | |
446 for (int i = 0; i < _members.length(); ++i) { | |
447 str->indent(); | |
448 print_method(str, _members.at(i).first); | |
449 if (_members.at(i).second == DISQUALIFIED) { | |
450 str->print(" (disqualified)"); | |
451 } | |
452 str->print_cr(""); | |
453 } | |
454 | |
455 if (_selected_target != NULL) { | |
456 print_selected(str, 1); | |
457 } | |
458 } | |
459 | |
460 void print_selected(outputStream* str, int indent) const { | |
461 assert(has_target(), "Should be called otherwise"); | |
462 streamIndentor si(str, indent * 2); | |
463 str->indent().print("Selected method: "); | |
464 print_method(str, _selected_target); | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
465 Klass* method_holder = _selected_target->method_holder(); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
466 if (!method_holder->is_interface()) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
467 tty->print(" : in superclass"); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
468 } |
6934 | 469 str->print_cr(""); |
470 } | |
471 | |
472 void print_exception(outputStream* str, int indent) { | |
473 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
|
474 assert(_exception_name != NULL, "exception_name should be set"); |
6934 | 475 streamIndentor si(str, indent * 2); |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
476 str->indent().print_cr("%s: %s", _exception_name->as_C_string(), _exception_message->as_C_string()); |
6934 | 477 } |
478 #endif // ndef PRODUCT | |
479 }; | |
480 | |
481 Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { | |
482 return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL); | |
483 } | |
484 | |
485 Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { | |
486 stringStream ss; | |
487 ss.print("Conflicting default methods:"); | |
488 for (int i = 0; i < methods->length(); ++i) { | |
489 Method* method = methods->at(i); | |
490 Symbol* klass = method->klass_name(); | |
491 Symbol* name = method->name(); | |
492 ss.print(" "); | |
493 ss.write((const char*)klass->bytes(), klass->utf8_length()); | |
494 ss.print("."); | |
495 ss.write((const char*)name->bytes(), name->utf8_length()); | |
496 } | |
497 return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); | |
498 } | |
499 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
500 |
6934 | 501 class StateRestorer; |
502 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
503 // StatefulMethodFamily is a wrapper around a MethodFamily that maintains the |
6934 | 504 // 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
|
505 // when adding members to the MethodFamily |
6934 | 506 class StatefulMethodFamily : public ResourceObj { |
507 friend class StateRestorer; | |
508 private: | |
509 QualifiedState _qualification_state; | |
510 | |
511 void set_qualification_state(QualifiedState state) { | |
512 _qualification_state = state; | |
513 } | |
514 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
515 protected: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
516 MethodFamily* _method_family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
517 |
6934 | 518 public: |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
519 StatefulMethodFamily() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
520 _method_family = new MethodFamily(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
521 _qualification_state = QUALIFIED; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
522 } |
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 StatefulMethodFamily(MethodFamily* mf) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
525 _method_family = mf; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
526 _qualification_state = QUALIFIED; |
6934 | 527 } |
528 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
529 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
|
530 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
531 MethodFamily* get_method_family() { return _method_family; } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
532 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
533 StateRestorer* record_method_and_dq_further(Method* mo); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
534 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
535 |
6934 | 536 class StateRestorer : public PseudoScopeMark { |
537 private: | |
538 StatefulMethodFamily* _method; | |
539 QualifiedState _state_to_restore; | |
540 public: | |
541 StateRestorer(StatefulMethodFamily* dm, QualifiedState state) | |
542 : _method(dm), _state_to_restore(state) {} | |
543 ~StateRestorer() { destroy(); } | |
544 void restore_state() { _method->set_qualification_state(_state_to_restore); } | |
545 virtual void destroy() { restore_state(); } | |
546 }; | |
547 | |
548 StateRestorer* StatefulMethodFamily::record_method_and_dq_further(Method* mo) { | |
549 StateRestorer* mark = new StateRestorer(this, _qualification_state); | |
550 if (_qualification_state == QUALIFIED) { | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
551 _method_family->record_qualified_method(mo); |
6934 | 552 } else { |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
553 _method_family->record_disqualified_method(mo); |
6934 | 554 } |
555 // Everything found "above"??? this method in the hierarchy walk is set to | |
556 // disqualified | |
557 set_qualification_state(DISQUALIFIED); | |
558 return mark; | |
559 } | |
560 | |
561 // Represents a location corresponding to a vtable slot for methods that | |
562 // neither the class nor any of it's ancestors provide an implementaion. | |
563 // Default methods may be present to fill this slot. | |
564 class EmptyVtableSlot : public ResourceObj { | |
565 private: | |
566 Symbol* _name; | |
567 Symbol* _signature; | |
568 int _size_of_parameters; | |
569 MethodFamily* _binding; | |
570 | |
571 public: | |
572 EmptyVtableSlot(Method* method) | |
573 : _name(method->name()), _signature(method->signature()), | |
574 _size_of_parameters(method->size_of_parameters()), _binding(NULL) {} | |
575 | |
576 Symbol* name() const { return _name; } | |
577 Symbol* signature() const { return _signature; } | |
578 int size_of_parameters() const { return _size_of_parameters; } | |
579 | |
580 void bind_family(MethodFamily* lm) { _binding = lm; } | |
581 bool is_bound() { return _binding != NULL; } | |
582 MethodFamily* get_binding() { return _binding; } | |
583 | |
584 #ifndef PRODUCT | |
585 void print_on(outputStream* str) const { | |
586 print_slot(str, name(), signature()); | |
587 } | |
588 #endif // ndef PRODUCT | |
589 }; | |
590 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
591 static bool already_in_vtable_slots(GrowableArray<EmptyVtableSlot*>* slots, Method* m) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
592 bool found = false; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
593 for (int j = 0; j < slots->length(); ++j) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
594 if (slots->at(j)->name() == m->name() && |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
595 slots->at(j)->signature() == m->signature() ) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
596 found = true; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
597 break; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
598 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
599 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
600 return found; |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
601 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
602 |
6934 | 603 static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( |
604 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { | |
605 | |
606 assert(klass != NULL, "Must be valid class"); | |
607 | |
608 GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); | |
609 | |
610 // All miranda methods are obvious candidates | |
611 for (int i = 0; i < mirandas->length(); ++i) { | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
612 Method* m = mirandas->at(i); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
613 if (!already_in_vtable_slots(slots, m)) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
614 slots->append(new EmptyVtableSlot(m)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
615 } |
6934 | 616 } |
617 | |
618 // Also any overpasses in our superclasses, that we haven't implemented. | |
619 // (can't use the vtable because it is not guaranteed to be initialized yet) | |
620 InstanceKlass* super = klass->java_super(); | |
621 while (super != NULL) { | |
622 for (int i = 0; i < super->methods()->length(); ++i) { | |
623 Method* m = super->methods()->at(i); | |
624 if (m->is_overpass()) { | |
625 // m is a method that would have been a miranda if not for the | |
626 // default method processing that occurred on behalf of our superclass, | |
627 // so it's a method we want to re-examine in this new context. That is, | |
628 // unless we have a real implementation of it in the current class. | |
629 Method* impl = klass->lookup_method(m->name(), m->signature()); | |
630 if (impl == NULL || impl->is_overpass()) { | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
631 if (!already_in_vtable_slots(slots, m)) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
632 slots->append(new EmptyVtableSlot(m)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
633 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
634 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
635 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
636 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
637 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
638 // also any default methods in our superclasses |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
639 if (super->default_methods() != NULL) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
640 for (int i = 0; i < super->default_methods()->length(); ++i) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
641 Method* m = super->default_methods()->at(i); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
642 // 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
|
643 // default method processing that occurred on behalf of our superclass, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
644 // 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
|
645 // 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
|
646 Method* impl = klass->lookup_method(m->name(), m->signature()); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
647 if (impl == NULL || impl->is_overpass()) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
648 if (!already_in_vtable_slots(slots, m)) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
649 slots->append(new EmptyVtableSlot(m)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
650 } |
6934 | 651 } |
652 } | |
653 } | |
654 super = super->java_super(); | |
655 } | |
656 | |
657 #ifndef PRODUCT | |
658 if (TraceDefaultMethods) { | |
659 tty->print_cr("Slots that need filling:"); | |
660 streamIndentor si(tty); | |
661 for (int i = 0; i < slots->length(); ++i) { | |
662 tty->indent(); | |
663 slots->at(i)->print_on(tty); | |
664 tty->print_cr(""); | |
665 } | |
666 } | |
667 #endif // ndef PRODUCT | |
668 return slots; | |
669 } | |
670 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
671 // 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
|
672 // with a specific erased signature. |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
673 class FindMethodsByErasedSig : public HierarchyVisitor<FindMethodsByErasedSig> { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
674 private: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
675 // Context data |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
676 Symbol* _method_name; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
677 Symbol* _method_signature; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
678 StatefulMethodFamily* _family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
679 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
680 public: |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
681 FindMethodsByErasedSig(Symbol* name, Symbol* signature) : |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
682 _method_name(name), _method_signature(signature), |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
683 _family(NULL) {} |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
684 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
685 void get_discovered_family(MethodFamily** family) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
686 if (_family != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
687 *family = _family->get_method_family(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
688 } else { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
689 *family = NULL; |
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 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
692 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
693 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
|
694 void free_node_data(void* node_data) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
695 PseudoScope::cast(node_data)->destroy(); |
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 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
698 // 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
|
699 // method's erased (name, signature) |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
700 bool visit() { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
701 PseudoScope* scope = PseudoScope::cast(current_data()); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
702 InstanceKlass* iklass = current_class(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
703 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
704 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
|
705 // 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
|
706 // invokespecial to private interface methods doesn't use default method logic |
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
707 // future: take access controls into account for superclass methods |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
708 if (m != NULL && !m->is_static() && (!iklass->is_interface() || m->is_public())) { |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
709 if (_family == NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
710 _family = new StatefulMethodFamily(); |
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 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
713 if (iklass->is_interface()) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
714 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
|
715 scope->add_mark(restorer); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
716 } else { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
717 // 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
|
718 // 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
|
719 _family->set_target_if_empty(m); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
720 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
721 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
722 return true; |
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 }; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
726 |
6934 | 727 |
728 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
729 static void create_defaults_and_exceptions( |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
730 GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
731 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
732 static void generate_erased_defaults( |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
733 InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots, |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
734 EmptyVtableSlot* slot, TRAPS) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
735 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
736 // 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
|
737 FindMethodsByErasedSig visitor(slot->name(), slot->signature()); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
738 visitor.run(klass); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
739 |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
740 MethodFamily* family; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
741 visitor.get_discovered_family(&family); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
742 if (family != NULL) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
743 family->determine_target(klass, CHECK); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
744 slot->bind_family(family); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
745 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
746 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
747 |
6934 | 748 static void merge_in_new_methods(InstanceKlass* klass, |
749 GrowableArray<Method*>* new_methods, TRAPS); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
750 static void create_default_methods( InstanceKlass* klass, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
751 GrowableArray<Method*>* new_methods, TRAPS); |
6934 | 752 |
753 // This is the guts of the default methods implementation. This is called just | |
754 // after the classfile has been parsed if some ancestor has default methods. | |
755 // | |
756 // First if finds any name/signature slots that need any implementation (either | |
757 // 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
|
758 // 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
|
759 // signature that matches the slot we are looking at. |
6934 | 760 // |
761 // For each slot filled, we generate an overpass method that either calls the | |
762 // unique default method candidate using invokespecial, or throws an exception | |
763 // (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
|
764 // 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
|
765 // The JVM does not create bridges nor handle generic signatures here. |
6934 | 766 void DefaultMethods::generate_default_methods( |
767 InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { | |
768 | |
769 // This resource mark is the bound for all memory allocation that takes | |
770 // place during default method processing. After this goes out of scope, | |
771 // all (Resource) objects' memory will be reclaimed. Be careful if adding an | |
772 // embedded resource mark under here as that memory can't be used outside | |
773 // whatever scope it's in. | |
774 ResourceMark rm(THREAD); | |
775 | |
776 // Keep entire hierarchy alive for the duration of the computation | |
777 KeepAliveRegistrar keepAlive(THREAD); | |
778 KeepAliveVisitor loadKeepAlive(&keepAlive); | |
779 loadKeepAlive.run(klass); | |
780 | |
781 #ifndef PRODUCT | |
782 if (TraceDefaultMethods) { | |
783 ResourceMark rm; // be careful with these! | |
784 tty->print_cr("Class %s requires default method processing", | |
785 klass->name()->as_klass_external_name()); | |
786 PrintHierarchy printer; | |
787 printer.run(klass); | |
788 } | |
789 #endif // ndef PRODUCT | |
790 | |
791 GrowableArray<EmptyVtableSlot*>* empty_slots = | |
792 find_empty_vtable_slots(klass, mirandas, CHECK); | |
793 | |
794 for (int i = 0; i < empty_slots->length(); ++i) { | |
795 EmptyVtableSlot* slot = empty_slots->at(i); | |
796 #ifndef PRODUCT | |
797 if (TraceDefaultMethods) { | |
798 streamIndentor si(tty, 2); | |
799 tty->indent().print("Looking for default methods for slot "); | |
800 slot->print_on(tty); | |
801 tty->print_cr(""); | |
802 } | |
803 #endif // ndef PRODUCT | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
804 |
12131
91b93f523ec6
8012294: remove generic handling for default methods
acorn
parents:
11104
diff
changeset
|
805 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
|
806 } |
6934 | 807 #ifndef PRODUCT |
808 if (TraceDefaultMethods) { | |
809 tty->print_cr("Creating overpasses..."); | |
810 } | |
811 #endif // ndef PRODUCT | |
812 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
813 create_defaults_and_exceptions(empty_slots, klass, CHECK); |
6934 | 814 |
815 #ifndef PRODUCT | |
816 if (TraceDefaultMethods) { | |
817 tty->print_cr("Default method processing complete"); | |
818 } | |
819 #endif // ndef PRODUCT | |
820 } | |
821 | |
12318
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
822 static int assemble_method_error( |
36b97be47bde
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
12213
diff
changeset
|
823 BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) { |
6934 | 824 |
825 Symbol* init = vmSymbols::object_initializer_name(); | |
826 Symbol* sig = vmSymbols::string_void_signature(); | |
827 | |
828 BytecodeAssembler assem(buffer, cp); | |
829 | |
830 assem._new(errorName); | |
831 assem.dup(); | |
832 assem.load_string(message); | |
833 assem.invokespecial(errorName, init, sig); | |
834 assem.athrow(); | |
835 | |
836 return 3; // max stack size: [ exception, exception, string ] | |
837 } | |
838 | |
839 static Method* new_method( | |
840 BytecodeConstantPool* cp, BytecodeBuffer* bytecodes, Symbol* name, | |
841 Symbol* sig, AccessFlags flags, int max_stack, int params, | |
842 ConstMethod::MethodType mt, TRAPS) { | |
843 | |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
844 address code_start = 0; |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
845 int code_length = 0; |
8031 | 846 InlineTableSizes sizes; |
6934 | 847 |
11104
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
848 if (bytecodes != NULL && bytecodes->length() > 0) { |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
849 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
|
850 code_length = bytecodes->length(); |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
851 } |
50257d6f5aaa
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
10377
diff
changeset
|
852 |
6934 | 853 Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), |
8031 | 854 code_length, flags, &sizes, |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7183
diff
changeset
|
855 mt, CHECK_NULL); |
6934 | 856 |
857 m->set_constants(NULL); // This will get filled in later | |
858 m->set_name_index(cp->utf8(name)); | |
859 m->set_signature_index(cp->utf8(sig)); | |
860 #ifdef CC_INTERP | |
861 ResultTypeFinder rtf(sig); | |
862 m->set_result_index(rtf.type()); | |
863 #endif | |
864 m->set_size_of_parameters(params); | |
865 m->set_max_stack(max_stack); | |
866 m->set_max_locals(params); | |
867 m->constMethod()->set_stackmap_data(NULL); | |
868 m->set_code(code_start); | |
869 | |
870 return m; | |
871 } | |
872 | |
873 static void switchover_constant_pool(BytecodeConstantPool* bpool, | |
874 InstanceKlass* klass, GrowableArray<Method*>* new_methods, TRAPS) { | |
875 | |
876 if (new_methods->length() > 0) { | |
877 ConstantPool* cp = bpool->create_constant_pool(CHECK); | |
878 if (cp != klass->constants()) { | |
879 klass->class_loader_data()->add_to_deallocate_list(klass->constants()); | |
880 klass->set_constants(cp); | |
881 cp->set_pool_holder(klass); | |
882 | |
883 for (int i = 0; i < new_methods->length(); ++i) { | |
884 new_methods->at(i)->set_constants(cp); | |
885 } | |
886 for (int i = 0; i < klass->methods()->length(); ++i) { | |
887 Method* mo = klass->methods()->at(i); | |
888 mo->set_constants(cp); | |
889 } | |
890 } | |
891 } | |
892 } | |
893 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
894 // Create default_methods list for the current class. |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
895 // With the VM only processing erased signatures, the VM only |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
896 // 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
|
897 // This allows virtual methods to override the overpass, but ensures |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
898 // 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
|
899 // or default method that is not a valid candidate. |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
900 static void create_defaults_and_exceptions( |
6934 | 901 GrowableArray<EmptyVtableSlot*>* slots, |
902 InstanceKlass* klass, TRAPS) { | |
903 | |
904 GrowableArray<Method*> overpasses; | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
905 GrowableArray<Method*> defaults; |
6934 | 906 BytecodeConstantPool bpool(klass->constants()); |
907 | |
908 for (int i = 0; i < slots->length(); ++i) { | |
909 EmptyVtableSlot* slot = slots->at(i); | |
910 | |
911 if (slot->is_bound()) { | |
912 MethodFamily* method = slot->get_binding(); | |
913 BytecodeBuffer buffer; | |
914 | |
915 #ifndef PRODUCT | |
916 if (TraceDefaultMethods) { | |
917 tty->print("for slot: "); | |
918 slot->print_on(tty); | |
919 tty->print_cr(""); | |
920 if (method->has_target()) { | |
921 method->print_selected(tty, 1); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
922 } else if (method->throws_exception()) { |
6934 | 923 method->print_exception(tty, 1); |
924 } | |
925 } | |
926 #endif // ndef PRODUCT | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
927 |
6934 | 928 if (method->has_target()) { |
929 Method* selected = method->get_selected_target(); | |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
930 if (selected->method_holder()->is_interface()) { |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
931 defaults.push(selected); |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
932 } |
6934 | 933 } else if (method->throws_exception()) { |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
934 int max_stack = assemble_method_error(&bpool, &buffer, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
935 method->get_exception_name(), method->get_exception_message(), CHECK); |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
936 AccessFlags flags = accessFlags_from( |
6934 | 937 JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
938 Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), |
6934 | 939 flags, max_stack, slot->size_of_parameters(), |
940 ConstMethod::OVERPASS, CHECK); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
941 // We push to the methods list: |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
942 // overpass methods which are exception throwing methods |
12213
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
943 if (m != NULL) { |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
944 overpasses.push(m); |
42863137168c
8024647: Default method resolution with private superclass method
acorn
parents:
12140
diff
changeset
|
945 } |
6934 | 946 } |
947 } | |
948 } | |
949 | |
950 #ifndef PRODUCT | |
951 if (TraceDefaultMethods) { | |
952 tty->print_cr("Created %d overpass methods", overpasses.length()); | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
953 tty->print_cr("Created %d default methods", defaults.length()); |
6934 | 954 } |
955 #endif // ndef PRODUCT | |
956 | |
12823
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
957 if (overpasses.length() > 0) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
958 switchover_constant_pool(&bpool, klass, &overpasses, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
959 merge_in_new_methods(klass, &overpasses, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
960 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
961 if (defaults.length() > 0) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
962 create_default_methods(klass, &defaults, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
963 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
964 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
965 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
966 static void create_default_methods( InstanceKlass* klass, |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
967 GrowableArray<Method*>* new_methods, TRAPS) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
968 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
969 int new_size = new_methods->length(); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
970 Array<Method*>* total_default_methods = MetadataFactory::new_array<Method*>( |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
971 klass->class_loader_data(), new_size, NULL, CHECK); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
972 for (int index = 0; index < new_size; index++ ) { |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
973 total_default_methods->at_put(index, new_methods->at(index)); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
974 } |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
975 Method::sort_methods(total_default_methods, false, false); |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
976 |
ac9cb1d5a202
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
12334
diff
changeset
|
977 klass->set_default_methods(total_default_methods); |
6934 | 978 } |
979 | |
980 static void sort_methods(GrowableArray<Method*>* methods) { | |
981 // Note that this must sort using the same key as is used for sorting | |
982 // methods in InstanceKlass. | |
983 bool sorted = true; | |
984 for (int i = methods->length() - 1; i > 0; --i) { | |
985 for (int j = 0; j < i; ++j) { | |
986 Method* m1 = methods->at(j); | |
987 Method* m2 = methods->at(j + 1); | |
988 if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) { | |
989 methods->at_put(j, m2); | |
990 methods->at_put(j + 1, m1); | |
991 sorted = false; | |
992 } | |
993 } | |
994 if (sorted) break; | |
995 sorted = true; | |
996 } | |
997 #ifdef ASSERT | |
998 uintptr_t prev = 0; | |
999 for (int i = 0; i < methods->length(); ++i) { | |
1000 Method* mh = methods->at(i); | |
1001 uintptr_t nv = (uintptr_t)mh->name(); | |
1002 assert(nv >= prev, "Incorrect overpass method ordering"); | |
1003 prev = nv; | |
1004 } | |
1005 #endif | |
1006 } | |
1007 | |
1008 static void merge_in_new_methods(InstanceKlass* klass, | |
1009 GrowableArray<Method*>* new_methods, TRAPS) { | |
1010 | |
1011 enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS }; | |
1012 | |
1013 Array<Method*>* original_methods = klass->methods(); | |
1014 Array<int>* original_ordering = klass->method_ordering(); | |
1015 Array<int>* merged_ordering = Universe::the_empty_int_array(); | |
1016 | |
1017 int new_size = klass->methods()->length() + new_methods->length(); | |
1018 | |
1019 Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>( | |
1020 klass->class_loader_data(), new_size, NULL, CHECK); | |
8031 | 1021 |
6934 | 1022 if (original_ordering != NULL && original_ordering->length() > 0) { |
1023 merged_ordering = MetadataFactory::new_array<int>( | |
1024 klass->class_loader_data(), new_size, CHECK); | |
1025 } | |
1026 int method_order_index = klass->methods()->length(); | |
1027 | |
1028 sort_methods(new_methods); | |
1029 | |
1030 // Perform grand merge of existing methods and new methods | |
1031 int orig_idx = 0; | |
1032 int new_idx = 0; | |
1033 | |
1034 for (int i = 0; i < new_size; ++i) { | |
1035 Method* orig_method = NULL; | |
1036 Method* new_method = NULL; | |
1037 if (orig_idx < original_methods->length()) { | |
1038 orig_method = original_methods->at(orig_idx); | |
1039 } | |
1040 if (new_idx < new_methods->length()) { | |
1041 new_method = new_methods->at(new_idx); | |
1042 } | |
1043 | |
1044 if (orig_method != NULL && | |
1045 (new_method == NULL || orig_method->name() < new_method->name())) { | |
1046 merged_methods->at_put(i, orig_method); | |
1047 original_methods->at_put(orig_idx, NULL); | |
1048 if (merged_ordering->length() > 0) { | |
1049 merged_ordering->at_put(i, original_ordering->at(orig_idx)); | |
1050 } | |
1051 ++orig_idx; | |
1052 } else { | |
1053 merged_methods->at_put(i, new_method); | |
1054 if (merged_ordering->length() > 0) { | |
1055 merged_ordering->at_put(i, method_order_index++); | |
1056 } | |
1057 ++new_idx; | |
1058 } | |
1059 // update idnum for new location | |
1060 merged_methods->at(i)->set_method_idnum(i); | |
1061 } | |
1062 | |
1063 // Verify correct order | |
1064 #ifdef ASSERT | |
1065 uintptr_t prev = 0; | |
1066 for (int i = 0; i < merged_methods->length(); ++i) { | |
1067 Method* mo = merged_methods->at(i); | |
1068 uintptr_t nv = (uintptr_t)mo->name(); | |
1069 assert(nv >= prev, "Incorrect method ordering"); | |
1070 prev = nv; | |
1071 } | |
1072 #endif | |
1073 | |
1074 // Replace klass methods with new merged lists | |
1075 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
|
1076 klass->set_initial_method_idnum(new_size); |
6934 | 1077 |
1078 ClassLoaderData* cld = klass->class_loader_data(); | |
1079 MetadataFactory::free_array(cld, original_methods); | |
1080 if (original_ordering->length() > 0) { | |
1081 klass->set_method_ordering(merged_ordering); | |
1082 MetadataFactory::free_array(cld, original_ordering); | |
1083 } | |
1084 } |