author | mchung |
Tue, 24 Nov 2015 14:59:17 -0800 | |
changeset 34280 | 72bfaaffee36 |
parent 33736 | 1b3950243443 |
child 34666 | 1c7168ea0034 |
permissions | -rw-r--r-- |
14385 | 1 |
/* |
29316
5287df8a8972
8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
27680
diff
changeset
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
14385 | 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" |
|
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
29 |
#include "logging/log.hpp" |
14385 | 30 |
#include "memory/allocation.hpp" |
31 |
#include "memory/metadataFactory.hpp" |
|
32 |
#include "memory/resourceArea.hpp" |
|
33 |
#include "runtime/signature.hpp" |
|
34 |
#include "runtime/thread.hpp" |
|
35 |
#include "oops/instanceKlass.hpp" |
|
36 |
#include "oops/klass.hpp" |
|
37 |
#include "oops/method.hpp" |
|
38 |
#include "utilities/accessFlags.hpp" |
|
39 |
#include "utilities/exceptions.hpp" |
|
40 |
#include "utilities/ostream.hpp" |
|
41 |
#include "utilities/pair.hpp" |
|
42 |
#include "utilities/resourceHash.hpp" |
|
43 |
||
44 |
typedef enum { QUALIFIED, DISQUALIFIED } QualifiedState; |
|
45 |
||
46 |
// Because we use an iterative algorithm when iterating over the type |
|
47 |
// hierarchy, we can't use traditional scoped objects which automatically do |
|
48 |
// cleanup in the destructor when the scope is exited. PseudoScope (and |
|
49 |
// PseudoScopeMark) provides a similar functionality, but for when you want a |
|
50 |
// scoped object in non-stack memory (such as in resource memory, as we do |
|
51 |
// here). You've just got to remember to call 'destroy()' on the scope when |
|
52 |
// leaving it (and marks have to be explicitly added). |
|
53 |
class PseudoScopeMark : public ResourceObj { |
|
54 |
public: |
|
55 |
virtual void destroy() = 0; |
|
56 |
}; |
|
57 |
||
58 |
class PseudoScope : public ResourceObj { |
|
59 |
private: |
|
60 |
GrowableArray<PseudoScopeMark*> _marks; |
|
61 |
public: |
|
62 |
||
63 |
static PseudoScope* cast(void* data) { |
|
64 |
return static_cast<PseudoScope*>(data); |
|
65 |
} |
|
66 |
||
67 |
void add_mark(PseudoScopeMark* psm) { |
|
68 |
_marks.append(psm); |
|
69 |
} |
|
70 |
||
71 |
void destroy() { |
|
72 |
for (int i = 0; i < _marks.length(); ++i) { |
|
73 |
_marks.at(i)->destroy(); |
|
74 |
} |
|
75 |
} |
|
76 |
}; |
|
77 |
||
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 |
||
91 |
/** |
|
92 |
* Perform a depth-first iteration over the class hierarchy, applying |
|
93 |
* algorithmic logic as it goes. |
|
94 |
* |
|
95 |
* This class is one half of the inheritance hierarchy analysis mechanism. |
|
96 |
* It is meant to be used in conjunction with another class, the algorithm, |
|
97 |
* which is indicated by the ALGO template parameter. This class can be |
|
98 |
* paired with any algorithm class that provides the required methods. |
|
99 |
* |
|
100 |
* This class contains all the mechanics for iterating over the class hierarchy |
|
101 |
* starting at a particular root, without recursing (thus limiting stack growth |
|
102 |
* from this point). It visits each superclass (if present) and superinterface |
|
103 |
* in a depth-first manner, with callbacks to the ALGO class as each class is |
|
104 |
* encountered (visit()), The algorithm can cut-off further exploration of a |
|
105 |
* particular branch by returning 'false' from a visit() call. |
|
106 |
* |
|
107 |
* The ALGO class, must provide a visit() method, which each of which will be |
|
108 |
* called once for each node in the inheritance tree during the iteration. In |
|
109 |
* addition, it can provide a memory block via new_node_data(InstanceKlass*), |
|
110 |
* which it can use for node-specific storage (and access via the |
|
111 |
* current_data() and data_at_depth(int) methods). |
|
112 |
* |
|
113 |
* Bare minimum needed to be an ALGO class: |
|
114 |
* class Algo : public HierarchyVisitor<Algo> { |
|
115 |
* void* new_node_data(InstanceKlass* cls) { return NULL; } |
|
116 |
* void free_node_data(void* data) { return; } |
|
117 |
* bool visit() { return true; } |
|
118 |
* }; |
|
119 |
*/ |
|
120 |
template <class ALGO> |
|
121 |
class HierarchyVisitor : StackObj { |
|
122 |
private: |
|
123 |
||
124 |
class Node : public ResourceObj { |
|
125 |
public: |
|
126 |
InstanceKlass* _class; |
|
127 |
bool _super_was_visited; |
|
128 |
int _interface_index; |
|
129 |
void* _algorithm_data; |
|
130 |
||
131 |
Node(InstanceKlass* cls, void* data, bool visit_super) |
|
132 |
: _class(cls), _super_was_visited(!visit_super), |
|
133 |
_interface_index(0), _algorithm_data(data) {} |
|
134 |
||
135 |
int number_of_interfaces() { return _class->local_interfaces()->length(); } |
|
136 |
int interface_index() { return _interface_index; } |
|
137 |
void set_super_visited() { _super_was_visited = true; } |
|
138 |
void increment_visited_interface() { ++_interface_index; } |
|
139 |
void set_all_interfaces_visited() { |
|
140 |
_interface_index = number_of_interfaces(); |
|
141 |
} |
|
142 |
bool has_visited_super() { return _super_was_visited; } |
|
143 |
bool has_visited_all_interfaces() { |
|
144 |
return interface_index() >= number_of_interfaces(); |
|
145 |
} |
|
146 |
InstanceKlass* interface_at(int index) { |
|
147 |
return InstanceKlass::cast(_class->local_interfaces()->at(index)); |
|
148 |
} |
|
149 |
InstanceKlass* next_super() { return _class->java_super(); } |
|
150 |
InstanceKlass* next_interface() { |
|
151 |
return interface_at(interface_index()); |
|
152 |
} |
|
153 |
}; |
|
154 |
||
155 |
bool _cancelled; |
|
156 |
GrowableArray<Node*> _path; |
|
157 |
||
158 |
Node* current_top() const { return _path.top(); } |
|
159 |
bool has_more_nodes() const { return !_path.is_empty(); } |
|
160 |
void push(InstanceKlass* cls, void* data) { |
|
161 |
assert(cls != NULL, "Requires a valid instance class"); |
|
162 |
Node* node = new Node(cls, data, has_super(cls)); |
|
163 |
_path.push(node); |
|
164 |
} |
|
165 |
void pop() { _path.pop(); } |
|
166 |
||
167 |
void reset_iteration() { |
|
168 |
_cancelled = false; |
|
169 |
_path.clear(); |
|
170 |
} |
|
171 |
bool is_cancelled() const { return _cancelled; } |
|
172 |
||
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
173 |
// This code used to skip interface classes because their only |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
174 |
// superclass was j.l.Object which would be also covered by class |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
175 |
// superclass hierarchy walks. Now that the starting point can be |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
176 |
// an interface, we must ensure we catch j.l.Object as the super. |
14385 | 177 |
static bool has_super(InstanceKlass* cls) { |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
178 |
return cls->super() != NULL; |
14385 | 179 |
} |
180 |
||
181 |
Node* node_at_depth(int i) const { |
|
182 |
return (i >= _path.length()) ? NULL : _path.at(_path.length() - i - 1); |
|
183 |
} |
|
184 |
||
185 |
protected: |
|
186 |
||
187 |
// Accessors available to the algorithm |
|
188 |
int current_depth() const { return _path.length() - 1; } |
|
189 |
||
190 |
InstanceKlass* class_at_depth(int i) { |
|
191 |
Node* n = node_at_depth(i); |
|
192 |
return n == NULL ? NULL : n->_class; |
|
193 |
} |
|
194 |
InstanceKlass* current_class() { return class_at_depth(0); } |
|
195 |
||
196 |
void* data_at_depth(int i) { |
|
197 |
Node* n = node_at_depth(i); |
|
198 |
return n == NULL ? NULL : n->_algorithm_data; |
|
199 |
} |
|
200 |
void* current_data() { return data_at_depth(0); } |
|
201 |
||
202 |
void cancel_iteration() { _cancelled = true; } |
|
203 |
||
204 |
public: |
|
205 |
||
206 |
void run(InstanceKlass* root) { |
|
207 |
ALGO* algo = static_cast<ALGO*>(this); |
|
208 |
||
209 |
reset_iteration(); |
|
210 |
||
211 |
void* algo_data = algo->new_node_data(root); |
|
212 |
push(root, algo_data); |
|
213 |
bool top_needs_visit = true; |
|
214 |
||
215 |
do { |
|
216 |
Node* top = current_top(); |
|
217 |
if (top_needs_visit) { |
|
218 |
if (algo->visit() == false) { |
|
219 |
// algorithm does not want to continue along this path. Arrange |
|
220 |
// it so that this state is immediately popped off the stack |
|
221 |
top->set_super_visited(); |
|
222 |
top->set_all_interfaces_visited(); |
|
223 |
} |
|
224 |
top_needs_visit = false; |
|
225 |
} |
|
226 |
||
227 |
if (top->has_visited_super() && top->has_visited_all_interfaces()) { |
|
228 |
algo->free_node_data(top->_algorithm_data); |
|
229 |
pop(); |
|
230 |
} else { |
|
231 |
InstanceKlass* next = NULL; |
|
232 |
if (top->has_visited_super() == false) { |
|
233 |
next = top->next_super(); |
|
234 |
top->set_super_visited(); |
|
235 |
} else { |
|
236 |
next = top->next_interface(); |
|
237 |
top->increment_visited_interface(); |
|
238 |
} |
|
239 |
assert(next != NULL, "Otherwise we shouldn't be here"); |
|
240 |
algo_data = algo->new_node_data(next); |
|
241 |
push(next, algo_data); |
|
242 |
top_needs_visit = true; |
|
243 |
} |
|
244 |
} while (!is_cancelled() && has_more_nodes()); |
|
245 |
} |
|
246 |
}; |
|
247 |
||
248 |
class PrintHierarchy : public HierarchyVisitor<PrintHierarchy> { |
|
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
249 |
private: |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
250 |
outputStream* _st; |
14385 | 251 |
public: |
252 |
bool visit() { |
|
253 |
InstanceKlass* cls = current_class(); |
|
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
254 |
streamIndentor si(_st, current_depth() * 2); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
255 |
_st->indent().print_cr("%s", cls->name()->as_C_string()); |
14385 | 256 |
return true; |
257 |
} |
|
258 |
||
259 |
void* new_node_data(InstanceKlass* cls) { return NULL; } |
|
260 |
void free_node_data(void* data) { return; } |
|
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
261 |
|
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
262 |
PrintHierarchy(outputStream* st = tty) : _st(st) {} |
14385 | 263 |
}; |
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 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
316 |
|
14385 | 317 |
// A method family contains a set of all methods that implement a single |
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
318 |
// erased method. As members of the set are collected while walking over the |
14385 | 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 |
|
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
322 |
// erased method defined in an interface. |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
323 |
|
14385 | 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 |
|
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
332 |
Symbol* _exception_name; // If no unique target is found |
14385 | 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); |
|
16379
02ed75a9a421
8009578: [parfait] Null pointer deference in hotspot/src/share/vm/classfile/defaultMethods.cpp
morris
parents:
15601
diff
changeset
|
347 |
guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); |
14385 | 348 |
_members.at(*index).second = DISQUALIFIED; |
349 |
} |
|
350 |
||
351 |
Symbol* generate_no_defaults_message(TRAPS) const; |
|
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
352 |
Symbol* generate_method_message(Symbol *klass_name, Method* method, TRAPS) const; |
14385 | 353 |
Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const; |
354 |
||
355 |
public: |
|
356 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
357 |
MethodFamily() |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
358 |
: _selected_target(NULL), _exception_message(NULL), _exception_name(NULL) {} |
14385 | 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; } |
|
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
391 |
Symbol* get_exception_name() { return _exception_name; } |
14385 | 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 |
||
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
399 |
// Qualified methods are maximally-specific methods |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
400 |
// These include public, instance concrete (=default) and abstract methods |
14385 | 401 |
GrowableArray<Method*> qualified_methods; |
21516
8fa5308ab970
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
20710
diff
changeset
|
402 |
int num_defaults = 0; |
8fa5308ab970
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
20710
diff
changeset
|
403 |
int default_index = -1; |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
404 |
int qualified_index = -1; |
14385 | 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); |
|
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
409 |
qualified_index++; |
21516
8fa5308ab970
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
20710
diff
changeset
|
410 |
if (entry.first->is_default_method()) { |
8fa5308ab970
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
20710
diff
changeset
|
411 |
num_defaults++; |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
412 |
default_index = qualified_index; |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
413 |
|
21516
8fa5308ab970
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
20710
diff
changeset
|
414 |
} |
14385 | 415 |
} |
416 |
} |
|
417 |
||
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
418 |
if (num_defaults == 0) { |
22493
af3de4cee5e5
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
22233
diff
changeset
|
419 |
// If the root klass has a static method with matching name and signature |
af3de4cee5e5
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
22233
diff
changeset
|
420 |
// then do not generate an overpass method because it will hide the |
af3de4cee5e5
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
22233
diff
changeset
|
421 |
// static method during resolution. |
23999
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22493
diff
changeset
|
422 |
if (qualified_methods.length() == 0) { |
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22493
diff
changeset
|
423 |
_exception_message = generate_no_defaults_message(CHECK); |
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22493
diff
changeset
|
424 |
} else { |
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22493
diff
changeset
|
425 |
assert(root != NULL, "Null root class"); |
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22493
diff
changeset
|
426 |
_exception_message = generate_method_message(root->name(), qualified_methods.at(0), CHECK); |
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
427 |
} |
23999
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22493
diff
changeset
|
428 |
_exception_name = vmSymbols::java_lang_AbstractMethodError(); |
22493
af3de4cee5e5
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
22233
diff
changeset
|
429 |
|
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
430 |
// If only one qualified method is default, select that |
21516
8fa5308ab970
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
20710
diff
changeset
|
431 |
} else if (num_defaults == 1) { |
8fa5308ab970
8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents:
20710
diff
changeset
|
432 |
_selected_target = qualified_methods.at(default_index); |
22493
af3de4cee5e5
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
22233
diff
changeset
|
433 |
|
23999
22eb7be3d99d
8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents:
22493
diff
changeset
|
434 |
} else if (num_defaults > 1) { |
22493
af3de4cee5e5
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
22233
diff
changeset
|
435 |
_exception_message = generate_conflicts_message(&qualified_methods,CHECK); |
af3de4cee5e5
8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents:
22233
diff
changeset
|
436 |
_exception_name = vmSymbols::java_lang_IncompatibleClassChangeError(); |
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
437 |
if (log_is_enabled(Debug, defaultmethods)) { |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
438 |
ResourceMark rm; |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
439 |
outputStream* logstream = LogHandle(defaultmethods)::debug_stream(); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
440 |
_exception_message->print_value_on(logstream); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
441 |
logstream->cr(); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
442 |
} |
14385 | 443 |
} |
444 |
} |
|
445 |
||
446 |
bool contains_signature(Symbol* query) { |
|
447 |
for (int i = 0; i < _members.length(); ++i) { |
|
448 |
if (query == _members.at(i).first->signature()) { |
|
449 |
return true; |
|
450 |
} |
|
451 |
} |
|
452 |
return false; |
|
453 |
} |
|
454 |
||
455 |
void print_selected(outputStream* str, int indent) const { |
|
456 |
assert(has_target(), "Should be called otherwise"); |
|
457 |
streamIndentor si(str, indent * 2); |
|
458 |
str->indent().print("Selected method: "); |
|
459 |
print_method(str, _selected_target); |
|
19966
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
460 |
Klass* method_holder = _selected_target->method_holder(); |
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
461 |
if (!method_holder->is_interface()) { |
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
462 |
str->print(" : in superclass"); |
19966
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
463 |
} |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23999
diff
changeset
|
464 |
str->cr(); |
14385 | 465 |
} |
466 |
||
467 |
void print_exception(outputStream* str, int indent) { |
|
468 |
assert(throws_exception(), "Should be called otherwise"); |
|
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
469 |
assert(_exception_name != NULL, "exception_name should be set"); |
14385 | 470 |
streamIndentor si(str, indent * 2); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
471 |
str->indent().print_cr("%s: %s", _exception_name->as_C_string(), _exception_message->as_C_string()); |
14385 | 472 |
} |
473 |
}; |
|
474 |
||
475 |
Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { |
|
27680
8ecc0871c18e
8064811: Use THREAD instead of CHECK_NULL in return statements
stefank
parents:
27677
diff
changeset
|
476 |
return SymbolTable::new_symbol("No qualifying defaults found", THREAD); |
14385 | 477 |
} |
478 |
||
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
479 |
Symbol* MethodFamily::generate_method_message(Symbol *klass_name, Method* method, TRAPS) const { |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
480 |
stringStream ss; |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
481 |
ss.print("Method "); |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
482 |
Symbol* name = method->name(); |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
483 |
Symbol* signature = method->signature(); |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
484 |
ss.write((const char*)klass_name->bytes(), klass_name->utf8_length()); |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
485 |
ss.print("."); |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
486 |
ss.write((const char*)name->bytes(), name->utf8_length()); |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
487 |
ss.write((const char*)signature->bytes(), signature->utf8_length()); |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
488 |
ss.print(" is abstract"); |
27677 | 489 |
return SymbolTable::new_symbol(ss.base(), (int)ss.size(), THREAD); |
22232
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
490 |
} |
26acfad336c0
8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents:
21913
diff
changeset
|
491 |
|
14385 | 492 |
Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { |
493 |
stringStream ss; |
|
494 |
ss.print("Conflicting default methods:"); |
|
495 |
for (int i = 0; i < methods->length(); ++i) { |
|
496 |
Method* method = methods->at(i); |
|
497 |
Symbol* klass = method->klass_name(); |
|
498 |
Symbol* name = method->name(); |
|
499 |
ss.print(" "); |
|
500 |
ss.write((const char*)klass->bytes(), klass->utf8_length()); |
|
501 |
ss.print("."); |
|
502 |
ss.write((const char*)name->bytes(), name->utf8_length()); |
|
503 |
} |
|
27677 | 504 |
return SymbolTable::new_symbol(ss.base(), (int)ss.size(), THREAD); |
14385 | 505 |
} |
506 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
507 |
|
14385 | 508 |
class StateRestorer; |
509 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
510 |
// StatefulMethodFamily is a wrapper around a MethodFamily that maintains the |
14385 | 511 |
// qualification state during hierarchy visitation, and applies that state |
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
512 |
// when adding members to the MethodFamily |
14385 | 513 |
class StatefulMethodFamily : public ResourceObj { |
514 |
friend class StateRestorer; |
|
515 |
private: |
|
516 |
QualifiedState _qualification_state; |
|
517 |
||
518 |
void set_qualification_state(QualifiedState state) { |
|
519 |
_qualification_state = state; |
|
520 |
} |
|
521 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
522 |
protected: |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
523 |
MethodFamily* _method_family; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
524 |
|
14385 | 525 |
public: |
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
526 |
StatefulMethodFamily() { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
527 |
_method_family = new MethodFamily(); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
528 |
_qualification_state = QUALIFIED; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
529 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
530 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
531 |
StatefulMethodFamily(MethodFamily* mf) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
532 |
_method_family = mf; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
533 |
_qualification_state = QUALIFIED; |
14385 | 534 |
} |
535 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
536 |
void set_target_if_empty(Method* m) { _method_family->set_target_if_empty(m); } |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
537 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
538 |
MethodFamily* get_method_family() { return _method_family; } |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
539 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
540 |
StateRestorer* record_method_and_dq_further(Method* mo); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
541 |
}; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
542 |
|
14385 | 543 |
class StateRestorer : public PseudoScopeMark { |
544 |
private: |
|
545 |
StatefulMethodFamily* _method; |
|
546 |
QualifiedState _state_to_restore; |
|
547 |
public: |
|
548 |
StateRestorer(StatefulMethodFamily* dm, QualifiedState state) |
|
549 |
: _method(dm), _state_to_restore(state) {} |
|
550 |
~StateRestorer() { destroy(); } |
|
551 |
void restore_state() { _method->set_qualification_state(_state_to_restore); } |
|
552 |
virtual void destroy() { restore_state(); } |
|
553 |
}; |
|
554 |
||
555 |
StateRestorer* StatefulMethodFamily::record_method_and_dq_further(Method* mo) { |
|
556 |
StateRestorer* mark = new StateRestorer(this, _qualification_state); |
|
557 |
if (_qualification_state == QUALIFIED) { |
|
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
558 |
_method_family->record_qualified_method(mo); |
14385 | 559 |
} else { |
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
560 |
_method_family->record_disqualified_method(mo); |
14385 | 561 |
} |
562 |
// Everything found "above"??? this method in the hierarchy walk is set to |
|
563 |
// disqualified |
|
564 |
set_qualification_state(DISQUALIFIED); |
|
565 |
return mark; |
|
566 |
} |
|
567 |
||
568 |
// Represents a location corresponding to a vtable slot for methods that |
|
569 |
// neither the class nor any of it's ancestors provide an implementaion. |
|
570 |
// Default methods may be present to fill this slot. |
|
571 |
class EmptyVtableSlot : public ResourceObj { |
|
572 |
private: |
|
573 |
Symbol* _name; |
|
574 |
Symbol* _signature; |
|
575 |
int _size_of_parameters; |
|
576 |
MethodFamily* _binding; |
|
577 |
||
578 |
public: |
|
579 |
EmptyVtableSlot(Method* method) |
|
580 |
: _name(method->name()), _signature(method->signature()), |
|
581 |
_size_of_parameters(method->size_of_parameters()), _binding(NULL) {} |
|
582 |
||
583 |
Symbol* name() const { return _name; } |
|
584 |
Symbol* signature() const { return _signature; } |
|
585 |
int size_of_parameters() const { return _size_of_parameters; } |
|
586 |
||
587 |
void bind_family(MethodFamily* lm) { _binding = lm; } |
|
588 |
bool is_bound() { return _binding != NULL; } |
|
589 |
MethodFamily* get_binding() { return _binding; } |
|
590 |
||
591 |
void print_on(outputStream* str) const { |
|
592 |
print_slot(str, name(), signature()); |
|
593 |
} |
|
594 |
}; |
|
595 |
||
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
596 |
static bool already_in_vtable_slots(GrowableArray<EmptyVtableSlot*>* slots, Method* m) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
597 |
bool found = false; |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
598 |
for (int j = 0; j < slots->length(); ++j) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
599 |
if (slots->at(j)->name() == m->name() && |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
600 |
slots->at(j)->signature() == m->signature() ) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
601 |
found = true; |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
602 |
break; |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
603 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
604 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
605 |
return found; |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
606 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
607 |
|
14385 | 608 |
static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( |
609 |
InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { |
|
610 |
||
611 |
assert(klass != NULL, "Must be valid class"); |
|
612 |
||
613 |
GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); |
|
614 |
||
615 |
// All miranda methods are obvious candidates |
|
616 |
for (int i = 0; i < mirandas->length(); ++i) { |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
617 |
Method* m = mirandas->at(i); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
618 |
if (!already_in_vtable_slots(slots, m)) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
619 |
slots->append(new EmptyVtableSlot(m)); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
620 |
} |
14385 | 621 |
} |
622 |
||
623 |
// Also any overpasses in our superclasses, that we haven't implemented. |
|
624 |
// (can't use the vtable because it is not guaranteed to be initialized yet) |
|
625 |
InstanceKlass* super = klass->java_super(); |
|
626 |
while (super != NULL) { |
|
627 |
for (int i = 0; i < super->methods()->length(); ++i) { |
|
628 |
Method* m = super->methods()->at(i); |
|
21913
0e2fd7282ac6
8028438: static superclass method masks default methods
acorn
parents:
21556
diff
changeset
|
629 |
if (m->is_overpass() || m->is_static()) { |
14385 | 630 |
// m is a method that would have been a miranda if not for the |
631 |
// default method processing that occurred on behalf of our superclass, |
|
632 |
// so it's a method we want to re-examine in this new context. That is, |
|
633 |
// unless we have a real implementation of it in the current class. |
|
634 |
Method* impl = klass->lookup_method(m->name(), m->signature()); |
|
21913
0e2fd7282ac6
8028438: static superclass method masks default methods
acorn
parents:
21556
diff
changeset
|
635 |
if (impl == NULL || impl->is_overpass() || impl->is_static()) { |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
636 |
if (!already_in_vtable_slots(slots, m)) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
637 |
slots->append(new EmptyVtableSlot(m)); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
638 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
639 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
640 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
641 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
642 |
|
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
643 |
// also any default methods in our superclasses |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
644 |
if (super->default_methods() != NULL) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
645 |
for (int i = 0; i < super->default_methods()->length(); ++i) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
646 |
Method* m = super->default_methods()->at(i); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
647 |
// m is a method that would have been a miranda if not for the |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
648 |
// default method processing that occurred on behalf of our superclass, |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
649 |
// so it's a method we want to re-examine in this new context. That is, |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
650 |
// unless we have a real implementation of it in the current class. |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
651 |
Method* impl = klass->lookup_method(m->name(), m->signature()); |
21913
0e2fd7282ac6
8028438: static superclass method masks default methods
acorn
parents:
21556
diff
changeset
|
652 |
if (impl == NULL || impl->is_overpass() || impl->is_static()) { |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
653 |
if (!already_in_vtable_slots(slots, m)) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
654 |
slots->append(new EmptyVtableSlot(m)); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
655 |
} |
14385 | 656 |
} |
657 |
} |
|
658 |
} |
|
659 |
super = super->java_super(); |
|
660 |
} |
|
661 |
||
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
662 |
if (log_is_enabled(Debug, defaultmethods)) { |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
663 |
log_debug(defaultmethods)("Slots that need filling:"); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
664 |
ResourceMark rm; |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
665 |
outputStream* logstream = LogHandle(defaultmethods)::debug_stream(); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
666 |
streamIndentor si(logstream); |
14385 | 667 |
for (int i = 0; i < slots->length(); ++i) { |
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
668 |
logstream->indent(); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
669 |
slots->at(i)->print_on(logstream); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
670 |
logstream->cr(); |
14385 | 671 |
} |
672 |
} |
|
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
673 |
|
14385 | 674 |
return slots; |
675 |
} |
|
676 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
677 |
// Iterates over the superinterface type hierarchy looking for all methods |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
678 |
// with a specific erased signature. |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
679 |
class FindMethodsByErasedSig : public HierarchyVisitor<FindMethodsByErasedSig> { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
680 |
private: |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
681 |
// Context data |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
682 |
Symbol* _method_name; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
683 |
Symbol* _method_signature; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
684 |
StatefulMethodFamily* _family; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
685 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
686 |
public: |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
687 |
FindMethodsByErasedSig(Symbol* name, Symbol* signature) : |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
688 |
_method_name(name), _method_signature(signature), |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
689 |
_family(NULL) {} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
690 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
691 |
void get_discovered_family(MethodFamily** family) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
692 |
if (_family != NULL) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
693 |
*family = _family->get_method_family(); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
694 |
} else { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
695 |
*family = NULL; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
696 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
697 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
698 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
699 |
void* new_node_data(InstanceKlass* cls) { return new PseudoScope(); } |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
700 |
void free_node_data(void* node_data) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
701 |
PseudoScope::cast(node_data)->destroy(); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
702 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
703 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
704 |
// Find all methods on this hierarchy that match this |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
705 |
// method's erased (name, signature) |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
706 |
bool visit() { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
707 |
PseudoScope* scope = PseudoScope::cast(current_data()); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
708 |
InstanceKlass* iklass = current_class(); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
709 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
710 |
Method* m = iklass->find_method(_method_name, _method_signature); |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
711 |
// private interface methods are not candidates for default methods |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
712 |
// invokespecial to private interface methods doesn't use default method logic |
29871 | 713 |
// private class methods are not candidates for default methods, |
714 |
// private methods do not override default methods, so need to perform |
|
715 |
// default method inheritance without including private methods |
|
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
716 |
// The overpasses are your supertypes' errors, we do not include them |
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
717 |
// future: take access controls into account for superclass methods |
29871 | 718 |
if (m != NULL && !m->is_static() && !m->is_overpass() && !m->is_private()) { |
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
719 |
if (_family == NULL) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
720 |
_family = new StatefulMethodFamily(); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
721 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
722 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
723 |
if (iklass->is_interface()) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
724 |
StateRestorer* restorer = _family->record_method_and_dq_further(m); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
725 |
scope->add_mark(restorer); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
726 |
} else { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
727 |
// This is the rule that methods in classes "win" (bad word) over |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
728 |
// methods in interfaces. This works because of single inheritance |
29871 | 729 |
// private methods in classes do not "win", they will be found |
730 |
// first on searching, but overriding for invokevirtual needs |
|
731 |
// to find default method candidates for the same signature |
|
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
732 |
_family->set_target_if_empty(m); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
733 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
734 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
735 |
return true; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
736 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
737 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
738 |
}; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
739 |
|
14385 | 740 |
|
741 |
||
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
742 |
static void create_defaults_and_exceptions( |
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
743 |
GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
744 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
745 |
static void generate_erased_defaults( |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
746 |
InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots, |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
747 |
EmptyVtableSlot* slot, TRAPS) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
748 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
749 |
// sets up a set of methods with the same exact erased signature |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
750 |
FindMethodsByErasedSig visitor(slot->name(), slot->signature()); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
751 |
visitor.run(klass); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
752 |
|
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
753 |
MethodFamily* family; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
754 |
visitor.get_discovered_family(&family); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
755 |
if (family != NULL) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
756 |
family->determine_target(klass, CHECK); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
757 |
slot->bind_family(family); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
758 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
759 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
760 |
|
14385 | 761 |
static void merge_in_new_methods(InstanceKlass* klass, |
762 |
GrowableArray<Method*>* new_methods, TRAPS); |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
763 |
static void create_default_methods( InstanceKlass* klass, |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
764 |
GrowableArray<Method*>* new_methods, TRAPS); |
14385 | 765 |
|
766 |
// This is the guts of the default methods implementation. This is called just |
|
767 |
// after the classfile has been parsed if some ancestor has default methods. |
|
768 |
// |
|
769 |
// First if finds any name/signature slots that need any implementation (either |
|
770 |
// because they are miranda or a superclass's implementation is an overpass |
|
19681
1b35da7b1d85
8012294: remove generic handling for default methods
acorn
parents:
18695
diff
changeset
|
771 |
// itself). For each slot, iterate over the hierarchy, to see if they contain a |
1b35da7b1d85
8012294: remove generic handling for default methods
acorn
parents:
18695
diff
changeset
|
772 |
// signature that matches the slot we are looking at. |
14385 | 773 |
// |
774 |
// For each slot filled, we generate an overpass method that either calls the |
|
775 |
// unique default method candidate using invokespecial, or throws an exception |
|
776 |
// (in the case of no default method candidates, or more than one valid |
|
19681
1b35da7b1d85
8012294: remove generic handling for default methods
acorn
parents:
18695
diff
changeset
|
777 |
// candidate). These methods are then added to the class's method list. |
1b35da7b1d85
8012294: remove generic handling for default methods
acorn
parents:
18695
diff
changeset
|
778 |
// The JVM does not create bridges nor handle generic signatures here. |
14385 | 779 |
void DefaultMethods::generate_default_methods( |
780 |
InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { |
|
781 |
||
782 |
// This resource mark is the bound for all memory allocation that takes |
|
783 |
// place during default method processing. After this goes out of scope, |
|
784 |
// all (Resource) objects' memory will be reclaimed. Be careful if adding an |
|
785 |
// embedded resource mark under here as that memory can't be used outside |
|
786 |
// whatever scope it's in. |
|
787 |
ResourceMark rm(THREAD); |
|
788 |
||
789 |
// Keep entire hierarchy alive for the duration of the computation |
|
790 |
KeepAliveRegistrar keepAlive(THREAD); |
|
791 |
KeepAliveVisitor loadKeepAlive(&keepAlive); |
|
792 |
loadKeepAlive.run(klass); |
|
793 |
||
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
794 |
if (log_is_enabled(Debug, defaultmethods)) { |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
795 |
ResourceMark rm; |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
796 |
log_debug(defaultmethods)("%s %s requires default method processing", |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
797 |
klass->is_interface() ? "Interface" : "Class", |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
798 |
klass->name()->as_klass_external_name()); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
799 |
PrintHierarchy printer(LogHandle(defaultmethods)::debug_stream()); |
14385 | 800 |
printer.run(klass); |
801 |
} |
|
802 |
||
803 |
GrowableArray<EmptyVtableSlot*>* empty_slots = |
|
804 |
find_empty_vtable_slots(klass, mirandas, CHECK); |
|
805 |
||
806 |
for (int i = 0; i < empty_slots->length(); ++i) { |
|
807 |
EmptyVtableSlot* slot = empty_slots->at(i); |
|
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
808 |
if (log_is_enabled(Debug, defaultmethods)) { |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
809 |
outputStream* logstream = LogHandle(defaultmethods)::debug_stream(); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
810 |
streamIndentor si(logstream, 2); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
811 |
logstream->indent().print("Looking for default methods for slot "); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
812 |
slot->print_on(logstream); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
813 |
logstream->cr(); |
14385 | 814 |
} |
19681
1b35da7b1d85
8012294: remove generic handling for default methods
acorn
parents:
18695
diff
changeset
|
815 |
generate_erased_defaults(klass, empty_slots, slot, CHECK); |
14385 | 816 |
} |
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
817 |
log_debug(defaultmethods)("Creating defaults and overpasses..."); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
818 |
create_defaults_and_exceptions(empty_slots, klass, CHECK); |
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
819 |
log_debug(defaultmethods)("Default method processing complete"); |
14385 | 820 |
} |
821 |
||
20284
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
822 |
static int assemble_method_error( |
595a25ab9474
8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents:
19966
diff
changeset
|
823 |
BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) { |
14385 | 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 |
||
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
844 |
address code_start = 0; |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
845 |
int code_length = 0; |
15601 | 846 |
InlineTableSizes sizes; |
14385 | 847 |
|
18695
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
848 |
if (bytecodes != NULL && bytecodes->length() > 0) { |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
849 |
code_start = static_cast<address>(bytecodes->adr_at(0)); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
850 |
code_length = bytecodes->length(); |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
851 |
} |
be902722fe0a
8013635: VM should no longer create bridges for generic signatures.
acorn
parents:
17859
diff
changeset
|
852 |
|
14385 | 853 |
Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), |
15601 | 854 |
code_length, flags, &sizes, |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
14586
diff
changeset
|
855 |
mt, CHECK_NULL); |
14385 | 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 |
||
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
894 |
// Create default_methods list for the current class. |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
895 |
// With the VM only processing erased signatures, the VM only |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
896 |
// creates an overpass in a conflict case or a case with no candidates. |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
897 |
// This allows virtual methods to override the overpass, but ensures |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
898 |
// that a local method search will find the exception rather than an abstract |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
899 |
// or default method that is not a valid candidate. |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
900 |
static void create_defaults_and_exceptions( |
14385 | 901 |
GrowableArray<EmptyVtableSlot*>* slots, |
902 |
InstanceKlass* klass, TRAPS) { |
|
903 |
||
904 |
GrowableArray<Method*> overpasses; |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
905 |
GrowableArray<Method*> defaults; |
14385 | 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 |
||
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
915 |
if (log_is_enabled(Debug, defaultmethods)) { |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
916 |
ResourceMark rm; |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
917 |
outputStream* logstream = LogHandle(defaultmethods)::debug_stream(); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
918 |
logstream->print("for slot: "); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
919 |
slot->print_on(logstream); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
920 |
logstream->cr(); |
14385 | 921 |
if (method->has_target()) { |
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
922 |
method->print_selected(logstream, 1); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
923 |
} else if (method->throws_exception()) { |
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
924 |
method->print_exception(logstream, 1); |
14385 | 925 |
} |
926 |
} |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
927 |
|
14385 | 928 |
if (method->has_target()) { |
929 |
Method* selected = method->get_selected_target(); |
|
19966
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
930 |
if (selected->method_holder()->is_interface()) { |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
931 |
defaults.push(selected); |
19966
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
932 |
} |
14385 | 933 |
} else if (method->throws_exception()) { |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
934 |
int max_stack = assemble_method_error(&bpool, &buffer, |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
935 |
method->get_exception_name(), method->get_exception_message(), CHECK); |
19966
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
936 |
AccessFlags flags = accessFlags_from( |
14385 | 937 |
JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); |
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
938 |
Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), |
14385 | 939 |
flags, max_stack, slot->size_of_parameters(), |
940 |
ConstMethod::OVERPASS, CHECK); |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
941 |
// We push to the methods list: |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
942 |
// overpass methods which are exception throwing methods |
19966
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
943 |
if (m != NULL) { |
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
944 |
overpasses.push(m); |
64732b96b5f5
8024647: Default method resolution with private superclass method
acorn
parents:
19690
diff
changeset
|
945 |
} |
14385 | 946 |
} |
947 |
} |
|
948 |
} |
|
949 |
||
33736
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
950 |
|
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
951 |
log_debug(defaultmethods)("Created %d overpass methods", overpasses.length()); |
1b3950243443
8139564: Convert TraceDefaultMethods to Unified Logging
rprotacio
parents:
29871
diff
changeset
|
952 |
log_debug(defaultmethods)("Created %d default methods", defaults.length()); |
14385 | 953 |
|
20391
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
954 |
if (overpasses.length() > 0) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
955 |
switchover_constant_pool(&bpool, klass, &overpasses, CHECK); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
956 |
merge_in_new_methods(klass, &overpasses, CHECK); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
957 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
958 |
if (defaults.length() > 0) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
959 |
create_default_methods(klass, &defaults, CHECK); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
960 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
961 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
962 |
|
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
963 |
static void create_default_methods( InstanceKlass* klass, |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
964 |
GrowableArray<Method*>* new_methods, TRAPS) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
965 |
|
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
966 |
int new_size = new_methods->length(); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
967 |
Array<Method*>* total_default_methods = MetadataFactory::new_array<Method*>( |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
968 |
klass->class_loader_data(), new_size, NULL, CHECK); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
969 |
for (int index = 0; index < new_size; index++ ) { |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
970 |
total_default_methods->at_put(index, new_methods->at(index)); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
971 |
} |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
972 |
Method::sort_methods(total_default_methods, false, false); |
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
973 |
|
7b146c5ebb18
8009130: Lambda: Fix access controls, loader constraints.
acorn
parents:
20300
diff
changeset
|
974 |
klass->set_default_methods(total_default_methods); |
14385 | 975 |
} |
976 |
||
977 |
static void sort_methods(GrowableArray<Method*>* methods) { |
|
978 |
// Note that this must sort using the same key as is used for sorting |
|
979 |
// methods in InstanceKlass. |
|
980 |
bool sorted = true; |
|
981 |
for (int i = methods->length() - 1; i > 0; --i) { |
|
982 |
for (int j = 0; j < i; ++j) { |
|
983 |
Method* m1 = methods->at(j); |
|
984 |
Method* m2 = methods->at(j + 1); |
|
985 |
if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) { |
|
986 |
methods->at_put(j, m2); |
|
987 |
methods->at_put(j + 1, m1); |
|
988 |
sorted = false; |
|
989 |
} |
|
990 |
} |
|
991 |
if (sorted) break; |
|
992 |
sorted = true; |
|
993 |
} |
|
994 |
#ifdef ASSERT |
|
995 |
uintptr_t prev = 0; |
|
996 |
for (int i = 0; i < methods->length(); ++i) { |
|
997 |
Method* mh = methods->at(i); |
|
998 |
uintptr_t nv = (uintptr_t)mh->name(); |
|
999 |
assert(nv >= prev, "Incorrect overpass method ordering"); |
|
1000 |
prev = nv; |
|
1001 |
} |
|
1002 |
#endif |
|
1003 |
} |
|
1004 |
||
1005 |
static void merge_in_new_methods(InstanceKlass* klass, |
|
1006 |
GrowableArray<Method*>* new_methods, TRAPS) { |
|
1007 |
||
1008 |
enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS }; |
|
1009 |
||
1010 |
Array<Method*>* original_methods = klass->methods(); |
|
1011 |
Array<int>* original_ordering = klass->method_ordering(); |
|
1012 |
Array<int>* merged_ordering = Universe::the_empty_int_array(); |
|
1013 |
||
1014 |
int new_size = klass->methods()->length() + new_methods->length(); |
|
1015 |
||
1016 |
Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>( |
|
1017 |
klass->class_loader_data(), new_size, NULL, CHECK); |
|
15601 | 1018 |
|
22233
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1019 |
// original_ordering might be empty if this class has no methods of its own |
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1020 |
if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
14385 | 1021 |
merged_ordering = MetadataFactory::new_array<int>( |
1022 |
klass->class_loader_data(), new_size, CHECK); |
|
1023 |
} |
|
1024 |
int method_order_index = klass->methods()->length(); |
|
1025 |
||
1026 |
sort_methods(new_methods); |
|
1027 |
||
1028 |
// Perform grand merge of existing methods and new methods |
|
1029 |
int orig_idx = 0; |
|
1030 |
int new_idx = 0; |
|
1031 |
||
1032 |
for (int i = 0; i < new_size; ++i) { |
|
1033 |
Method* orig_method = NULL; |
|
1034 |
Method* new_method = NULL; |
|
1035 |
if (orig_idx < original_methods->length()) { |
|
1036 |
orig_method = original_methods->at(orig_idx); |
|
1037 |
} |
|
1038 |
if (new_idx < new_methods->length()) { |
|
1039 |
new_method = new_methods->at(new_idx); |
|
1040 |
} |
|
1041 |
||
1042 |
if (orig_method != NULL && |
|
1043 |
(new_method == NULL || orig_method->name() < new_method->name())) { |
|
1044 |
merged_methods->at_put(i, orig_method); |
|
1045 |
original_methods->at_put(orig_idx, NULL); |
|
1046 |
if (merged_ordering->length() > 0) { |
|
22233
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1047 |
assert(original_ordering != NULL && original_ordering->length() > 0, |
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1048 |
"should have original order information for this method"); |
14385 | 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); |
|
29316
5287df8a8972
8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
27680
diff
changeset
|
1061 |
merged_methods->at(i)->set_orig_method_idnum(i); |
14385 | 1062 |
} |
1063 |
||
1064 |
// Verify correct order |
|
1065 |
#ifdef ASSERT |
|
1066 |
uintptr_t prev = 0; |
|
1067 |
for (int i = 0; i < merged_methods->length(); ++i) { |
|
1068 |
Method* mo = merged_methods->at(i); |
|
1069 |
uintptr_t nv = (uintptr_t)mo->name(); |
|
1070 |
assert(nv >= prev, "Incorrect method ordering"); |
|
1071 |
prev = nv; |
|
1072 |
} |
|
1073 |
#endif |
|
1074 |
||
1075 |
// Replace klass methods with new merged lists |
|
1076 |
klass->set_methods(merged_methods); |
|
17859
cda7f55ca4dc
8015436: compiler/ciReplay/TestSA.sh fails with assert() index is out of bounds
sspitsyn
parents:
16379
diff
changeset
|
1077 |
klass->set_initial_method_idnum(new_size); |
22233
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1078 |
klass->set_method_ordering(merged_ordering); |
14385 | 1079 |
|
22233
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1080 |
// Free metadata |
14385 | 1081 |
ClassLoaderData* cld = klass->class_loader_data(); |
22233
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1082 |
if (original_methods->length() > 0) { |
21556
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
1083 |
MetadataFactory::free_array(cld, original_methods); |
e75cd34a59e0
8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents:
21516
diff
changeset
|
1084 |
} |
22233
f0028de67b30
8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents:
22232
diff
changeset
|
1085 |
if (original_ordering != NULL && original_ordering->length() > 0) { |
14385 | 1086 |
MetadataFactory::free_array(cld, original_ordering); |
1087 |
} |
|
1088 |
} |