Mercurial > hg > truffle
annotate src/share/vm/code/dependencies.cpp @ 3852:fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
Reviewed-by: kvn, never, bdelsart
author | twisti |
---|---|
date | Tue, 16 Aug 2011 04:14:05 -0700 |
parents | 1d1603768966 |
children | b27c72d69fd1 |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1206
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1206
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1206
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciArrayKlass.hpp" | |
27 #include "ci/ciEnv.hpp" | |
28 #include "ci/ciKlass.hpp" | |
29 #include "ci/ciMethod.hpp" | |
30 #include "code/dependencies.hpp" | |
31 #include "compiler/compileLog.hpp" | |
32 #include "oops/oop.inline.hpp" | |
33 #include "runtime/handles.inline.hpp" | |
34 #include "utilities/copy.hpp" | |
0 | 35 |
36 | |
37 #ifdef ASSERT | |
38 static bool must_be_in_vm() { | |
39 Thread* thread = Thread::current(); | |
40 if (thread->is_Java_thread()) | |
41 return ((JavaThread*)thread)->thread_state() == _thread_in_vm; | |
42 else | |
43 return true; //something like this: thread->is_VM_thread(); | |
44 } | |
45 #endif //ASSERT | |
46 | |
47 void Dependencies::initialize(ciEnv* env) { | |
48 Arena* arena = env->arena(); | |
49 _oop_recorder = env->oop_recorder(); | |
50 _log = env->log(); | |
51 _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0); | |
52 DEBUG_ONLY(_deps[end_marker] = NULL); | |
53 for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) { | |
54 _deps[i] = new(arena) GrowableArray<ciObject*>(arena, 10, 0, 0); | |
55 } | |
56 _content_bytes = NULL; | |
57 _size_in_bytes = (size_t)-1; | |
58 | |
59 assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT), "sanity"); | |
60 } | |
61 | |
62 void Dependencies::assert_evol_method(ciMethod* m) { | |
63 assert_common_1(evol_method, m); | |
64 } | |
65 | |
66 void Dependencies::assert_leaf_type(ciKlass* ctxk) { | |
67 if (ctxk->is_array_klass()) { | |
68 // As a special case, support this assertion on an array type, | |
69 // which reduces to an assertion on its element type. | |
70 // Note that this cannot be done with assertions that | |
71 // relate to concreteness or abstractness. | |
72 ciType* elemt = ctxk->as_array_klass()->base_element_type(); | |
73 if (!elemt->is_instance_klass()) return; // Ex: int[][] | |
74 ctxk = elemt->as_instance_klass(); | |
75 //if (ctxk->is_final()) return; // Ex: String[][] | |
76 } | |
77 check_ctxk(ctxk); | |
78 assert_common_1(leaf_type, ctxk); | |
79 } | |
80 | |
81 void Dependencies::assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck) { | |
82 check_ctxk_abstract(ctxk); | |
83 assert_common_2(abstract_with_unique_concrete_subtype, ctxk, conck); | |
84 } | |
85 | |
86 void Dependencies::assert_abstract_with_no_concrete_subtype(ciKlass* ctxk) { | |
87 check_ctxk_abstract(ctxk); | |
88 assert_common_1(abstract_with_no_concrete_subtype, ctxk); | |
89 } | |
90 | |
91 void Dependencies::assert_concrete_with_no_concrete_subtype(ciKlass* ctxk) { | |
92 check_ctxk_concrete(ctxk); | |
93 assert_common_1(concrete_with_no_concrete_subtype, ctxk); | |
94 } | |
95 | |
96 void Dependencies::assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm) { | |
97 check_ctxk(ctxk); | |
98 assert_common_2(unique_concrete_method, ctxk, uniqm); | |
99 } | |
100 | |
101 void Dependencies::assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2) { | |
102 check_ctxk(ctxk); | |
103 assert_common_3(abstract_with_exclusive_concrete_subtypes_2, ctxk, k1, k2); | |
104 } | |
105 | |
106 void Dependencies::assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2) { | |
107 check_ctxk(ctxk); | |
108 assert_common_3(exclusive_concrete_methods_2, ctxk, m1, m2); | |
109 } | |
110 | |
111 void Dependencies::assert_has_no_finalizable_subclasses(ciKlass* ctxk) { | |
112 check_ctxk(ctxk); | |
113 assert_common_1(no_finalizable_subclasses, ctxk); | |
114 } | |
115 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
116 void Dependencies::assert_call_site_target_value(ciKlass* ctxk, ciCallSite* call_site, ciMethodHandle* method_handle) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
117 check_ctxk(ctxk); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
118 assert_common_3(call_site_target_value, ctxk, call_site, method_handle); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
119 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
120 |
0 | 121 // Helper function. If we are adding a new dep. under ctxk2, |
122 // try to find an old dep. under a broader* ctxk1. If there is | |
123 // | |
124 bool Dependencies::maybe_merge_ctxk(GrowableArray<ciObject*>* deps, | |
125 int ctxk_i, ciKlass* ctxk2) { | |
126 ciKlass* ctxk1 = deps->at(ctxk_i)->as_klass(); | |
127 if (ctxk2->is_subtype_of(ctxk1)) { | |
128 return true; // success, and no need to change | |
129 } else if (ctxk1->is_subtype_of(ctxk2)) { | |
130 // new context class fully subsumes previous one | |
131 deps->at_put(ctxk_i, ctxk2); | |
132 return true; | |
133 } else { | |
134 return false; | |
135 } | |
136 } | |
137 | |
138 void Dependencies::assert_common_1(Dependencies::DepType dept, ciObject* x) { | |
139 assert(dep_args(dept) == 1, "sanity"); | |
140 log_dependency(dept, x); | |
141 GrowableArray<ciObject*>* deps = _deps[dept]; | |
142 | |
143 // see if the same (or a similar) dep is already recorded | |
144 if (note_dep_seen(dept, x)) { | |
145 assert(deps->find(x) >= 0, "sanity"); | |
146 } else { | |
147 deps->append(x); | |
148 } | |
149 } | |
150 | |
151 void Dependencies::assert_common_2(Dependencies::DepType dept, | |
152 ciKlass* ctxk, ciObject* x) { | |
153 assert(dep_context_arg(dept) == 0, "sanity"); | |
154 assert(dep_args(dept) == 2, "sanity"); | |
155 log_dependency(dept, ctxk, x); | |
156 GrowableArray<ciObject*>* deps = _deps[dept]; | |
157 | |
158 // see if the same (or a similar) dep is already recorded | |
159 if (note_dep_seen(dept, x)) { | |
160 // look in this bucket for redundant assertions | |
161 const int stride = 2; | |
162 for (int i = deps->length(); (i -= stride) >= 0; ) { | |
163 ciObject* x1 = deps->at(i+1); | |
164 if (x == x1) { // same subject; check the context | |
165 if (maybe_merge_ctxk(deps, i+0, ctxk)) { | |
166 return; | |
167 } | |
168 } | |
169 } | |
170 } | |
171 | |
172 // append the assertion in the correct bucket: | |
173 deps->append(ctxk); | |
174 deps->append(x); | |
175 } | |
176 | |
177 void Dependencies::assert_common_3(Dependencies::DepType dept, | |
178 ciKlass* ctxk, ciObject* x, ciObject* x2) { | |
179 assert(dep_context_arg(dept) == 0, "sanity"); | |
180 assert(dep_args(dept) == 3, "sanity"); | |
181 log_dependency(dept, ctxk, x, x2); | |
182 GrowableArray<ciObject*>* deps = _deps[dept]; | |
183 | |
184 // try to normalize an unordered pair: | |
185 bool swap = false; | |
186 switch (dept) { | |
187 case abstract_with_exclusive_concrete_subtypes_2: | |
188 swap = (x->ident() > x2->ident() && x != ctxk); | |
189 break; | |
190 case exclusive_concrete_methods_2: | |
191 swap = (x->ident() > x2->ident() && x->as_method()->holder() != ctxk); | |
192 break; | |
193 } | |
194 if (swap) { ciObject* t = x; x = x2; x2 = t; } | |
195 | |
196 // see if the same (or a similar) dep is already recorded | |
197 if (note_dep_seen(dept, x) && note_dep_seen(dept, x2)) { | |
198 // look in this bucket for redundant assertions | |
199 const int stride = 3; | |
200 for (int i = deps->length(); (i -= stride) >= 0; ) { | |
201 ciObject* y = deps->at(i+1); | |
202 ciObject* y2 = deps->at(i+2); | |
203 if (x == y && x2 == y2) { // same subjects; check the context | |
204 if (maybe_merge_ctxk(deps, i+0, ctxk)) { | |
205 return; | |
206 } | |
207 } | |
208 } | |
209 } | |
210 // append the assertion in the correct bucket: | |
211 deps->append(ctxk); | |
212 deps->append(x); | |
213 deps->append(x2); | |
214 } | |
215 | |
216 /// Support for encoding dependencies into an nmethod: | |
217 | |
218 void Dependencies::copy_to(nmethod* nm) { | |
219 address beg = nm->dependencies_begin(); | |
220 address end = nm->dependencies_end(); | |
221 guarantee(end - beg >= (ptrdiff_t) size_in_bytes(), "bad sizing"); | |
222 Copy::disjoint_words((HeapWord*) content_bytes(), | |
223 (HeapWord*) beg, | |
224 size_in_bytes() / sizeof(HeapWord)); | |
225 assert(size_in_bytes() % sizeof(HeapWord) == 0, "copy by words"); | |
226 } | |
227 | |
228 static int sort_dep(ciObject** p1, ciObject** p2, int narg) { | |
229 for (int i = 0; i < narg; i++) { | |
230 int diff = p1[i]->ident() - p2[i]->ident(); | |
231 if (diff != 0) return diff; | |
232 } | |
233 return 0; | |
234 } | |
235 static int sort_dep_arg_1(ciObject** p1, ciObject** p2) | |
236 { return sort_dep(p1, p2, 1); } | |
237 static int sort_dep_arg_2(ciObject** p1, ciObject** p2) | |
238 { return sort_dep(p1, p2, 2); } | |
239 static int sort_dep_arg_3(ciObject** p1, ciObject** p2) | |
240 { return sort_dep(p1, p2, 3); } | |
241 | |
242 void Dependencies::sort_all_deps() { | |
243 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | |
244 DepType dept = (DepType)deptv; | |
245 GrowableArray<ciObject*>* deps = _deps[dept]; | |
246 if (deps->length() <= 1) continue; | |
247 switch (dep_args(dept)) { | |
248 case 1: deps->sort(sort_dep_arg_1, 1); break; | |
249 case 2: deps->sort(sort_dep_arg_2, 2); break; | |
250 case 3: deps->sort(sort_dep_arg_3, 3); break; | |
251 default: ShouldNotReachHere(); | |
252 } | |
253 } | |
254 } | |
255 | |
256 size_t Dependencies::estimate_size_in_bytes() { | |
257 size_t est_size = 100; | |
258 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | |
259 DepType dept = (DepType)deptv; | |
260 GrowableArray<ciObject*>* deps = _deps[dept]; | |
261 est_size += deps->length()*2; // tags and argument(s) | |
262 } | |
263 return est_size; | |
264 } | |
265 | |
266 ciKlass* Dependencies::ctxk_encoded_as_null(DepType dept, ciObject* x) { | |
267 switch (dept) { | |
268 case abstract_with_exclusive_concrete_subtypes_2: | |
269 return x->as_klass(); | |
270 case unique_concrete_method: | |
271 case exclusive_concrete_methods_2: | |
272 return x->as_method()->holder(); | |
273 } | |
274 return NULL; // let NULL be NULL | |
275 } | |
276 | |
277 klassOop Dependencies::ctxk_encoded_as_null(DepType dept, oop x) { | |
278 assert(must_be_in_vm(), "raw oops here"); | |
279 switch (dept) { | |
280 case abstract_with_exclusive_concrete_subtypes_2: | |
281 assert(x->is_klass(), "sanity"); | |
282 return (klassOop) x; | |
283 case unique_concrete_method: | |
284 case exclusive_concrete_methods_2: | |
285 assert(x->is_method(), "sanity"); | |
286 return ((methodOop)x)->method_holder(); | |
287 } | |
288 return NULL; // let NULL be NULL | |
289 } | |
290 | |
291 void Dependencies::encode_content_bytes() { | |
292 sort_all_deps(); | |
293 | |
294 // cast is safe, no deps can overflow INT_MAX | |
295 CompressedWriteStream bytes((int)estimate_size_in_bytes()); | |
296 | |
297 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | |
298 DepType dept = (DepType)deptv; | |
299 GrowableArray<ciObject*>* deps = _deps[dept]; | |
300 if (deps->length() == 0) continue; | |
301 int stride = dep_args(dept); | |
302 int ctxkj = dep_context_arg(dept); // -1 if no context arg | |
303 assert(stride > 0, "sanity"); | |
304 for (int i = 0; i < deps->length(); i += stride) { | |
305 jbyte code_byte = (jbyte)dept; | |
306 int skipj = -1; | |
307 if (ctxkj >= 0 && ctxkj+1 < stride) { | |
308 ciKlass* ctxk = deps->at(i+ctxkj+0)->as_klass(); | |
309 ciObject* x = deps->at(i+ctxkj+1); // following argument | |
310 if (ctxk == ctxk_encoded_as_null(dept, x)) { | |
311 skipj = ctxkj; // we win: maybe one less oop to keep track of | |
312 code_byte |= default_context_type_bit; | |
313 } | |
314 } | |
315 bytes.write_byte(code_byte); | |
316 for (int j = 0; j < stride; j++) { | |
317 if (j == skipj) continue; | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
196
diff
changeset
|
318 bytes.write_int(_oop_recorder->find_index(deps->at(i+j)->constant_encoding())); |
0 | 319 } |
320 } | |
321 } | |
322 | |
323 // write a sentinel byte to mark the end | |
324 bytes.write_byte(end_marker); | |
325 | |
326 // round it out to a word boundary | |
327 while (bytes.position() % sizeof(HeapWord) != 0) { | |
328 bytes.write_byte(end_marker); | |
329 } | |
330 | |
331 // check whether the dept byte encoding really works | |
332 assert((jbyte)default_context_type_bit != 0, "byte overflow"); | |
333 | |
334 _content_bytes = bytes.buffer(); | |
335 _size_in_bytes = bytes.position(); | |
336 } | |
337 | |
338 | |
339 const char* Dependencies::_dep_name[TYPE_LIMIT] = { | |
340 "end_marker", | |
341 "evol_method", | |
342 "leaf_type", | |
343 "abstract_with_unique_concrete_subtype", | |
344 "abstract_with_no_concrete_subtype", | |
345 "concrete_with_no_concrete_subtype", | |
346 "unique_concrete_method", | |
347 "abstract_with_exclusive_concrete_subtypes_2", | |
348 "exclusive_concrete_methods_2", | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
349 "no_finalizable_subclasses", |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
350 "call_site_target_value" |
0 | 351 }; |
352 | |
353 int Dependencies::_dep_args[TYPE_LIMIT] = { | |
354 -1,// end_marker | |
355 1, // evol_method m | |
356 1, // leaf_type ctxk | |
357 2, // abstract_with_unique_concrete_subtype ctxk, k | |
358 1, // abstract_with_no_concrete_subtype ctxk | |
359 1, // concrete_with_no_concrete_subtype ctxk | |
360 2, // unique_concrete_method ctxk, m | |
361 3, // unique_concrete_subtypes_2 ctxk, k1, k2 | |
362 3, // unique_concrete_methods_2 ctxk, m1, m2 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
363 1, // no_finalizable_subclasses ctxk |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
364 3 // call_site_target_value ctxk, call_site, method_handle |
0 | 365 }; |
366 | |
367 const char* Dependencies::dep_name(Dependencies::DepType dept) { | |
368 if (!dept_in_mask(dept, all_types)) return "?bad-dep?"; | |
369 return _dep_name[dept]; | |
370 } | |
371 | |
372 int Dependencies::dep_args(Dependencies::DepType dept) { | |
373 if (!dept_in_mask(dept, all_types)) return -1; | |
374 return _dep_args[dept]; | |
375 } | |
376 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
377 void Dependencies::check_valid_dependency_type(DepType dept) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
378 for (int deptv = (int) FIRST_TYPE; deptv < (int) TYPE_LIMIT; deptv++) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
379 if (dept == ((DepType) deptv)) return; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
380 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
381 ShouldNotReachHere(); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
382 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
383 |
0 | 384 // for the sake of the compiler log, print out current dependencies: |
385 void Dependencies::log_all_dependencies() { | |
386 if (log() == NULL) return; | |
387 ciObject* args[max_arg_count]; | |
388 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | |
389 DepType dept = (DepType)deptv; | |
390 GrowableArray<ciObject*>* deps = _deps[dept]; | |
391 if (deps->length() == 0) continue; | |
392 int stride = dep_args(dept); | |
393 for (int i = 0; i < deps->length(); i += stride) { | |
394 for (int j = 0; j < stride; j++) { | |
395 // flush out the identities before printing | |
396 args[j] = deps->at(i+j); | |
397 } | |
398 write_dependency_to(log(), dept, stride, args); | |
399 } | |
400 } | |
401 } | |
402 | |
403 void Dependencies::write_dependency_to(CompileLog* log, | |
404 DepType dept, | |
405 int nargs, oop args[], | |
406 klassOop witness) { | |
407 if (log == NULL) { | |
408 return; | |
409 } | |
410 ciEnv* env = ciEnv::current(); | |
411 ciObject* ciargs[max_arg_count]; | |
412 assert(nargs <= max_arg_count, "oob"); | |
413 for (int j = 0; j < nargs; j++) { | |
414 ciargs[j] = env->get_object(args[j]); | |
415 } | |
416 Dependencies::write_dependency_to(log, dept, nargs, ciargs, witness); | |
417 } | |
418 | |
419 void Dependencies::write_dependency_to(CompileLog* log, | |
420 DepType dept, | |
421 int nargs, ciObject* args[], | |
422 klassOop witness) { | |
423 if (log == NULL) return; | |
424 assert(nargs <= max_arg_count, "oob"); | |
425 int argids[max_arg_count]; | |
426 int ctxkj = dep_context_arg(dept); // -1 if no context arg | |
427 int j; | |
428 for (j = 0; j < nargs; j++) { | |
429 argids[j] = log->identify(args[j]); | |
430 } | |
431 if (witness != NULL) { | |
432 log->begin_elem("dependency_failed"); | |
433 } else { | |
434 log->begin_elem("dependency"); | |
435 } | |
436 log->print(" type='%s'", dep_name(dept)); | |
437 if (ctxkj >= 0) { | |
438 log->print(" ctxk='%d'", argids[ctxkj]); | |
439 } | |
440 // write remaining arguments, if any. | |
441 for (j = 0; j < nargs; j++) { | |
442 if (j == ctxkj) continue; // already logged | |
443 if (j == 1) { | |
444 log->print( " x='%d'", argids[j]); | |
445 } else { | |
446 log->print(" x%d='%d'", j, argids[j]); | |
447 } | |
448 } | |
449 if (witness != NULL) { | |
450 log->object("witness", witness); | |
451 log->stamp(); | |
452 } | |
453 log->end_elem(); | |
454 } | |
455 | |
456 void Dependencies::write_dependency_to(xmlStream* xtty, | |
457 DepType dept, | |
458 int nargs, oop args[], | |
459 klassOop witness) { | |
460 if (xtty == NULL) return; | |
461 ttyLocker ttyl; | |
462 int ctxkj = dep_context_arg(dept); // -1 if no context arg | |
463 if (witness != NULL) { | |
464 xtty->begin_elem("dependency_failed"); | |
465 } else { | |
466 xtty->begin_elem("dependency"); | |
467 } | |
468 xtty->print(" type='%s'", dep_name(dept)); | |
469 if (ctxkj >= 0) { | |
470 xtty->object("ctxk", args[ctxkj]); | |
471 } | |
472 // write remaining arguments, if any. | |
473 for (int j = 0; j < nargs; j++) { | |
474 if (j == ctxkj) continue; // already logged | |
475 if (j == 1) { | |
476 xtty->object("x", args[j]); | |
477 } else { | |
478 char xn[10]; sprintf(xn, "x%d", j); | |
479 xtty->object(xn, args[j]); | |
480 } | |
481 } | |
482 if (witness != NULL) { | |
483 xtty->object("witness", witness); | |
484 xtty->stamp(); | |
485 } | |
486 xtty->end_elem(); | |
487 } | |
488 | |
489 void Dependencies::print_dependency(DepType dept, int nargs, oop args[], | |
490 klassOop witness) { | |
491 ResourceMark rm; | |
492 ttyLocker ttyl; // keep the following output all in one block | |
493 tty->print_cr("%s of type %s", | |
494 (witness == NULL)? "Dependency": "Failed dependency", | |
495 dep_name(dept)); | |
496 // print arguments | |
497 int ctxkj = dep_context_arg(dept); // -1 if no context arg | |
498 for (int j = 0; j < nargs; j++) { | |
499 oop arg = args[j]; | |
500 bool put_star = false; | |
501 if (arg == NULL) continue; | |
502 const char* what; | |
503 if (j == ctxkj) { | |
504 what = "context"; | |
505 put_star = !Dependencies::is_concrete_klass((klassOop)arg); | |
506 } else if (arg->is_method()) { | |
507 what = "method "; | |
508 put_star = !Dependencies::is_concrete_method((methodOop)arg); | |
509 } else if (arg->is_klass()) { | |
510 what = "class "; | |
511 } else { | |
512 what = "object "; | |
513 } | |
514 tty->print(" %s = %s", what, (put_star? "*": "")); | |
515 if (arg->is_klass()) | |
516 tty->print("%s", Klass::cast((klassOop)arg)->external_name()); | |
517 else | |
518 arg->print_value(); | |
519 tty->cr(); | |
520 } | |
521 if (witness != NULL) { | |
522 bool put_star = !Dependencies::is_concrete_klass(witness); | |
523 tty->print_cr(" witness = %s%s", | |
524 (put_star? "*": ""), | |
525 Klass::cast(witness)->external_name()); | |
526 } | |
527 } | |
528 | |
529 void Dependencies::DepStream::log_dependency(klassOop witness) { | |
530 if (_deps == NULL && xtty == NULL) return; // fast cutout for runtime | |
531 int nargs = argument_count(); | |
532 oop args[max_arg_count]; | |
533 for (int j = 0; j < nargs; j++) { | |
534 args[j] = argument(j); | |
535 } | |
536 if (_deps != NULL && _deps->log() != NULL) { | |
537 Dependencies::write_dependency_to(_deps->log(), | |
538 type(), nargs, args, witness); | |
539 } else { | |
540 Dependencies::write_dependency_to(xtty, | |
541 type(), nargs, args, witness); | |
542 } | |
543 } | |
544 | |
545 void Dependencies::DepStream::print_dependency(klassOop witness, bool verbose) { | |
546 int nargs = argument_count(); | |
547 oop args[max_arg_count]; | |
548 for (int j = 0; j < nargs; j++) { | |
549 args[j] = argument(j); | |
550 } | |
551 Dependencies::print_dependency(type(), nargs, args, witness); | |
552 if (verbose) { | |
553 if (_code != NULL) { | |
554 tty->print(" code: "); | |
555 _code->print_value_on(tty); | |
556 tty->cr(); | |
557 } | |
558 } | |
559 } | |
560 | |
561 | |
562 /// Dependency stream support (decodes dependencies from an nmethod): | |
563 | |
564 #ifdef ASSERT | |
565 void Dependencies::DepStream::initial_asserts(size_t byte_limit) { | |
566 assert(must_be_in_vm(), "raw oops here"); | |
567 _byte_limit = byte_limit; | |
568 _type = (DepType)(end_marker-1); // defeat "already at end" assert | |
569 assert((_code!=NULL) + (_deps!=NULL) == 1, "one or t'other"); | |
570 } | |
571 #endif //ASSERT | |
572 | |
573 bool Dependencies::DepStream::next() { | |
574 assert(_type != end_marker, "already at end"); | |
575 if (_bytes.position() == 0 && _code != NULL | |
576 && _code->dependencies_size() == 0) { | |
577 // Method has no dependencies at all. | |
578 return false; | |
579 } | |
580 int code_byte = (_bytes.read_byte() & 0xFF); | |
581 if (code_byte == end_marker) { | |
582 DEBUG_ONLY(_type = end_marker); | |
583 return false; | |
584 } else { | |
585 int ctxk_bit = (code_byte & Dependencies::default_context_type_bit); | |
586 code_byte -= ctxk_bit; | |
587 DepType dept = (DepType)code_byte; | |
588 _type = dept; | |
589 guarantee((dept - FIRST_TYPE) < (TYPE_LIMIT - FIRST_TYPE), | |
590 "bad dependency type tag"); | |
591 int stride = _dep_args[dept]; | |
592 assert(stride == dep_args(dept), "sanity"); | |
593 int skipj = -1; | |
594 if (ctxk_bit != 0) { | |
595 skipj = 0; // currently the only context argument is at zero | |
596 assert(skipj == dep_context_arg(dept), "zero arg always ctxk"); | |
597 } | |
598 for (int j = 0; j < stride; j++) { | |
599 _xi[j] = (j == skipj)? 0: _bytes.read_int(); | |
600 } | |
601 DEBUG_ONLY(_xi[stride] = -1); // help detect overruns | |
602 return true; | |
603 } | |
604 } | |
605 | |
606 inline oop Dependencies::DepStream::recorded_oop_at(int i) { | |
607 return (_code != NULL) | |
608 ? _code->oop_at(i) | |
609 : JNIHandles::resolve(_deps->oop_recorder()->handle_at(i)); | |
610 } | |
611 | |
612 oop Dependencies::DepStream::argument(int i) { | |
613 return recorded_oop_at(argument_index(i)); | |
614 } | |
615 | |
616 klassOop Dependencies::DepStream::context_type() { | |
617 assert(must_be_in_vm(), "raw oops here"); | |
618 int ctxkj = dep_context_arg(_type); // -1 if no context arg | |
619 if (ctxkj < 0) { | |
620 return NULL; // for example, evol_method | |
621 } else { | |
622 oop k = recorded_oop_at(_xi[ctxkj]); | |
623 if (k != NULL) { // context type was not compressed away | |
624 assert(k->is_klass(), "type check"); | |
625 return (klassOop) k; | |
626 } else { // recompute "default" context type | |
627 return ctxk_encoded_as_null(_type, recorded_oop_at(_xi[ctxkj+1])); | |
628 } | |
629 } | |
630 } | |
631 | |
632 /// Checking dependencies: | |
633 | |
634 // This hierarchy walker inspects subtypes of a given type, | |
635 // trying to find a "bad" class which breaks a dependency. | |
636 // Such a class is called a "witness" to the broken dependency. | |
637 // While searching around, we ignore "participants", which | |
638 // are already known to the dependency. | |
639 class ClassHierarchyWalker { | |
640 public: | |
641 enum { PARTICIPANT_LIMIT = 3 }; | |
642 | |
643 private: | |
644 // optional method descriptor to check for: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
645 Symbol* _name; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
646 Symbol* _signature; |
0 | 647 |
648 // special classes which are not allowed to be witnesses: | |
649 klassOop _participants[PARTICIPANT_LIMIT+1]; | |
650 int _num_participants; | |
651 | |
652 // cache of method lookups | |
653 methodOop _found_methods[PARTICIPANT_LIMIT+1]; | |
654 | |
655 // if non-zero, tells how many witnesses to convert to participants | |
656 int _record_witnesses; | |
657 | |
658 void initialize(klassOop participant) { | |
659 _record_witnesses = 0; | |
660 _participants[0] = participant; | |
661 _found_methods[0] = NULL; | |
662 _num_participants = 0; | |
663 if (participant != NULL) { | |
664 // Terminating NULL. | |
665 _participants[1] = NULL; | |
666 _found_methods[1] = NULL; | |
667 _num_participants = 1; | |
668 } | |
669 } | |
670 | |
671 void initialize_from_method(methodOop m) { | |
672 assert(m != NULL && m->is_method(), "sanity"); | |
673 _name = m->name(); | |
674 _signature = m->signature(); | |
675 } | |
676 | |
677 public: | |
678 // The walker is initialized to recognize certain methods and/or types | |
679 // as friendly participants. | |
680 ClassHierarchyWalker(klassOop participant, methodOop m) { | |
681 initialize_from_method(m); | |
682 initialize(participant); | |
683 } | |
684 ClassHierarchyWalker(methodOop m) { | |
685 initialize_from_method(m); | |
686 initialize(NULL); | |
687 } | |
688 ClassHierarchyWalker(klassOop participant = NULL) { | |
689 _name = NULL; | |
690 _signature = NULL; | |
691 initialize(participant); | |
692 } | |
693 | |
694 // This is common code for two searches: One for concrete subtypes, | |
695 // the other for concrete method implementations and overrides. | |
696 bool doing_subtype_search() { | |
697 return _name == NULL; | |
698 } | |
699 | |
700 int num_participants() { return _num_participants; } | |
701 klassOop participant(int n) { | |
702 assert((uint)n <= (uint)_num_participants, "oob"); | |
703 return _participants[n]; | |
704 } | |
705 | |
706 // Note: If n==num_participants, returns NULL. | |
707 methodOop found_method(int n) { | |
708 assert((uint)n <= (uint)_num_participants, "oob"); | |
709 methodOop fm = _found_methods[n]; | |
710 assert(n == _num_participants || fm != NULL, "proper usage"); | |
711 assert(fm == NULL || fm->method_holder() == _participants[n], "sanity"); | |
712 return fm; | |
713 } | |
714 | |
715 #ifdef ASSERT | |
716 // Assert that m is inherited into ctxk, without intervening overrides. | |
717 // (May return true even if this is not true, in corner cases where we punt.) | |
718 bool check_method_context(klassOop ctxk, methodOop m) { | |
719 if (m->method_holder() == ctxk) | |
720 return true; // Quick win. | |
721 if (m->is_private()) | |
722 return false; // Quick lose. Should not happen. | |
723 if (!(m->is_public() || m->is_protected())) | |
724 // The override story is complex when packages get involved. | |
725 return true; // Must punt the assertion to true. | |
726 Klass* k = Klass::cast(ctxk); | |
727 methodOop lm = k->lookup_method(m->name(), m->signature()); | |
728 if (lm == NULL && k->oop_is_instance()) { | |
729 // It might be an abstract interface method, devoid of mirandas. | |
730 lm = ((instanceKlass*)k)->lookup_method_in_all_interfaces(m->name(), | |
731 m->signature()); | |
732 } | |
733 if (lm == m) | |
734 // Method m is inherited into ctxk. | |
735 return true; | |
736 if (lm != NULL) { | |
737 if (!(lm->is_public() || lm->is_protected())) | |
738 // Method is [package-]private, so the override story is complex. | |
739 return true; // Must punt the assertion to true. | |
740 if ( !Dependencies::is_concrete_method(lm) | |
741 && !Dependencies::is_concrete_method(m) | |
742 && Klass::cast(lm->method_holder())->is_subtype_of(m->method_holder())) | |
743 // Method m is overridden by lm, but both are non-concrete. | |
744 return true; | |
745 } | |
746 ResourceMark rm; | |
747 tty->print_cr("Dependency method not found in the associated context:"); | |
748 tty->print_cr(" context = %s", Klass::cast(ctxk)->external_name()); | |
749 tty->print( " method = "); m->print_short_name(tty); tty->cr(); | |
750 if (lm != NULL) { | |
751 tty->print( " found = "); lm->print_short_name(tty); tty->cr(); | |
752 } | |
753 return false; | |
754 } | |
755 #endif | |
756 | |
757 void add_participant(klassOop participant) { | |
758 assert(_num_participants + _record_witnesses < PARTICIPANT_LIMIT, "oob"); | |
759 int np = _num_participants++; | |
760 _participants[np] = participant; | |
761 _participants[np+1] = NULL; | |
762 _found_methods[np+1] = NULL; | |
763 } | |
764 | |
765 void record_witnesses(int add) { | |
766 if (add > PARTICIPANT_LIMIT) add = PARTICIPANT_LIMIT; | |
767 assert(_num_participants + add < PARTICIPANT_LIMIT, "oob"); | |
768 _record_witnesses = add; | |
769 } | |
770 | |
771 bool is_witness(klassOop k) { | |
772 if (doing_subtype_search()) { | |
773 return Dependencies::is_concrete_klass(k); | |
774 } else { | |
775 methodOop m = instanceKlass::cast(k)->find_method(_name, _signature); | |
776 if (m == NULL || !Dependencies::is_concrete_method(m)) return false; | |
777 _found_methods[_num_participants] = m; | |
778 // Note: If add_participant(k) is called, | |
779 // the method m will already be memoized for it. | |
780 return true; | |
781 } | |
782 } | |
783 | |
784 bool is_participant(klassOop k) { | |
785 if (k == _participants[0]) { | |
786 return true; | |
787 } else if (_num_participants <= 1) { | |
788 return false; | |
789 } else { | |
790 return in_list(k, &_participants[1]); | |
791 } | |
792 } | |
793 bool ignore_witness(klassOop witness) { | |
794 if (_record_witnesses == 0) { | |
795 return false; | |
796 } else { | |
797 --_record_witnesses; | |
798 add_participant(witness); | |
799 return true; | |
800 } | |
801 } | |
802 static bool in_list(klassOop x, klassOop* list) { | |
803 for (int i = 0; ; i++) { | |
804 klassOop y = list[i]; | |
805 if (y == NULL) break; | |
806 if (y == x) return true; | |
807 } | |
808 return false; // not in list | |
809 } | |
810 | |
811 private: | |
812 // the actual search method: | |
813 klassOop find_witness_anywhere(klassOop context_type, | |
814 bool participants_hide_witnesses, | |
815 bool top_level_call = true); | |
816 // the spot-checking version: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
817 klassOop find_witness_in(KlassDepChange& changes, |
0 | 818 klassOop context_type, |
819 bool participants_hide_witnesses); | |
820 public: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
821 klassOop find_witness_subtype(klassOop context_type, KlassDepChange* changes = NULL) { |
0 | 822 assert(doing_subtype_search(), "must set up a subtype search"); |
823 // When looking for unexpected concrete types, | |
824 // do not look beneath expected ones. | |
825 const bool participants_hide_witnesses = true; | |
826 // CX > CC > C' is OK, even if C' is new. | |
827 // CX > { CC, C' } is not OK if C' is new, and C' is the witness. | |
828 if (changes != NULL) { | |
829 return find_witness_in(*changes, context_type, participants_hide_witnesses); | |
830 } else { | |
831 return find_witness_anywhere(context_type, participants_hide_witnesses); | |
832 } | |
833 } | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
834 klassOop find_witness_definer(klassOop context_type, KlassDepChange* changes = NULL) { |
0 | 835 assert(!doing_subtype_search(), "must set up a method definer search"); |
836 // When looking for unexpected concrete methods, | |
837 // look beneath expected ones, to see if there are overrides. | |
838 const bool participants_hide_witnesses = true; | |
839 // CX.m > CC.m > C'.m is not OK, if C'.m is new, and C' is the witness. | |
840 if (changes != NULL) { | |
841 return find_witness_in(*changes, context_type, !participants_hide_witnesses); | |
842 } else { | |
843 return find_witness_anywhere(context_type, !participants_hide_witnesses); | |
844 } | |
845 } | |
846 }; | |
847 | |
848 #ifndef PRODUCT | |
849 static int deps_find_witness_calls = 0; | |
850 static int deps_find_witness_steps = 0; | |
851 static int deps_find_witness_recursions = 0; | |
852 static int deps_find_witness_singles = 0; | |
853 static int deps_find_witness_print = 0; // set to -1 to force a final print | |
854 static bool count_find_witness_calls() { | |
855 if (TraceDependencies || LogCompilation) { | |
856 int pcount = deps_find_witness_print + 1; | |
857 bool final_stats = (pcount == 0); | |
858 bool initial_call = (pcount == 1); | |
859 bool occasional_print = ((pcount & ((1<<10) - 1)) == 0); | |
860 if (pcount < 0) pcount = 1; // crude overflow protection | |
861 deps_find_witness_print = pcount; | |
862 if (VerifyDependencies && initial_call) { | |
863 tty->print_cr("Warning: TraceDependencies results may be inflated by VerifyDependencies"); | |
864 } | |
865 if (occasional_print || final_stats) { | |
866 // Every now and then dump a little info about dependency searching. | |
867 if (xtty != NULL) { | |
1206
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1123
diff
changeset
|
868 ttyLocker ttyl; |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1123
diff
changeset
|
869 xtty->elem("deps_find_witness calls='%d' steps='%d' recursions='%d' singles='%d'", |
0 | 870 deps_find_witness_calls, |
871 deps_find_witness_steps, | |
872 deps_find_witness_recursions, | |
873 deps_find_witness_singles); | |
874 } | |
875 if (final_stats || (TraceDependencies && WizardMode)) { | |
1206
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1123
diff
changeset
|
876 ttyLocker ttyl; |
0 | 877 tty->print_cr("Dependency check (find_witness) " |
878 "calls=%d, steps=%d (avg=%.1f), recursions=%d, singles=%d", | |
879 deps_find_witness_calls, | |
880 deps_find_witness_steps, | |
881 (double)deps_find_witness_steps / deps_find_witness_calls, | |
882 deps_find_witness_recursions, | |
883 deps_find_witness_singles); | |
884 } | |
885 } | |
886 return true; | |
887 } | |
888 return false; | |
889 } | |
890 #else | |
891 #define count_find_witness_calls() (0) | |
892 #endif //PRODUCT | |
893 | |
894 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
895 klassOop ClassHierarchyWalker::find_witness_in(KlassDepChange& changes, |
0 | 896 klassOop context_type, |
897 bool participants_hide_witnesses) { | |
898 assert(changes.involves_context(context_type), "irrelevant dependency"); | |
899 klassOop new_type = changes.new_type(); | |
900 | |
901 count_find_witness_calls(); | |
902 NOT_PRODUCT(deps_find_witness_singles++); | |
903 | |
904 // Current thread must be in VM (not native mode, as in CI): | |
905 assert(must_be_in_vm(), "raw oops here"); | |
906 // Must not move the class hierarchy during this check: | |
907 assert_locked_or_safepoint(Compile_lock); | |
908 | |
30 | 909 int nof_impls = instanceKlass::cast(context_type)->nof_implementors(); |
910 if (nof_impls > 1) { | |
911 // Avoid this case: *I.m > { A.m, C }; B.m > C | |
912 // %%% Until this is fixed more systematically, bail out. | |
913 // See corresponding comment in find_witness_anywhere. | |
914 return context_type; | |
915 } | |
916 | |
0 | 917 assert(!is_participant(new_type), "only old classes are participants"); |
918 if (participants_hide_witnesses) { | |
919 // If the new type is a subtype of a participant, we are done. | |
920 for (int i = 0; i < num_participants(); i++) { | |
921 klassOop part = participant(i); | |
922 if (part == NULL) continue; | |
923 assert(changes.involves_context(part) == Klass::cast(new_type)->is_subtype_of(part), | |
924 "correct marking of participants, b/c new_type is unique"); | |
925 if (changes.involves_context(part)) { | |
926 // new guy is protected from this check by previous participant | |
927 return NULL; | |
928 } | |
929 } | |
930 } | |
931 | |
932 if (is_witness(new_type) && | |
933 !ignore_witness(new_type)) { | |
934 return new_type; | |
935 } | |
936 | |
937 return NULL; | |
938 } | |
939 | |
940 | |
941 // Walk hierarchy under a context type, looking for unexpected types. | |
942 // Do not report participant types, and recursively walk beneath | |
943 // them only if participants_hide_witnesses is false. | |
944 // If top_level_call is false, skip testing the context type, | |
945 // because the caller has already considered it. | |
946 klassOop ClassHierarchyWalker::find_witness_anywhere(klassOop context_type, | |
947 bool participants_hide_witnesses, | |
948 bool top_level_call) { | |
949 // Current thread must be in VM (not native mode, as in CI): | |
950 assert(must_be_in_vm(), "raw oops here"); | |
951 // Must not move the class hierarchy during this check: | |
952 assert_locked_or_safepoint(Compile_lock); | |
953 | |
954 bool do_counts = count_find_witness_calls(); | |
955 | |
956 // Check the root of the sub-hierarchy first. | |
957 if (top_level_call) { | |
958 if (do_counts) { | |
959 NOT_PRODUCT(deps_find_witness_calls++); | |
960 NOT_PRODUCT(deps_find_witness_steps++); | |
961 } | |
962 if (is_participant(context_type)) { | |
963 if (participants_hide_witnesses) return NULL; | |
964 // else fall through to search loop... | |
965 } else if (is_witness(context_type) && !ignore_witness(context_type)) { | |
966 // The context is an abstract class or interface, to start with. | |
967 return context_type; | |
968 } | |
969 } | |
970 | |
971 // Now we must check each implementor and each subclass. | |
972 // Use a short worklist to avoid blowing the stack. | |
973 // Each worklist entry is a *chain* of subklass siblings to process. | |
974 const int CHAINMAX = 100; // >= 1 + instanceKlass::implementors_limit | |
975 Klass* chains[CHAINMAX]; | |
976 int chaini = 0; // index into worklist | |
977 Klass* chain; // scratch variable | |
978 #define ADD_SUBCLASS_CHAIN(k) { \ | |
979 assert(chaini < CHAINMAX, "oob"); \ | |
980 chain = instanceKlass::cast(k)->subklass(); \ | |
981 if (chain != NULL) chains[chaini++] = chain; } | |
982 | |
983 // Look for non-abstract subclasses. | |
984 // (Note: Interfaces do not have subclasses.) | |
985 ADD_SUBCLASS_CHAIN(context_type); | |
986 | |
987 // If it is an interface, search its direct implementors. | |
988 // (Their subclasses are additional indirect implementors. | |
989 // See instanceKlass::add_implementor.) | |
990 // (Note: nof_implementors is always zero for non-interfaces.) | |
991 int nof_impls = instanceKlass::cast(context_type)->nof_implementors(); | |
992 if (nof_impls > 1) { | |
993 // Avoid this case: *I.m > { A.m, C }; B.m > C | |
994 // Here, I.m has 2 concrete implementations, but m appears unique | |
995 // as A.m, because the search misses B.m when checking C. | |
996 // The inherited method B.m was getting missed by the walker | |
997 // when interface 'I' was the starting point. | |
998 // %%% Until this is fixed more systematically, bail out. | |
999 // (Old CHA had the same limitation.) | |
1000 return context_type; | |
1001 } | |
1002 for (int i = 0; i < nof_impls; i++) { | |
1003 klassOop impl = instanceKlass::cast(context_type)->implementor(i); | |
1004 if (impl == NULL) { | |
1005 // implementors array overflowed => no exact info. | |
1006 return context_type; // report an inexact witness to this sad affair | |
1007 } | |
1008 if (do_counts) | |
1009 { NOT_PRODUCT(deps_find_witness_steps++); } | |
1010 if (is_participant(impl)) { | |
1011 if (participants_hide_witnesses) continue; | |
1012 // else fall through to process this guy's subclasses | |
1013 } else if (is_witness(impl) && !ignore_witness(impl)) { | |
1014 return impl; | |
1015 } | |
1016 ADD_SUBCLASS_CHAIN(impl); | |
1017 } | |
1018 | |
1019 // Recursively process each non-trivial sibling chain. | |
1020 while (chaini > 0) { | |
1021 Klass* chain = chains[--chaini]; | |
1022 for (Klass* subk = chain; subk != NULL; subk = subk->next_sibling()) { | |
1023 klassOop sub = subk->as_klassOop(); | |
1024 if (do_counts) { NOT_PRODUCT(deps_find_witness_steps++); } | |
1025 if (is_participant(sub)) { | |
1026 if (participants_hide_witnesses) continue; | |
1027 // else fall through to process this guy's subclasses | |
1028 } else if (is_witness(sub) && !ignore_witness(sub)) { | |
1029 return sub; | |
1030 } | |
1031 if (chaini < (VerifyDependencies? 2: CHAINMAX)) { | |
1032 // Fast path. (Partially disabled if VerifyDependencies.) | |
1033 ADD_SUBCLASS_CHAIN(sub); | |
1034 } else { | |
1035 // Worklist overflow. Do a recursive call. Should be rare. | |
1036 // The recursive call will have its own worklist, of course. | |
1037 // (Note that sub has already been tested, so that there is | |
1038 // no need for the recursive call to re-test. That's handy, | |
1039 // since the recursive call sees sub as the context_type.) | |
1040 if (do_counts) { NOT_PRODUCT(deps_find_witness_recursions++); } | |
1041 klassOop witness = find_witness_anywhere(sub, | |
1042 participants_hide_witnesses, | |
1043 /*top_level_call=*/ false); | |
1044 if (witness != NULL) return witness; | |
1045 } | |
1046 } | |
1047 } | |
1048 | |
1049 // No witness found. The dependency remains unbroken. | |
1050 return NULL; | |
1051 #undef ADD_SUBCLASS_CHAIN | |
1052 } | |
1053 | |
1054 | |
1055 bool Dependencies::is_concrete_klass(klassOop k) { | |
1056 if (Klass::cast(k)->is_abstract()) return false; | |
1057 // %%% We could treat classes which are concrete but | |
1058 // have not yet been instantiated as virtually abstract. | |
1059 // This would require a deoptimization barrier on first instantiation. | |
1060 //if (k->is_not_instantiated()) return false; | |
1061 return true; | |
1062 } | |
1063 | |
1064 bool Dependencies::is_concrete_method(methodOop m) { | |
1065 if (m->is_abstract()) return false; | |
1066 // %%% We could treat unexecuted methods as virtually abstract also. | |
1067 // This would require a deoptimization barrier on first execution. | |
1068 return !m->is_abstract(); | |
1069 } | |
1070 | |
1071 | |
1072 Klass* Dependencies::find_finalizable_subclass(Klass* k) { | |
1073 if (k->is_interface()) return NULL; | |
1074 if (k->has_finalizer()) return k; | |
1075 k = k->subklass(); | |
1076 while (k != NULL) { | |
1077 Klass* result = find_finalizable_subclass(k); | |
1078 if (result != NULL) return result; | |
1079 k = k->next_sibling(); | |
1080 } | |
1081 return NULL; | |
1082 } | |
1083 | |
1084 | |
1085 bool Dependencies::is_concrete_klass(ciInstanceKlass* k) { | |
1086 if (k->is_abstract()) return false; | |
1087 // We could return also false if k does not yet appear to be | |
1088 // instantiated, if the VM version supports this distinction also. | |
1089 //if (k->is_not_instantiated()) return false; | |
1090 return true; | |
1091 } | |
1092 | |
1093 bool Dependencies::is_concrete_method(ciMethod* m) { | |
1094 // Statics are irrelevant to virtual call sites. | |
1095 if (m->is_static()) return false; | |
1096 | |
1097 // We could return also false if m does not yet appear to be | |
1098 // executed, if the VM version supports this distinction also. | |
1099 return !m->is_abstract(); | |
1100 } | |
1101 | |
1102 | |
1103 bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) { | |
1104 return k->has_finalizable_subclass(); | |
1105 } | |
1106 | |
1107 | |
1108 // Any use of the contents (bytecodes) of a method must be | |
1109 // marked by an "evol_method" dependency, if those contents | |
1110 // can change. (Note: A method is always dependent on itself.) | |
1111 klassOop Dependencies::check_evol_method(methodOop m) { | |
1112 assert(must_be_in_vm(), "raw oops here"); | |
1113 // Did somebody do a JVMTI RedefineClasses while our backs were turned? | |
1114 // Or is there a now a breakpoint? | |
1115 // (Assumes compiled code cannot handle bkpts; change if UseFastBreakpoints.) | |
1116 if (m->is_old() | |
1117 || m->number_of_breakpoints() > 0) { | |
1118 return m->method_holder(); | |
1119 } else { | |
1120 return NULL; | |
1121 } | |
1122 } | |
1123 | |
1124 // This is a strong assertion: It is that the given type | |
1125 // has no subtypes whatever. It is most useful for | |
1126 // optimizing checks on reflected types or on array types. | |
1127 // (Checks on types which are derived from real instances | |
1128 // can be optimized more strongly than this, because we | |
1129 // know that the checked type comes from a concrete type, | |
1130 // and therefore we can disregard abstract types.) | |
1131 klassOop Dependencies::check_leaf_type(klassOop ctxk) { | |
1132 assert(must_be_in_vm(), "raw oops here"); | |
1133 assert_locked_or_safepoint(Compile_lock); | |
1134 instanceKlass* ctx = instanceKlass::cast(ctxk); | |
1135 Klass* sub = ctx->subklass(); | |
1136 if (sub != NULL) { | |
1137 return sub->as_klassOop(); | |
1138 } else if (ctx->nof_implementors() != 0) { | |
1139 // if it is an interface, it must be unimplemented | |
1140 // (if it is not an interface, nof_implementors is always zero) | |
1141 klassOop impl = ctx->implementor(0); | |
1142 return (impl != NULL)? impl: ctxk; | |
1143 } else { | |
1144 return NULL; | |
1145 } | |
1146 } | |
1147 | |
1148 // Test the assertion that conck is the only concrete subtype* of ctxk. | |
1149 // The type conck itself is allowed to have have further concrete subtypes. | |
1150 // This allows the compiler to narrow occurrences of ctxk by conck, | |
1151 // when dealing with the types of actual instances. | |
1152 klassOop Dependencies::check_abstract_with_unique_concrete_subtype(klassOop ctxk, | |
1153 klassOop conck, | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1154 KlassDepChange* changes) { |
0 | 1155 ClassHierarchyWalker wf(conck); |
1156 return wf.find_witness_subtype(ctxk, changes); | |
1157 } | |
1158 | |
1159 // If a non-concrete class has no concrete subtypes, it is not (yet) | |
1160 // instantiatable. This can allow the compiler to make some paths go | |
1161 // dead, if they are gated by a test of the type. | |
1162 klassOop Dependencies::check_abstract_with_no_concrete_subtype(klassOop ctxk, | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1163 KlassDepChange* changes) { |
0 | 1164 // Find any concrete subtype, with no participants: |
1165 ClassHierarchyWalker wf; | |
1166 return wf.find_witness_subtype(ctxk, changes); | |
1167 } | |
1168 | |
1169 | |
1170 // If a concrete class has no concrete subtypes, it can always be | |
1171 // exactly typed. This allows the use of a cheaper type test. | |
1172 klassOop Dependencies::check_concrete_with_no_concrete_subtype(klassOop ctxk, | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1173 KlassDepChange* changes) { |
0 | 1174 // Find any concrete subtype, with only the ctxk as participant: |
1175 ClassHierarchyWalker wf(ctxk); | |
1176 return wf.find_witness_subtype(ctxk, changes); | |
1177 } | |
1178 | |
1179 | |
1180 // Find the unique concrete proper subtype of ctxk, or NULL if there | |
1181 // is more than one concrete proper subtype. If there are no concrete | |
1182 // proper subtypes, return ctxk itself, whether it is concrete or not. | |
1183 // The returned subtype is allowed to have have further concrete subtypes. | |
1184 // That is, return CC1 for CX > CC1 > CC2, but NULL for CX > { CC1, CC2 }. | |
1185 klassOop Dependencies::find_unique_concrete_subtype(klassOop ctxk) { | |
1186 ClassHierarchyWalker wf(ctxk); // Ignore ctxk when walking. | |
1187 wf.record_witnesses(1); // Record one other witness when walking. | |
1188 klassOop wit = wf.find_witness_subtype(ctxk); | |
1189 if (wit != NULL) return NULL; // Too many witnesses. | |
1190 klassOop conck = wf.participant(0); | |
1191 if (conck == NULL) { | |
1192 #ifndef PRODUCT | |
1193 // Make sure the dependency mechanism will pass this discovery: | |
1194 if (VerifyDependencies) { | |
1195 // Turn off dependency tracing while actually testing deps. | |
1196 FlagSetting fs(TraceDependencies, false); | |
1197 if (!Dependencies::is_concrete_klass(ctxk)) { | |
1198 guarantee(NULL == | |
1199 (void *)check_abstract_with_no_concrete_subtype(ctxk), | |
1200 "verify dep."); | |
1201 } else { | |
1202 guarantee(NULL == | |
1203 (void *)check_concrete_with_no_concrete_subtype(ctxk), | |
1204 "verify dep."); | |
1205 } | |
1206 } | |
1207 #endif //PRODUCT | |
1208 return ctxk; // Return ctxk as a flag for "no subtypes". | |
1209 } else { | |
1210 #ifndef PRODUCT | |
1211 // Make sure the dependency mechanism will pass this discovery: | |
1212 if (VerifyDependencies) { | |
1213 // Turn off dependency tracing while actually testing deps. | |
1214 FlagSetting fs(TraceDependencies, false); | |
1215 if (!Dependencies::is_concrete_klass(ctxk)) { | |
1216 guarantee(NULL == (void *) | |
1217 check_abstract_with_unique_concrete_subtype(ctxk, conck), | |
1218 "verify dep."); | |
1219 } | |
1220 } | |
1221 #endif //PRODUCT | |
1222 return conck; | |
1223 } | |
1224 } | |
1225 | |
1226 // Test the assertion that the k[12] are the only concrete subtypes of ctxk, | |
1227 // except possibly for further subtypes of k[12] themselves. | |
1228 // The context type must be abstract. The types k1 and k2 are themselves | |
1229 // allowed to have further concrete subtypes. | |
1230 klassOop Dependencies::check_abstract_with_exclusive_concrete_subtypes( | |
1231 klassOop ctxk, | |
1232 klassOop k1, | |
1233 klassOop k2, | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1234 KlassDepChange* changes) { |
0 | 1235 ClassHierarchyWalker wf; |
1236 wf.add_participant(k1); | |
1237 wf.add_participant(k2); | |
1238 return wf.find_witness_subtype(ctxk, changes); | |
1239 } | |
1240 | |
1241 // Search ctxk for concrete implementations. If there are klen or fewer, | |
1242 // pack them into the given array and return the number. | |
1243 // Otherwise, return -1, meaning the given array would overflow. | |
1244 // (Note that a return of 0 means there are exactly no concrete subtypes.) | |
1245 // In this search, if ctxk is concrete, it will be reported alone. | |
1246 // For any type CC reported, no proper subtypes of CC will be reported. | |
1247 int Dependencies::find_exclusive_concrete_subtypes(klassOop ctxk, | |
1248 int klen, | |
1249 klassOop karray[]) { | |
1250 ClassHierarchyWalker wf; | |
1251 wf.record_witnesses(klen); | |
1252 klassOop wit = wf.find_witness_subtype(ctxk); | |
1253 if (wit != NULL) return -1; // Too many witnesses. | |
1254 int num = wf.num_participants(); | |
1255 assert(num <= klen, "oob"); | |
1256 // Pack the result array with the good news. | |
1257 for (int i = 0; i < num; i++) | |
1258 karray[i] = wf.participant(i); | |
1259 #ifndef PRODUCT | |
1260 // Make sure the dependency mechanism will pass this discovery: | |
1261 if (VerifyDependencies) { | |
1262 // Turn off dependency tracing while actually testing deps. | |
1263 FlagSetting fs(TraceDependencies, false); | |
1264 switch (Dependencies::is_concrete_klass(ctxk)? -1: num) { | |
1265 case -1: // ctxk was itself concrete | |
1266 guarantee(num == 1 && karray[0] == ctxk, "verify dep."); | |
1267 break; | |
1268 case 0: | |
1269 guarantee(NULL == (void *)check_abstract_with_no_concrete_subtype(ctxk), | |
1270 "verify dep."); | |
1271 break; | |
1272 case 1: | |
1273 guarantee(NULL == (void *) | |
1274 check_abstract_with_unique_concrete_subtype(ctxk, karray[0]), | |
1275 "verify dep."); | |
1276 break; | |
1277 case 2: | |
1278 guarantee(NULL == (void *) | |
1279 check_abstract_with_exclusive_concrete_subtypes(ctxk, | |
1280 karray[0], | |
1281 karray[1]), | |
1282 "verify dep."); | |
1283 break; | |
1284 default: | |
1285 ShouldNotReachHere(); // klen > 2 yet supported | |
1286 } | |
1287 } | |
1288 #endif //PRODUCT | |
1289 return num; | |
1290 } | |
1291 | |
1292 // If a class (or interface) has a unique concrete method uniqm, return NULL. | |
1293 // Otherwise, return a class that contains an interfering method. | |
1294 klassOop Dependencies::check_unique_concrete_method(klassOop ctxk, methodOop uniqm, | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1295 KlassDepChange* changes) { |
0 | 1296 // Here is a missing optimization: If uniqm->is_final(), |
1297 // we don't really need to search beneath it for overrides. | |
1298 // This is probably not important, since we don't use dependencies | |
1299 // to track final methods. (They can't be "definalized".) | |
1300 ClassHierarchyWalker wf(uniqm->method_holder(), uniqm); | |
1301 return wf.find_witness_definer(ctxk, changes); | |
1302 } | |
1303 | |
1304 // Find the set of all non-abstract methods under ctxk that match m. | |
1305 // (The method m must be defined or inherited in ctxk.) | |
1306 // Include m itself in the set, unless it is abstract. | |
1307 // If this set has exactly one element, return that element. | |
1308 methodOop Dependencies::find_unique_concrete_method(klassOop ctxk, methodOop m) { | |
1309 ClassHierarchyWalker wf(m); | |
1310 assert(wf.check_method_context(ctxk, m), "proper context"); | |
1311 wf.record_witnesses(1); | |
1312 klassOop wit = wf.find_witness_definer(ctxk); | |
1313 if (wit != NULL) return NULL; // Too many witnesses. | |
1314 methodOop fm = wf.found_method(0); // Will be NULL if num_parts == 0. | |
1315 if (Dependencies::is_concrete_method(m)) { | |
1316 if (fm == NULL) { | |
1317 // It turns out that m was always the only implementation. | |
1318 fm = m; | |
1319 } else if (fm != m) { | |
1320 // Two conflicting implementations after all. | |
1321 // (This can happen if m is inherited into ctxk and fm overrides it.) | |
1322 return NULL; | |
1323 } | |
1324 } | |
1325 #ifndef PRODUCT | |
1326 // Make sure the dependency mechanism will pass this discovery: | |
1327 if (VerifyDependencies && fm != NULL) { | |
1328 guarantee(NULL == (void *)check_unique_concrete_method(ctxk, fm), | |
1329 "verify dep."); | |
1330 } | |
1331 #endif //PRODUCT | |
1332 return fm; | |
1333 } | |
1334 | |
1335 klassOop Dependencies::check_exclusive_concrete_methods(klassOop ctxk, | |
1336 methodOop m1, | |
1337 methodOop m2, | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1338 KlassDepChange* changes) { |
0 | 1339 ClassHierarchyWalker wf(m1); |
1340 wf.add_participant(m1->method_holder()); | |
1341 wf.add_participant(m2->method_holder()); | |
1342 return wf.find_witness_definer(ctxk, changes); | |
1343 } | |
1344 | |
1345 // Find the set of all non-abstract methods under ctxk that match m[0]. | |
1346 // (The method m[0] must be defined or inherited in ctxk.) | |
1347 // Include m itself in the set, unless it is abstract. | |
1348 // Fill the given array m[0..(mlen-1)] with this set, and return the length. | |
1349 // (The length may be zero if no concrete methods are found anywhere.) | |
1350 // If there are too many concrete methods to fit in marray, return -1. | |
1351 int Dependencies::find_exclusive_concrete_methods(klassOop ctxk, | |
1352 int mlen, | |
1353 methodOop marray[]) { | |
1354 methodOop m0 = marray[0]; | |
1355 ClassHierarchyWalker wf(m0); | |
1356 assert(wf.check_method_context(ctxk, m0), "proper context"); | |
1357 wf.record_witnesses(mlen); | |
1358 bool participants_hide_witnesses = true; | |
1359 klassOop wit = wf.find_witness_definer(ctxk); | |
1360 if (wit != NULL) return -1; // Too many witnesses. | |
1361 int num = wf.num_participants(); | |
1362 assert(num <= mlen, "oob"); | |
1363 // Keep track of whether m is also part of the result set. | |
1364 int mfill = 0; | |
1365 assert(marray[mfill] == m0, "sanity"); | |
1366 if (Dependencies::is_concrete_method(m0)) | |
1367 mfill++; // keep m0 as marray[0], the first result | |
1368 for (int i = 0; i < num; i++) { | |
1369 methodOop fm = wf.found_method(i); | |
1370 if (fm == m0) continue; // Already put this guy in the list. | |
1371 if (mfill == mlen) { | |
1372 return -1; // Oops. Too many methods after all! | |
1373 } | |
1374 marray[mfill++] = fm; | |
1375 } | |
1376 #ifndef PRODUCT | |
1377 // Make sure the dependency mechanism will pass this discovery: | |
1378 if (VerifyDependencies) { | |
1379 // Turn off dependency tracing while actually testing deps. | |
1380 FlagSetting fs(TraceDependencies, false); | |
1381 switch (mfill) { | |
1382 case 1: | |
1383 guarantee(NULL == (void *)check_unique_concrete_method(ctxk, marray[0]), | |
1384 "verify dep."); | |
1385 break; | |
1386 case 2: | |
1387 guarantee(NULL == (void *) | |
1388 check_exclusive_concrete_methods(ctxk, marray[0], marray[1]), | |
1389 "verify dep."); | |
1390 break; | |
1391 default: | |
1392 ShouldNotReachHere(); // mlen > 2 yet supported | |
1393 } | |
1394 } | |
1395 #endif //PRODUCT | |
1396 return mfill; | |
1397 } | |
1398 | |
1399 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1400 klassOop Dependencies::check_has_no_finalizable_subclasses(klassOop ctxk, KlassDepChange* changes) { |
0 | 1401 Klass* search_at = ctxk->klass_part(); |
1402 if (changes != NULL) | |
1403 search_at = changes->new_type()->klass_part(); // just look at the new bit | |
1404 Klass* result = find_finalizable_subclass(search_at); | |
1405 if (result == NULL) { | |
1406 return NULL; | |
1407 } | |
1408 return result->as_klassOop(); | |
1409 } | |
1410 | |
1411 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1412 klassOop Dependencies::check_call_site_target_value(klassOop ctxk, oop call_site, oop method_handle, CallSiteDepChange* changes) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1413 assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "sanity"); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1414 assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity"); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1415 if (changes == NULL) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1416 // Validate all CallSites |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1417 if (java_lang_invoke_CallSite::target(call_site) != method_handle) |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1418 return ctxk; // assertion failed |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1419 } else { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1420 // Validate the given CallSite |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1421 if (call_site == changes->call_site() && java_lang_invoke_CallSite::target(call_site) != changes->method_handle()) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1422 assert(method_handle != changes->method_handle(), "must be"); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1423 return ctxk; // assertion failed |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1424 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1425 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1426 assert(java_lang_invoke_CallSite::target(call_site) == method_handle, "should still be valid"); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1427 return NULL; // assertion still valid |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1428 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1429 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1430 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1431 void Dependencies::DepStream::trace_and_log_witness(klassOop witness) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1432 if (witness != NULL) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1433 if (TraceDependencies) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1434 print_dependency(witness, /*verbose=*/ true); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1435 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1436 // The following is a no-op unless logging is enabled: |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1437 log_dependency(witness); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1438 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1439 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1440 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1441 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1442 klassOop Dependencies::DepStream::check_klass_dependency(KlassDepChange* changes) { |
0 | 1443 assert_locked_or_safepoint(Compile_lock); |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1444 Dependencies::check_valid_dependency_type(type()); |
0 | 1445 |
1446 klassOop witness = NULL; | |
1447 switch (type()) { | |
1448 case evol_method: | |
1449 witness = check_evol_method(method_argument(0)); | |
1450 break; | |
1451 case leaf_type: | |
1452 witness = check_leaf_type(context_type()); | |
1453 break; | |
1454 case abstract_with_unique_concrete_subtype: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1455 witness = check_abstract_with_unique_concrete_subtype(context_type(), type_argument(1), changes); |
0 | 1456 break; |
1457 case abstract_with_no_concrete_subtype: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1458 witness = check_abstract_with_no_concrete_subtype(context_type(), changes); |
0 | 1459 break; |
1460 case concrete_with_no_concrete_subtype: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1461 witness = check_concrete_with_no_concrete_subtype(context_type(), changes); |
0 | 1462 break; |
1463 case unique_concrete_method: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1464 witness = check_unique_concrete_method(context_type(), method_argument(1), changes); |
0 | 1465 break; |
1466 case abstract_with_exclusive_concrete_subtypes_2: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1467 witness = check_abstract_with_exclusive_concrete_subtypes(context_type(), type_argument(1), type_argument(2), changes); |
0 | 1468 break; |
1469 case exclusive_concrete_methods_2: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1470 witness = check_exclusive_concrete_methods(context_type(), method_argument(1), method_argument(2), changes); |
0 | 1471 break; |
1472 case no_finalizable_subclasses: | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1473 witness = check_has_no_finalizable_subclasses(context_type(), changes); |
0 | 1474 break; |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1475 default: |
0 | 1476 witness = NULL; |
1477 break; | |
1478 } | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1479 trace_and_log_witness(witness); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1480 return witness; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1481 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1482 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1483 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1484 klassOop Dependencies::DepStream::check_call_site_dependency(CallSiteDepChange* changes) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1485 assert_locked_or_safepoint(Compile_lock); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1486 Dependencies::check_valid_dependency_type(type()); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1487 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1488 klassOop witness = NULL; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1489 switch (type()) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1490 case call_site_target_value: |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1491 witness = check_call_site_target_value(context_type(), argument(1), argument(2), changes); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1492 break; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1493 default: |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1494 witness = NULL; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1495 break; |
0 | 1496 } |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1497 trace_and_log_witness(witness); |
0 | 1498 return witness; |
1499 } | |
1500 | |
1501 | |
1502 klassOop Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) { | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1503 // Handle klass dependency |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1504 if (changes.is_klass_change() && changes.as_klass_change()->involves_context(context_type())) |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1505 return check_klass_dependency(changes.as_klass_change()); |
0 | 1506 |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1507 // Handle CallSite dependency |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1508 if (changes.is_call_site_change()) |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1509 return check_call_site_dependency(changes.as_call_site_change()); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1510 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1511 // irrelevant dependency; skip it |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1512 return NULL; |
0 | 1513 } |
1514 | |
1515 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1516 void DepChange::print() { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1517 int nsup = 0, nint = 0; |
0 | 1518 for (ContextStream str(*this); str.next(); ) { |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1519 klassOop k = str.klass(); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1520 switch (str.change_type()) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1521 case Change_new_type: |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1522 tty->print_cr(" dependee = %s", instanceKlass::cast(k)->external_name()); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1523 break; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1524 case Change_new_sub: |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1525 if (!WizardMode) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1526 ++nsup; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1527 } else { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1528 tty->print_cr(" context super = %s", instanceKlass::cast(k)->external_name()); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1529 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1530 break; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1531 case Change_new_impl: |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1532 if (!WizardMode) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1533 ++nint; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1534 } else { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1535 tty->print_cr(" context interface = %s", instanceKlass::cast(k)->external_name()); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1536 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1537 break; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1538 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1539 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1540 if (nsup + nint != 0) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1541 tty->print_cr(" context supers = %d, interfaces = %d", nsup, nint); |
0 | 1542 } |
1543 } | |
1544 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1545 void DepChange::ContextStream::start() { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1546 klassOop new_type = _changes.is_klass_change() ? _changes.as_klass_change()->new_type() : (klassOop) NULL; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1547 _change_type = (new_type == NULL ? NO_CHANGE : Start_Klass); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1548 _klass = new_type; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1549 _ti_base = NULL; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1550 _ti_index = 0; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1551 _ti_limit = 0; |
0 | 1552 } |
1553 | |
1554 bool DepChange::ContextStream::next() { | |
1555 switch (_change_type) { | |
1556 case Start_Klass: // initial state; _klass is the new type | |
1557 _ti_base = instanceKlass::cast(_klass)->transitive_interfaces(); | |
1558 _ti_index = 0; | |
1559 _change_type = Change_new_type; | |
1560 return true; | |
1561 case Change_new_type: | |
1562 // fall through: | |
1563 _change_type = Change_new_sub; | |
1564 case Change_new_sub: | |
54
d4a0f561287a
6598190: JPRT tests fail when run with -XX:+CheckUnhandledOops
sbohne
parents:
0
diff
changeset
|
1565 // 6598190: brackets workaround Sun Studio C++ compiler bug 6629277 |
d4a0f561287a
6598190: JPRT tests fail when run with -XX:+CheckUnhandledOops
sbohne
parents:
0
diff
changeset
|
1566 { |
d4a0f561287a
6598190: JPRT tests fail when run with -XX:+CheckUnhandledOops
sbohne
parents:
0
diff
changeset
|
1567 _klass = instanceKlass::cast(_klass)->super(); |
d4a0f561287a
6598190: JPRT tests fail when run with -XX:+CheckUnhandledOops
sbohne
parents:
0
diff
changeset
|
1568 if (_klass != NULL) { |
d4a0f561287a
6598190: JPRT tests fail when run with -XX:+CheckUnhandledOops
sbohne
parents:
0
diff
changeset
|
1569 return true; |
d4a0f561287a
6598190: JPRT tests fail when run with -XX:+CheckUnhandledOops
sbohne
parents:
0
diff
changeset
|
1570 } |
0 | 1571 } |
1572 // else set up _ti_limit and fall through: | |
1573 _ti_limit = (_ti_base == NULL) ? 0 : _ti_base->length(); | |
1574 _change_type = Change_new_impl; | |
1575 case Change_new_impl: | |
1576 if (_ti_index < _ti_limit) { | |
1577 _klass = klassOop( _ti_base->obj_at(_ti_index++) ); | |
1578 return true; | |
1579 } | |
1580 // fall through: | |
1581 _change_type = NO_CHANGE; // iterator is exhausted | |
1582 case NO_CHANGE: | |
1583 break; | |
1584 default: | |
1585 ShouldNotReachHere(); | |
1586 } | |
1587 return false; | |
1588 } | |
1589 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1590 void KlassDepChange::initialize() { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1591 // entire transaction must be under this lock: |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1592 assert_lock_strong(Compile_lock); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1593 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1594 // Mark all dependee and all its superclasses |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1595 // Mark transitive interfaces |
0 | 1596 for (ContextStream str(*this); str.next(); ) { |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1597 klassOop d = str.klass(); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1598 assert(!instanceKlass::cast(d)->is_marked_dependent(), "checking"); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1599 instanceKlass::cast(d)->set_is_marked_dependent(true); |
0 | 1600 } |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1601 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1602 |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1603 KlassDepChange::~KlassDepChange() { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1604 // Unmark all dependee and all its superclasses |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1605 // Unmark transitive interfaces |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1606 for (ContextStream str(*this); str.next(); ) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1607 klassOop d = str.klass(); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1608 instanceKlass::cast(d)->set_is_marked_dependent(false); |
0 | 1609 } |
1610 } | |
1611 | |
3852
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1612 bool KlassDepChange::involves_context(klassOop k) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1613 if (k == NULL || !Klass::cast(k)->oop_is_instance()) { |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1614 return false; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1615 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1616 instanceKlass* ik = instanceKlass::cast(k); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1617 bool is_contained = ik->is_marked_dependent(); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1618 assert(is_contained == Klass::cast(new_type())->is_subtype_of(k), |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1619 "correct marking of potential context types"); |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1620 return is_contained; |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1621 } |
fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents:
2426
diff
changeset
|
1622 |
0 | 1623 #ifndef PRODUCT |
1624 void Dependencies::print_statistics() { | |
1625 if (deps_find_witness_print != 0) { | |
1626 // Call one final time, to flush out the data. | |
1627 deps_find_witness_print = -1; | |
1628 count_find_witness_calls(); | |
1629 } | |
1630 } | |
1631 #endif |