Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/code/dependencies.hpp
+++ new/src/share/vm/code/dependencies.hpp
1 1 /*
2 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #ifndef SHARE_VM_CODE_DEPENDENCIES_HPP
26 26 #define SHARE_VM_CODE_DEPENDENCIES_HPP
27 27
28 +#include "ci/ciCallSite.hpp"
28 29 #include "ci/ciKlass.hpp"
30 +#include "ci/ciMethodHandle.hpp"
31 +#include "classfile/systemDictionary.hpp"
29 32 #include "code/compressedStream.hpp"
30 33 #include "code/nmethod.hpp"
31 34 #include "utilities/growableArray.hpp"
32 35
33 36 //** Dependencies represent assertions (approximate invariants) within
34 -// the class hierarchy. An example is an assertion that a given
35 -// method is not overridden; another example is that a type has only
36 -// one concrete subtype. Compiled code which relies on such
37 -// assertions must be discarded if they are overturned by changes in
38 -// the class hierarchy. We can think of these assertions as
39 -// approximate invariants, because we expect them to be overturned
37 +// the runtime system, e.g. class hierarchy changes. An example is an
38 +// assertion that a given method is not overridden; another example is
39 +// that a type has only one concrete subtype. Compiled code which
40 +// relies on such assertions must be discarded if they are overturned
41 +// by changes in the runtime system. We can think of these assertions
42 +// as approximate invariants, because we expect them to be overturned
40 43 // very infrequently. We are willing to perform expensive recovery
41 44 // operations when they are overturned. The benefit, of course, is
42 45 // performing optimistic optimizations (!) on the object code.
43 46 //
44 47 // Changes in the class hierarchy due to dynamic linking or
45 48 // class evolution can violate dependencies. There is enough
46 49 // indexing between classes and nmethods to make dependency
47 50 // checking reasonably efficient.
48 51
49 52 class ciEnv;
50 53 class nmethod;
51 54 class OopRecorder;
52 55 class xmlStream;
53 56 class CompileLog;
54 57 class DepChange;
58 +class KlassDepChange;
59 +class CallSiteDepChange;
55 60 class No_Safepoint_Verifier;
56 61
57 62 class Dependencies: public ResourceObj {
58 63 public:
59 64 // Note: In the comments on dependency types, most uses of the terms
60 65 // subtype and supertype are used in a "non-strict" or "inclusive"
61 66 // sense, and are starred to remind the reader of this fact.
62 67 // Strict uses of the terms use the word "proper".
63 68 //
64 69 // Specifically, every class is its own subtype* and supertype*.
65 70 // (This trick is easier than continually saying things like "Y is a
66 71 // subtype of X or X itself".)
67 72 //
68 73 // Sometimes we write X > Y to mean X is a proper supertype of Y.
69 74 // The notation X > {Y, Z} means X has proper subtypes Y, Z.
70 75 // The notation X.m > Y means that Y inherits m from X, while
71 76 // X.m > Y.m means Y overrides X.m. A star denotes abstractness,
72 77 // as *I > A, meaning (abstract) interface I is a super type of A,
73 78 // or A.*m > B.m, meaning B.m implements abstract method A.m.
74 79 //
75 80 // In this module, the terms "subtype" and "supertype" refer to
76 81 // Java-level reference type conversions, as detected by
77 82 // "instanceof" and performed by "checkcast" operations. The method
78 83 // Klass::is_subtype_of tests these relations. Note that "subtype"
79 84 // is richer than "subclass" (as tested by Klass::is_subclass_of),
80 85 // since it takes account of relations involving interface and array
81 86 // types.
82 87 //
83 88 // To avoid needless complexity, dependencies involving array types
84 89 // are not accepted. If you need to make an assertion about an
85 90 // array type, make the assertion about its corresponding element
86 91 // types. Any assertion that might change about an array type can
87 92 // be converted to an assertion about its element type.
88 93 //
89 94 // Most dependencies are evaluated over a "context type" CX, which
90 95 // stands for the set Subtypes(CX) of every Java type that is a subtype*
91 96 // of CX. When the system loads a new class or interface N, it is
92 97 // responsible for re-evaluating changed dependencies whose context
93 98 // type now includes N, that is, all super types of N.
94 99 //
95 100 enum DepType {
96 101 end_marker = 0,
97 102
98 103 // An 'evol' dependency simply notes that the contents of the
99 104 // method were used. If it evolves (is replaced), the nmethod
100 105 // must be recompiled. No other dependencies are implied.
101 106 evol_method,
102 107 FIRST_TYPE = evol_method,
103 108
104 109 // A context type CX is a leaf it if has no proper subtype.
105 110 leaf_type,
106 111
107 112 // An abstract class CX has exactly one concrete subtype CC.
108 113 abstract_with_unique_concrete_subtype,
109 114
110 115 // The type CX is purely abstract, with no concrete subtype* at all.
111 116 abstract_with_no_concrete_subtype,
112 117
113 118 // The concrete CX is free of concrete proper subtypes.
114 119 concrete_with_no_concrete_subtype,
115 120
116 121 // Given a method M1 and a context class CX, the set MM(CX, M1) of
117 122 // "concrete matching methods" in CX of M1 is the set of every
118 123 // concrete M2 for which it is possible to create an invokevirtual
119 124 // or invokeinterface call site that can reach either M1 or M2.
120 125 // That is, M1 and M2 share a name, signature, and vtable index.
121 126 // We wish to notice when the set MM(CX, M1) is just {M1}, or
122 127 // perhaps a set of two {M1,M2}, and issue dependencies on this.
123 128
124 129 // The set MM(CX, M1) can be computed by starting with any matching
125 130 // concrete M2 that is inherited into CX, and then walking the
126 131 // subtypes* of CX looking for concrete definitions.
127 132
128 133 // The parameters to this dependency are the method M1 and the
129 134 // context class CX. M1 must be either inherited in CX or defined
130 135 // in a subtype* of CX. It asserts that MM(CX, M1) is no greater
131 136 // than {M1}.
132 137 unique_concrete_method, // one unique concrete method under CX
133 138
134 139 // An "exclusive" assertion concerns two methods or subtypes, and
135 140 // declares that there are at most two (or perhaps later N>2)
136 141 // specific items that jointly satisfy the restriction.
137 142 // We list all items explicitly rather than just giving their
138 143 // count, for robustness in the face of complex schema changes.
139 144
140 145 // A context class CX (which may be either abstract or concrete)
141 146 // has two exclusive concrete subtypes* C1, C2 if every concrete
142 147 // subtype* of CX is either C1 or C2. Note that if neither C1 or C2
143 148 // are equal to CX, then CX itself must be abstract. But it is
144 149 // also possible (for example) that C1 is CX (a concrete class)
↓ open down ↓ |
80 lines elided |
↑ open up ↑ |
145 150 // and C2 is a proper subtype of C1.
146 151 abstract_with_exclusive_concrete_subtypes_2,
147 152
148 153 // This dependency asserts that MM(CX, M1) is no greater than {M1,M2}.
149 154 exclusive_concrete_methods_2,
150 155
151 156 // This dependency asserts that no instances of class or it's
152 157 // subclasses require finalization registration.
153 158 no_finalizable_subclasses,
154 159
160 + // This dependency asserts when the CallSite.target value changed.
161 + call_site_target_value,
162 +
155 163 TYPE_LIMIT
156 164 };
157 165 enum {
158 166 LG2_TYPE_LIMIT = 4, // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))
159 167
160 168 // handy categorizations of dependency types:
161 169 all_types = ((1<<TYPE_LIMIT)-1) & ((-1)<<FIRST_TYPE),
162 170 non_ctxk_types = (1<<evol_method),
163 171 ctxk_types = all_types & ~non_ctxk_types,
164 172
165 173 max_arg_count = 3, // current maximum number of arguments (incl. ctxk)
166 174
167 175 // A "context type" is a class or interface that
168 176 // provides context for evaluating a dependency.
169 177 // When present, it is one of the arguments (dep_context_arg).
170 178 //
171 179 // If a dependency does not have a context type, there is a
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
172 180 // default context, depending on the type of the dependency.
173 181 // This bit signals that a default context has been compressed away.
174 182 default_context_type_bit = (1<<LG2_TYPE_LIMIT)
175 183 };
176 184
177 185 static const char* dep_name(DepType dept);
178 186 static int dep_args(DepType dept);
179 187 static int dep_context_arg(DepType dept) {
180 188 return dept_in_mask(dept, ctxk_types)? 0: -1;
181 189 }
190 + static void check_valid_dependency_type(DepType dept);
182 191
183 192 private:
184 193 // State for writing a new set of dependencies:
185 194 GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept))
186 195 GrowableArray<ciObject*>* _deps[TYPE_LIMIT];
187 196
188 197 static const char* _dep_name[TYPE_LIMIT];
189 198 static int _dep_args[TYPE_LIMIT];
190 199
191 200 static bool dept_in_mask(DepType dept, int mask) {
192 201 return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;
193 202 }
194 203
195 204 bool note_dep_seen(int dept, ciObject* x) {
196 205 assert(dept < BitsPerInt, "oob");
197 206 int x_id = x->ident();
198 207 assert(_dep_seen != NULL, "deps must be writable");
199 208 int seen = _dep_seen->at_grow(x_id, 0);
200 209 _dep_seen->at_put(x_id, seen | (1<<dept));
201 210 // return true if we've already seen dept/x
202 211 return (seen & (1<<dept)) != 0;
203 212 }
204 213
205 214 bool maybe_merge_ctxk(GrowableArray<ciObject*>* deps,
206 215 int ctxk_i, ciKlass* ctxk);
207 216
208 217 void sort_all_deps();
209 218 size_t estimate_size_in_bytes();
210 219
211 220 // Initialize _deps, etc.
212 221 void initialize(ciEnv* env);
213 222
214 223 // State for making a new set of dependencies:
215 224 OopRecorder* _oop_recorder;
216 225
217 226 // Logging support
218 227 CompileLog* _log;
219 228
220 229 address _content_bytes; // everything but the oop references, encoded
221 230 size_t _size_in_bytes;
222 231
223 232 public:
224 233 // Make a new empty dependencies set.
225 234 Dependencies(ciEnv* env) {
226 235 initialize(env);
227 236 }
228 237
229 238 private:
230 239 // Check for a valid context type.
231 240 // Enforce the restriction against array types.
232 241 static void check_ctxk(ciKlass* ctxk) {
233 242 assert(ctxk->is_instance_klass(), "java types only");
234 243 }
235 244 static void check_ctxk_concrete(ciKlass* ctxk) {
236 245 assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");
237 246 }
238 247 static void check_ctxk_abstract(ciKlass* ctxk) {
239 248 check_ctxk(ctxk);
240 249 assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
241 250 }
242 251
243 252 void assert_common_1(DepType dept, ciObject* x);
244 253 void assert_common_2(DepType dept, ciKlass* ctxk, ciObject* x);
245 254 void assert_common_3(DepType dept, ciKlass* ctxk, ciObject* x, ciObject* x2);
246 255
247 256 public:
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
248 257 // Adding assertions to a new dependency set at compile time:
249 258 void assert_evol_method(ciMethod* m);
250 259 void assert_leaf_type(ciKlass* ctxk);
251 260 void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
252 261 void assert_abstract_with_no_concrete_subtype(ciKlass* ctxk);
253 262 void assert_concrete_with_no_concrete_subtype(ciKlass* ctxk);
254 263 void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);
255 264 void assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2);
256 265 void assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2);
257 266 void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
267 + void assert_call_site_target_value(ciKlass* ctxk, ciCallSite* call_site, ciMethodHandle* method_handle);
258 268
259 269 // Define whether a given method or type is concrete.
260 270 // These methods define the term "concrete" as used in this module.
261 271 // For this module, an "abstract" class is one which is non-concrete.
262 272 //
263 273 // Future optimizations may allow some classes to remain
264 274 // non-concrete until their first instantiation, and allow some
265 275 // methods to remain non-concrete until their first invocation.
266 276 // In that case, there would be a middle ground between concrete
267 277 // and abstract (as defined by the Java language and VM).
268 278 static bool is_concrete_klass(klassOop k); // k is instantiable
269 279 static bool is_concrete_method(methodOop m); // m is invocable
270 280 static Klass* find_finalizable_subclass(Klass* k);
271 281
272 282 // These versions of the concreteness queries work through the CI.
273 283 // The CI versions are allowed to skew sometimes from the VM
274 284 // (oop-based) versions. The cost of such a difference is a
275 285 // (safely) aborted compilation, or a deoptimization, or a missed
276 286 // optimization opportunity.
277 287 //
278 288 // In order to prevent spurious assertions, query results must
279 289 // remain stable within any single ciEnv instance. (I.e., they must
280 290 // not go back into the VM to get their value; they must cache the
281 291 // bit in the CI, either eagerly or lazily.)
282 292 static bool is_concrete_klass(ciInstanceKlass* k); // k appears instantiable
283 293 static bool is_concrete_method(ciMethod* m); // m appears invocable
284 294 static bool has_finalizable_subclass(ciInstanceKlass* k);
285 295
286 296 // As a general rule, it is OK to compile under the assumption that
287 297 // a given type or method is concrete, even if it at some future
288 298 // point becomes abstract. So dependency checking is one-sided, in
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
289 299 // that it permits supposedly concrete classes or methods to turn up
290 300 // as really abstract. (This shouldn't happen, except during class
291 301 // evolution, but that's the logic of the checking.) However, if a
292 302 // supposedly abstract class or method suddenly becomes concrete, a
293 303 // dependency on it must fail.
294 304
295 305 // Checking old assertions at run-time (in the VM only):
296 306 static klassOop check_evol_method(methodOop m);
297 307 static klassOop check_leaf_type(klassOop ctxk);
298 308 static klassOop check_abstract_with_unique_concrete_subtype(klassOop ctxk, klassOop conck,
299 - DepChange* changes = NULL);
309 + KlassDepChange* changes = NULL);
300 310 static klassOop check_abstract_with_no_concrete_subtype(klassOop ctxk,
301 - DepChange* changes = NULL);
311 + KlassDepChange* changes = NULL);
302 312 static klassOop check_concrete_with_no_concrete_subtype(klassOop ctxk,
303 - DepChange* changes = NULL);
313 + KlassDepChange* changes = NULL);
304 314 static klassOop check_unique_concrete_method(klassOop ctxk, methodOop uniqm,
305 - DepChange* changes = NULL);
315 + KlassDepChange* changes = NULL);
306 316 static klassOop check_abstract_with_exclusive_concrete_subtypes(klassOop ctxk, klassOop k1, klassOop k2,
307 - DepChange* changes = NULL);
317 + KlassDepChange* changes = NULL);
308 318 static klassOop check_exclusive_concrete_methods(klassOop ctxk, methodOop m1, methodOop m2,
309 - DepChange* changes = NULL);
310 - static klassOop check_has_no_finalizable_subclasses(klassOop ctxk,
311 - DepChange* changes = NULL);
319 + KlassDepChange* changes = NULL);
320 + static klassOop check_has_no_finalizable_subclasses(klassOop ctxk, KlassDepChange* changes = NULL);
321 + static klassOop check_call_site_target_value(klassOop ctxk, oop call_site, oop method_handle, CallSiteDepChange* changes = NULL);
312 322 // A returned klassOop is NULL if the dependency assertion is still
313 323 // valid. A non-NULL klassOop is a 'witness' to the assertion
314 324 // failure, a point in the class hierarchy where the assertion has
315 325 // been proven false. For example, if check_leaf_type returns
316 326 // non-NULL, the value is a subtype of the supposed leaf type. This
317 327 // witness value may be useful for logging the dependency failure.
318 328 // Note that, when a dependency fails, there may be several possible
319 329 // witnesses to the failure. The value returned from the check_foo
320 330 // method is chosen arbitrarily.
321 331
322 332 // The 'changes' value, if non-null, requests a limited spot-check
323 333 // near the indicated recent changes in the class hierarchy.
324 334 // It is used by DepStream::spot_check_dependency_at.
325 335
326 336 // Detecting possible new assertions:
327 337 static klassOop find_unique_concrete_subtype(klassOop ctxk);
328 338 static methodOop find_unique_concrete_method(klassOop ctxk, methodOop m);
329 339 static int find_exclusive_concrete_subtypes(klassOop ctxk, int klen, klassOop k[]);
330 340 static int find_exclusive_concrete_methods(klassOop ctxk, int mlen, methodOop m[]);
331 341
332 342 // Create the encoding which will be stored in an nmethod.
333 343 void encode_content_bytes();
334 344
335 345 address content_bytes() {
336 346 assert(_content_bytes != NULL, "encode it first");
337 347 return _content_bytes;
338 348 }
339 349 size_t size_in_bytes() {
340 350 assert(_content_bytes != NULL, "encode it first");
341 351 return _size_in_bytes;
342 352 }
343 353
344 354 OopRecorder* oop_recorder() { return _oop_recorder; }
345 355 CompileLog* log() { return _log; }
346 356
347 357 void copy_to(nmethod* nm);
348 358
349 359 void log_all_dependencies();
350 360 void log_dependency(DepType dept, int nargs, ciObject* args[]) {
351 361 write_dependency_to(log(), dept, nargs, args);
352 362 }
353 363 void log_dependency(DepType dept,
354 364 ciObject* x0,
355 365 ciObject* x1 = NULL,
356 366 ciObject* x2 = NULL) {
357 367 if (log() == NULL) return;
358 368 ciObject* args[max_arg_count];
359 369 args[0] = x0;
360 370 args[1] = x1;
361 371 args[2] = x2;
362 372 assert(2 < max_arg_count, "");
363 373 log_dependency(dept, dep_args(dept), args);
364 374 }
365 375
366 376 static void write_dependency_to(CompileLog* log,
367 377 DepType dept,
368 378 int nargs, ciObject* args[],
369 379 klassOop witness = NULL);
370 380 static void write_dependency_to(CompileLog* log,
371 381 DepType dept,
372 382 int nargs, oop args[],
373 383 klassOop witness = NULL);
374 384 static void write_dependency_to(xmlStream* xtty,
375 385 DepType dept,
376 386 int nargs, oop args[],
377 387 klassOop witness = NULL);
378 388 static void print_dependency(DepType dept,
379 389 int nargs, oop args[],
380 390 klassOop witness = NULL);
381 391
382 392 private:
383 393 // helper for encoding common context types as zero:
384 394 static ciKlass* ctxk_encoded_as_null(DepType dept, ciObject* x);
385 395
386 396 static klassOop ctxk_encoded_as_null(DepType dept, oop x);
387 397
388 398 public:
389 399 // Use this to iterate over an nmethod's dependency set.
390 400 // Works on new and old dependency sets.
391 401 // Usage:
392 402 //
393 403 // ;
394 404 // Dependencies::DepType dept;
395 405 // for (Dependencies::DepStream deps(nm); deps.next(); ) {
396 406 // ...
397 407 // }
398 408 //
399 409 // The caller must be in the VM, since oops are not wrapped in handles.
400 410 class DepStream {
401 411 private:
402 412 nmethod* _code; // null if in a compiler thread
403 413 Dependencies* _deps; // null if not in a compiler thread
404 414 CompressedReadStream _bytes;
405 415 #ifdef ASSERT
406 416 size_t _byte_limit;
407 417 #endif
↓ open down ↓ |
86 lines elided |
↑ open up ↑ |
408 418
409 419 // iteration variables:
410 420 DepType _type;
411 421 int _xi[max_arg_count+1];
412 422
413 423 void initial_asserts(size_t byte_limit) NOT_DEBUG({});
414 424
415 425 inline oop recorded_oop_at(int i);
416 426 // => _code? _code->oop_at(i): *_deps->_oop_recorder->handle_at(i)
417 427
418 - klassOop check_dependency_impl(DepChange* changes);
428 + klassOop check_klass_dependency(KlassDepChange* changes);
429 + klassOop check_call_site_dependency(CallSiteDepChange* changes);
430 +
431 + void trace_and_log_witness(klassOop witness);
419 432
420 433 public:
421 434 DepStream(Dependencies* deps)
422 435 : _deps(deps),
423 436 _code(NULL),
424 437 _bytes(deps->content_bytes())
425 438 {
426 439 initial_asserts(deps->size_in_bytes());
427 440 }
428 441 DepStream(nmethod* code)
429 442 : _deps(NULL),
430 443 _code(code),
431 444 _bytes(code->dependencies_begin())
432 445 {
433 446 initial_asserts(code->dependencies_size());
434 447 }
435 448
436 449 bool next();
437 450
438 451 DepType type() { return _type; }
439 452 int argument_count() { return dep_args(type()); }
440 453 int argument_index(int i) { assert(0 <= i && i < argument_count(), "oob");
441 454 return _xi[i]; }
442 455 oop argument(int i); // => recorded_oop_at(argument_index(i))
443 456 klassOop context_type();
444 457
445 458 methodOop method_argument(int i) {
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
446 459 oop x = argument(i);
447 460 assert(x->is_method(), "type");
448 461 return (methodOop) x;
449 462 }
450 463 klassOop type_argument(int i) {
451 464 oop x = argument(i);
452 465 assert(x->is_klass(), "type");
453 466 return (klassOop) x;
454 467 }
455 468
456 - // The point of the whole exercise: Is this dep is still OK?
469 + // The point of the whole exercise: Is this dep still OK?
457 470 klassOop check_dependency() {
458 - return check_dependency_impl(NULL);
471 + klassOop result = check_klass_dependency(NULL);
472 + if (result != NULL) return result;
473 + return check_call_site_dependency(NULL);
459 474 }
475 +
460 476 // A lighter version: Checks only around recent changes in a class
461 477 // hierarchy. (See Universe::flush_dependents_on.)
462 478 klassOop spot_check_dependency_at(DepChange& changes);
463 479
464 480 // Log the current dependency to xtty or compilation log.
465 481 void log_dependency(klassOop witness = NULL);
466 482
467 483 // Print the current dependency to tty.
468 484 void print_dependency(klassOop witness = NULL, bool verbose = false);
469 485 };
470 486 friend class Dependencies::DepStream;
471 487
472 488 static void print_statistics() PRODUCT_RETURN;
473 489 };
474 490
475 -// A class hierarchy change coming through the VM (under the Compile_lock).
476 -// The change is structured as a single new type with any number of supers
477 -// and implemented interface types. Other than the new type, any of the
478 -// super types can be context types for a relevant dependency, which the
479 -// new type could invalidate.
491 +
492 +// Every particular DepChange is a sub-class of this class.
480 493 class DepChange : public StackObj {
481 494 public:
495 + // What kind of DepChange is this?
496 + virtual bool is_klass_change() const { return false; }
497 + virtual bool is_call_site_change() const { return false; }
498 +
499 + // Subclass casting with assertions.
500 + KlassDepChange* as_klass_change() {
501 + assert(is_klass_change(), "bad cast");
502 + return (KlassDepChange*) this;
503 + }
504 + CallSiteDepChange* as_call_site_change() {
505 + assert(is_call_site_change(), "bad cast");
506 + return (CallSiteDepChange*) this;
507 + }
508 +
509 + void print();
510 +
511 + public:
482 512 enum ChangeType {
483 513 NO_CHANGE = 0, // an uninvolved klass
484 514 Change_new_type, // a newly loaded type
485 515 Change_new_sub, // a super with a new subtype
486 516 Change_new_impl, // an interface with a new implementation
487 517 CHANGE_LIMIT,
488 518 Start_Klass = CHANGE_LIMIT // internal indicator for ContextStream
489 519 };
490 520
491 - private:
492 - // each change set is rooted in exactly one new type (at present):
493 - KlassHandle _new_type;
494 -
495 - void initialize();
496 -
497 - public:
498 - // notes the new type, marks it and all its super-types
499 - DepChange(KlassHandle new_type)
500 - : _new_type(new_type)
501 - {
502 - initialize();
503 - }
504 -
505 - // cleans up the marks
506 - ~DepChange();
507 -
508 - klassOop new_type() { return _new_type(); }
509 -
510 - // involves_context(k) is true if k is new_type or any of the super types
511 - bool involves_context(klassOop k);
512 -
513 521 // Usage:
514 522 // for (DepChange::ContextStream str(changes); str.next(); ) {
515 523 // klassOop k = str.klass();
516 524 // switch (str.change_type()) {
517 525 // ...
518 526 // }
519 527 // }
520 528 class ContextStream : public StackObj {
521 529 private:
522 530 DepChange& _changes;
523 531 friend class DepChange;
524 532
525 533 // iteration variables:
526 534 ChangeType _change_type;
527 535 klassOop _klass;
528 536 objArrayOop _ti_base; // i.e., transitive_interfaces
529 537 int _ti_index;
530 538 int _ti_limit;
531 539
532 540 // start at the beginning:
533 - void start() {
534 - klassOop new_type = _changes.new_type();
535 - _change_type = (new_type == NULL ? NO_CHANGE: Start_Klass);
536 - _klass = new_type;
537 - _ti_base = NULL;
538 - _ti_index = 0;
539 - _ti_limit = 0;
540 - }
541 + void start();
541 542
542 543 public:
543 544 ContextStream(DepChange& changes)
544 545 : _changes(changes)
545 546 { start(); }
546 547
547 548 ContextStream(DepChange& changes, No_Safepoint_Verifier& nsv)
548 549 : _changes(changes)
549 550 // the nsv argument makes it safe to hold oops like _klass
550 551 { start(); }
551 552
552 553 bool next();
553 554
554 555 ChangeType change_type() { return _change_type; }
555 556 klassOop klass() { return _klass; }
556 557 };
557 558 friend class DepChange::ContextStream;
559 +};
558 560
559 - void print();
561 +
562 +// A class hierarchy change coming through the VM (under the Compile_lock).
563 +// The change is structured as a single new type with any number of supers
564 +// and implemented interface types. Other than the new type, any of the
565 +// super types can be context types for a relevant dependency, which the
566 +// new type could invalidate.
567 +class KlassDepChange : public DepChange {
568 + private:
569 + // each change set is rooted in exactly one new type (at present):
570 + KlassHandle _new_type;
571 +
572 + void initialize();
573 +
574 + public:
575 + // notes the new type, marks it and all its super-types
576 + KlassDepChange(KlassHandle new_type)
577 + : _new_type(new_type)
578 + {
579 + initialize();
580 + }
581 +
582 + // cleans up the marks
583 + ~KlassDepChange();
584 +
585 + // What kind of DepChange is this?
586 + virtual bool is_klass_change() const { return true; }
587 +
588 + klassOop new_type() { return _new_type(); }
589 +
590 + // involves_context(k) is true if k is new_type or any of the super types
591 + bool involves_context(klassOop k);
592 +};
593 +
594 +
595 +// A CallSite has changed its target.
596 +class CallSiteDepChange : public DepChange {
597 + private:
598 + Handle _call_site;
599 + Handle _method_handle;
600 +
601 + public:
602 + CallSiteDepChange(Handle call_site, Handle method_handle)
603 + : _call_site(call_site),
604 + _method_handle(method_handle)
605 + {
606 + assert(_call_site() ->is_a(SystemDictionary::CallSite_klass()), "must be");
607 + assert(_method_handle()->is_a(SystemDictionary::MethodHandle_klass()), "must be");
608 + }
609 +
610 + // What kind of DepChange is this?
611 + virtual bool is_call_site_change() const { return true; }
612 +
613 + oop call_site() const { return _call_site(); }
614 + oop method_handle() const { return _method_handle(); }
560 615 };
561 616
562 617 #endif // SHARE_VM_CODE_DEPENDENCIES_HPP
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX