1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/dependencies.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,550 @@ 1.4 +/* 1.5 + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +//** Dependencies represent assertions (approximate invariants) within 1.29 +// the class hierarchy. An example is an assertion that a given 1.30 +// method is not overridden; another example is that a type has only 1.31 +// one concrete subtype. Compiled code which relies on such 1.32 +// assertions must be discarded if they are overturned by changes in 1.33 +// the class hierarchy. We can think of these assertions as 1.34 +// approximate invariants, because we expect them to be overturned 1.35 +// very infrequently. We are willing to perform expensive recovery 1.36 +// operations when they are overturned. The benefit, of course, is 1.37 +// performing optimistic optimizations (!) on the object code. 1.38 +// 1.39 +// Changes in the class hierarchy due to dynamic linking or 1.40 +// class evolution can violate dependencies. There is enough 1.41 +// indexing between classes and nmethods to make dependency 1.42 +// checking reasonably efficient. 1.43 + 1.44 +class ciEnv; 1.45 +class nmethod; 1.46 +class OopRecorder; 1.47 +class xmlStream; 1.48 +class CompileLog; 1.49 +class DepChange; 1.50 +class No_Safepoint_Verifier; 1.51 + 1.52 +class Dependencies: public ResourceObj { 1.53 + public: 1.54 + // Note: In the comments on dependency types, most uses of the terms 1.55 + // subtype and supertype are used in a "non-strict" or "inclusive" 1.56 + // sense, and are starred to remind the reader of this fact. 1.57 + // Strict uses of the terms use the word "proper". 1.58 + // 1.59 + // Specifically, every class is its own subtype* and supertype*. 1.60 + // (This trick is easier than continually saying things like "Y is a 1.61 + // subtype of X or X itself".) 1.62 + // 1.63 + // Sometimes we write X > Y to mean X is a proper supertype of Y. 1.64 + // The notation X > {Y, Z} means X has proper subtypes Y, Z. 1.65 + // The notation X.m > Y means that Y inherits m from X, while 1.66 + // X.m > Y.m means Y overrides X.m. A star denotes abstractness, 1.67 + // as *I > A, meaning (abstract) interface I is a super type of A, 1.68 + // or A.*m > B.m, meaning B.m implements abstract method A.m. 1.69 + // 1.70 + // In this module, the terms "subtype" and "supertype" refer to 1.71 + // Java-level reference type conversions, as detected by 1.72 + // "instanceof" and performed by "checkcast" operations. The method 1.73 + // Klass::is_subtype_of tests these relations. Note that "subtype" 1.74 + // is richer than "subclass" (as tested by Klass::is_subclass_of), 1.75 + // since it takes account of relations involving interface and array 1.76 + // types. 1.77 + // 1.78 + // To avoid needless complexity, dependencies involving array types 1.79 + // are not accepted. If you need to make an assertion about an 1.80 + // array type, make the assertion about its corresponding element 1.81 + // types. Any assertion that might change about an array type can 1.82 + // be converted to an assertion about its element type. 1.83 + // 1.84 + // Most dependencies are evaluated over a "context type" CX, which 1.85 + // stands for the set Subtypes(CX) of every Java type that is a subtype* 1.86 + // of CX. When the system loads a new class or interface N, it is 1.87 + // responsible for re-evaluating changed dependencies whose context 1.88 + // type now includes N, that is, all super types of N. 1.89 + // 1.90 + enum DepType { 1.91 + end_marker = 0, 1.92 + 1.93 + // An 'evol' dependency simply notes that the contents of the 1.94 + // method were used. If it evolves (is replaced), the nmethod 1.95 + // must be recompiled. No other dependencies are implied. 1.96 + evol_method, 1.97 + FIRST_TYPE = evol_method, 1.98 + 1.99 + // A context type CX is a leaf it if has no proper subtype. 1.100 + leaf_type, 1.101 + 1.102 + // An abstract class CX has exactly one concrete subtype CC. 1.103 + abstract_with_unique_concrete_subtype, 1.104 + 1.105 + // The type CX is purely abstract, with no concrete subtype* at all. 1.106 + abstract_with_no_concrete_subtype, 1.107 + 1.108 + // The concrete CX is free of concrete proper subtypes. 1.109 + concrete_with_no_concrete_subtype, 1.110 + 1.111 + // Given a method M1 and a context class CX, the set MM(CX, M1) of 1.112 + // "concrete matching methods" in CX of M1 is the set of every 1.113 + // concrete M2 for which it is possible to create an invokevirtual 1.114 + // or invokeinterface call site that can reach either M1 or M2. 1.115 + // That is, M1 and M2 share a name, signature, and vtable index. 1.116 + // We wish to notice when the set MM(CX, M1) is just {M1}, or 1.117 + // perhaps a set of two {M1,M2}, and issue dependencies on this. 1.118 + 1.119 + // The set MM(CX, M1) can be computed by starting with any matching 1.120 + // concrete M2 that is inherited into CX, and then walking the 1.121 + // subtypes* of CX looking for concrete definitions. 1.122 + 1.123 + // The parameters to this dependency are the method M1 and the 1.124 + // context class CX. M1 must be either inherited in CX or defined 1.125 + // in a subtype* of CX. It asserts that MM(CX, M1) is no greater 1.126 + // than {M1}. 1.127 + unique_concrete_method, // one unique concrete method under CX 1.128 + 1.129 + // An "exclusive" assertion concerns two methods or subtypes, and 1.130 + // declares that there are at most two (or perhaps later N>2) 1.131 + // specific items that jointly satisfy the restriction. 1.132 + // We list all items explicitly rather than just giving their 1.133 + // count, for robustness in the face of complex schema changes. 1.134 + 1.135 + // A context class CX (which may be either abstract or concrete) 1.136 + // has two exclusive concrete subtypes* C1, C2 if every concrete 1.137 + // subtype* of CX is either C1 or C2. Note that if neither C1 or C2 1.138 + // are equal to CX, then CX itself must be abstract. But it is 1.139 + // also possible (for example) that C1 is CX (a concrete class) 1.140 + // and C2 is a proper subtype of C1. 1.141 + abstract_with_exclusive_concrete_subtypes_2, 1.142 + 1.143 + // This dependency asserts that MM(CX, M1) is no greater than {M1,M2}. 1.144 + exclusive_concrete_methods_2, 1.145 + 1.146 + // This dependency asserts that no instances of class or it's 1.147 + // subclasses require finalization registration. 1.148 + no_finalizable_subclasses, 1.149 + 1.150 + TYPE_LIMIT 1.151 + }; 1.152 + enum { 1.153 + LG2_TYPE_LIMIT = 4, // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT)) 1.154 + 1.155 + // handy categorizations of dependency types: 1.156 + all_types = ((1<<TYPE_LIMIT)-1) & ((-1)<<FIRST_TYPE), 1.157 + non_ctxk_types = (1<<evol_method), 1.158 + ctxk_types = all_types & ~non_ctxk_types, 1.159 + 1.160 + max_arg_count = 3, // current maximum number of arguments (incl. ctxk) 1.161 + 1.162 + // A "context type" is a class or interface that 1.163 + // provides context for evaluating a dependency. 1.164 + // When present, it is one of the arguments (dep_context_arg). 1.165 + // 1.166 + // If a dependency does not have a context type, there is a 1.167 + // default context, depending on the type of the dependency. 1.168 + // This bit signals that a default context has been compressed away. 1.169 + default_context_type_bit = (1<<LG2_TYPE_LIMIT) 1.170 + }; 1.171 + 1.172 + static const char* dep_name(DepType dept); 1.173 + static int dep_args(DepType dept); 1.174 + static int dep_context_arg(DepType dept) { 1.175 + return dept_in_mask(dept, ctxk_types)? 0: -1; 1.176 + } 1.177 + 1.178 + private: 1.179 + // State for writing a new set of dependencies: 1.180 + GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept)) 1.181 + GrowableArray<ciObject*>* _deps[TYPE_LIMIT]; 1.182 + 1.183 + static const char* _dep_name[TYPE_LIMIT]; 1.184 + static int _dep_args[TYPE_LIMIT]; 1.185 + 1.186 + static bool dept_in_mask(DepType dept, int mask) { 1.187 + return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0; 1.188 + } 1.189 + 1.190 + bool note_dep_seen(int dept, ciObject* x) { 1.191 + assert(dept < BitsPerInt, "oob"); 1.192 + int x_id = x->ident(); 1.193 + assert(_dep_seen != NULL, "deps must be writable"); 1.194 + int seen = _dep_seen->at_grow(x_id, 0); 1.195 + _dep_seen->at_put(x_id, seen | (1<<dept)); 1.196 + // return true if we've already seen dept/x 1.197 + return (seen & (1<<dept)) != 0; 1.198 + } 1.199 + 1.200 + bool maybe_merge_ctxk(GrowableArray<ciObject*>* deps, 1.201 + int ctxk_i, ciKlass* ctxk); 1.202 + 1.203 + void sort_all_deps(); 1.204 + size_t estimate_size_in_bytes(); 1.205 + 1.206 + // Initialize _deps, etc. 1.207 + void initialize(ciEnv* env); 1.208 + 1.209 + // State for making a new set of dependencies: 1.210 + OopRecorder* _oop_recorder; 1.211 + 1.212 + // Logging support 1.213 + CompileLog* _log; 1.214 + 1.215 + address _content_bytes; // everything but the oop references, encoded 1.216 + size_t _size_in_bytes; 1.217 + 1.218 + public: 1.219 + // Make a new empty dependencies set. 1.220 + Dependencies(ciEnv* env) { 1.221 + initialize(env); 1.222 + } 1.223 + 1.224 + private: 1.225 + // Check for a valid context type. 1.226 + // Enforce the restriction against array types. 1.227 + static void check_ctxk(ciKlass* ctxk) { 1.228 + assert(ctxk->is_instance_klass(), "java types only"); 1.229 + } 1.230 + static void check_ctxk_concrete(ciKlass* ctxk) { 1.231 + assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete"); 1.232 + } 1.233 + static void check_ctxk_abstract(ciKlass* ctxk) { 1.234 + check_ctxk(ctxk); 1.235 + assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract"); 1.236 + } 1.237 + 1.238 + void assert_common_1(DepType dept, ciObject* x); 1.239 + void assert_common_2(DepType dept, ciKlass* ctxk, ciObject* x); 1.240 + void assert_common_3(DepType dept, ciKlass* ctxk, ciObject* x, ciObject* x2); 1.241 + 1.242 + public: 1.243 + // Adding assertions to a new dependency set at compile time: 1.244 + void assert_evol_method(ciMethod* m); 1.245 + void assert_leaf_type(ciKlass* ctxk); 1.246 + void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck); 1.247 + void assert_abstract_with_no_concrete_subtype(ciKlass* ctxk); 1.248 + void assert_concrete_with_no_concrete_subtype(ciKlass* ctxk); 1.249 + void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm); 1.250 + void assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2); 1.251 + void assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2); 1.252 + void assert_has_no_finalizable_subclasses(ciKlass* ctxk); 1.253 + 1.254 + // Define whether a given method or type is concrete. 1.255 + // These methods define the term "concrete" as used in this module. 1.256 + // For this module, an "abstract" class is one which is non-concrete. 1.257 + // 1.258 + // Future optimizations may allow some classes to remain 1.259 + // non-concrete until their first instantiation, and allow some 1.260 + // methods to remain non-concrete until their first invocation. 1.261 + // In that case, there would be a middle ground between concrete 1.262 + // and abstract (as defined by the Java language and VM). 1.263 + static bool is_concrete_klass(klassOop k); // k is instantiable 1.264 + static bool is_concrete_method(methodOop m); // m is invocable 1.265 + static Klass* find_finalizable_subclass(Klass* k); 1.266 + 1.267 + // These versions of the concreteness queries work through the CI. 1.268 + // The CI versions are allowed to skew sometimes from the VM 1.269 + // (oop-based) versions. The cost of such a difference is a 1.270 + // (safely) aborted compilation, or a deoptimization, or a missed 1.271 + // optimization opportunity. 1.272 + // 1.273 + // In order to prevent spurious assertions, query results must 1.274 + // remain stable within any single ciEnv instance. (I.e., they must 1.275 + // not go back into the VM to get their value; they must cache the 1.276 + // bit in the CI, either eagerly or lazily.) 1.277 + static bool is_concrete_klass(ciInstanceKlass* k); // k appears instantiable 1.278 + static bool is_concrete_method(ciMethod* m); // m appears invocable 1.279 + static bool has_finalizable_subclass(ciInstanceKlass* k); 1.280 + 1.281 + // As a general rule, it is OK to compile under the assumption that 1.282 + // a given type or method is concrete, even if it at some future 1.283 + // point becomes abstract. So dependency checking is one-sided, in 1.284 + // that it permits supposedly concrete classes or methods to turn up 1.285 + // as really abstract. (This shouldn't happen, except during class 1.286 + // evolution, but that's the logic of the checking.) However, if a 1.287 + // supposedly abstract class or method suddenly becomes concrete, a 1.288 + // dependency on it must fail. 1.289 + 1.290 + // Checking old assertions at run-time (in the VM only): 1.291 + static klassOop check_evol_method(methodOop m); 1.292 + static klassOop check_leaf_type(klassOop ctxk); 1.293 + static klassOop check_abstract_with_unique_concrete_subtype(klassOop ctxk, klassOop conck, 1.294 + DepChange* changes = NULL); 1.295 + static klassOop check_abstract_with_no_concrete_subtype(klassOop ctxk, 1.296 + DepChange* changes = NULL); 1.297 + static klassOop check_concrete_with_no_concrete_subtype(klassOop ctxk, 1.298 + DepChange* changes = NULL); 1.299 + static klassOop check_unique_concrete_method(klassOop ctxk, methodOop uniqm, 1.300 + DepChange* changes = NULL); 1.301 + static klassOop check_abstract_with_exclusive_concrete_subtypes(klassOop ctxk, klassOop k1, klassOop k2, 1.302 + DepChange* changes = NULL); 1.303 + static klassOop check_exclusive_concrete_methods(klassOop ctxk, methodOop m1, methodOop m2, 1.304 + DepChange* changes = NULL); 1.305 + static klassOop check_has_no_finalizable_subclasses(klassOop ctxk, 1.306 + DepChange* changes = NULL); 1.307 + // A returned klassOop is NULL if the dependency assertion is still 1.308 + // valid. A non-NULL klassOop is a 'witness' to the assertion 1.309 + // failure, a point in the class hierarchy where the assertion has 1.310 + // been proven false. For example, if check_leaf_type returns 1.311 + // non-NULL, the value is a subtype of the supposed leaf type. This 1.312 + // witness value may be useful for logging the dependency failure. 1.313 + // Note that, when a dependency fails, there may be several possible 1.314 + // witnesses to the failure. The value returned from the check_foo 1.315 + // method is chosen arbitrarily. 1.316 + 1.317 + // The 'changes' value, if non-null, requests a limited spot-check 1.318 + // near the indicated recent changes in the class hierarchy. 1.319 + // It is used by DepStream::spot_check_dependency_at. 1.320 + 1.321 + // Detecting possible new assertions: 1.322 + static klassOop find_unique_concrete_subtype(klassOop ctxk); 1.323 + static methodOop find_unique_concrete_method(klassOop ctxk, methodOop m); 1.324 + static int find_exclusive_concrete_subtypes(klassOop ctxk, int klen, klassOop k[]); 1.325 + static int find_exclusive_concrete_methods(klassOop ctxk, int mlen, methodOop m[]); 1.326 + 1.327 + // Create the encoding which will be stored in an nmethod. 1.328 + void encode_content_bytes(); 1.329 + 1.330 + address content_bytes() { 1.331 + assert(_content_bytes != NULL, "encode it first"); 1.332 + return _content_bytes; 1.333 + } 1.334 + size_t size_in_bytes() { 1.335 + assert(_content_bytes != NULL, "encode it first"); 1.336 + return _size_in_bytes; 1.337 + } 1.338 + 1.339 + OopRecorder* oop_recorder() { return _oop_recorder; } 1.340 + CompileLog* log() { return _log; } 1.341 + 1.342 + void copy_to(nmethod* nm); 1.343 + 1.344 + void log_all_dependencies(); 1.345 + void log_dependency(DepType dept, int nargs, ciObject* args[]) { 1.346 + write_dependency_to(log(), dept, nargs, args); 1.347 + } 1.348 + void log_dependency(DepType dept, 1.349 + ciObject* x0, 1.350 + ciObject* x1 = NULL, 1.351 + ciObject* x2 = NULL) { 1.352 + if (log() == NULL) return; 1.353 + ciObject* args[max_arg_count]; 1.354 + args[0] = x0; 1.355 + args[1] = x1; 1.356 + args[2] = x2; 1.357 + assert(2 < max_arg_count, ""); 1.358 + log_dependency(dept, dep_args(dept), args); 1.359 + } 1.360 + 1.361 + static void write_dependency_to(CompileLog* log, 1.362 + DepType dept, 1.363 + int nargs, ciObject* args[], 1.364 + klassOop witness = NULL); 1.365 + static void write_dependency_to(CompileLog* log, 1.366 + DepType dept, 1.367 + int nargs, oop args[], 1.368 + klassOop witness = NULL); 1.369 + static void write_dependency_to(xmlStream* xtty, 1.370 + DepType dept, 1.371 + int nargs, oop args[], 1.372 + klassOop witness = NULL); 1.373 + static void print_dependency(DepType dept, 1.374 + int nargs, oop args[], 1.375 + klassOop witness = NULL); 1.376 + 1.377 + private: 1.378 + // helper for encoding common context types as zero: 1.379 + static ciKlass* ctxk_encoded_as_null(DepType dept, ciObject* x); 1.380 + 1.381 + static klassOop ctxk_encoded_as_null(DepType dept, oop x); 1.382 + 1.383 + public: 1.384 + // Use this to iterate over an nmethod's dependency set. 1.385 + // Works on new and old dependency sets. 1.386 + // Usage: 1.387 + // 1.388 + // ; 1.389 + // Dependencies::DepType dept; 1.390 + // for (Dependencies::DepStream deps(nm); deps.next(); ) { 1.391 + // ... 1.392 + // } 1.393 + // 1.394 + // The caller must be in the VM, since oops are not wrapped in handles. 1.395 + class DepStream { 1.396 + private: 1.397 + nmethod* _code; // null if in a compiler thread 1.398 + Dependencies* _deps; // null if not in a compiler thread 1.399 + CompressedReadStream _bytes; 1.400 +#ifdef ASSERT 1.401 + size_t _byte_limit; 1.402 +#endif 1.403 + 1.404 + // iteration variables: 1.405 + DepType _type; 1.406 + int _xi[max_arg_count+1]; 1.407 + 1.408 + void initial_asserts(size_t byte_limit) NOT_DEBUG({}); 1.409 + 1.410 + inline oop recorded_oop_at(int i); 1.411 + // => _code? _code->oop_at(i): *_deps->_oop_recorder->handle_at(i) 1.412 + 1.413 + klassOop check_dependency_impl(DepChange* changes); 1.414 + 1.415 + public: 1.416 + DepStream(Dependencies* deps) 1.417 + : _deps(deps), 1.418 + _code(NULL), 1.419 + _bytes(deps->content_bytes()) 1.420 + { 1.421 + initial_asserts(deps->size_in_bytes()); 1.422 + } 1.423 + DepStream(nmethod* code) 1.424 + : _deps(NULL), 1.425 + _code(code), 1.426 + _bytes(code->dependencies_begin()) 1.427 + { 1.428 + initial_asserts(code->dependencies_size()); 1.429 + } 1.430 + 1.431 + bool next(); 1.432 + 1.433 + DepType type() { return _type; } 1.434 + int argument_count() { return dep_args(type()); } 1.435 + int argument_index(int i) { assert(0 <= i && i < argument_count(), "oob"); 1.436 + return _xi[i]; } 1.437 + oop argument(int i); // => recorded_oop_at(argument_index(i)) 1.438 + klassOop context_type(); 1.439 + 1.440 + methodOop method_argument(int i) { 1.441 + oop x = argument(i); 1.442 + assert(x->is_method(), "type"); 1.443 + return (methodOop) x; 1.444 + } 1.445 + klassOop type_argument(int i) { 1.446 + oop x = argument(i); 1.447 + assert(x->is_klass(), "type"); 1.448 + return (klassOop) x; 1.449 + } 1.450 + 1.451 + // The point of the whole exercise: Is this dep is still OK? 1.452 + klassOop check_dependency() { 1.453 + return check_dependency_impl(NULL); 1.454 + } 1.455 + // A lighter version: Checks only around recent changes in a class 1.456 + // hierarchy. (See Universe::flush_dependents_on.) 1.457 + klassOop spot_check_dependency_at(DepChange& changes); 1.458 + 1.459 + // Log the current dependency to xtty or compilation log. 1.460 + void log_dependency(klassOop witness = NULL); 1.461 + 1.462 + // Print the current dependency to tty. 1.463 + void print_dependency(klassOop witness = NULL, bool verbose = false); 1.464 + }; 1.465 + friend class Dependencies::DepStream; 1.466 + 1.467 + static void print_statistics() PRODUCT_RETURN; 1.468 +}; 1.469 + 1.470 +// A class hierarchy change coming through the VM (under the Compile_lock). 1.471 +// The change is structured as a single new type with any number of supers 1.472 +// and implemented interface types. Other than the new type, any of the 1.473 +// super types can be context types for a relevant dependency, which the 1.474 +// new type could invalidate. 1.475 +class DepChange : public StackObj { 1.476 + private: 1.477 + enum ChangeType { 1.478 + NO_CHANGE = 0, // an uninvolved klass 1.479 + Change_new_type, // a newly loaded type 1.480 + Change_new_sub, // a super with a new subtype 1.481 + Change_new_impl, // an interface with a new implementation 1.482 + CHANGE_LIMIT, 1.483 + Start_Klass = CHANGE_LIMIT // internal indicator for ContextStream 1.484 + }; 1.485 + 1.486 + // each change set is rooted in exactly one new type (at present): 1.487 + KlassHandle _new_type; 1.488 + 1.489 + void initialize(); 1.490 + 1.491 + public: 1.492 + // notes the new type, marks it and all its super-types 1.493 + DepChange(KlassHandle new_type) 1.494 + : _new_type(new_type) 1.495 + { 1.496 + initialize(); 1.497 + } 1.498 + 1.499 + // cleans up the marks 1.500 + ~DepChange(); 1.501 + 1.502 + klassOop new_type() { return _new_type(); } 1.503 + 1.504 + // involves_context(k) is true if k is new_type or any of the super types 1.505 + bool involves_context(klassOop k); 1.506 + 1.507 + // Usage: 1.508 + // for (DepChange::ContextStream str(changes); str.next(); ) { 1.509 + // klassOop k = str.klass(); 1.510 + // switch (str.change_type()) { 1.511 + // ... 1.512 + // } 1.513 + // } 1.514 + class ContextStream : public StackObj { 1.515 + private: 1.516 + DepChange& _changes; 1.517 + friend class DepChange; 1.518 + 1.519 + // iteration variables: 1.520 + ChangeType _change_type; 1.521 + klassOop _klass; 1.522 + objArrayOop _ti_base; // i.e., transitive_interfaces 1.523 + int _ti_index; 1.524 + int _ti_limit; 1.525 + 1.526 + // start at the beginning: 1.527 + void start() { 1.528 + klassOop new_type = _changes.new_type(); 1.529 + _change_type = (new_type == NULL ? NO_CHANGE: Start_Klass); 1.530 + _klass = new_type; 1.531 + _ti_base = NULL; 1.532 + _ti_index = 0; 1.533 + _ti_limit = 0; 1.534 + } 1.535 + 1.536 + ContextStream(DepChange& changes) 1.537 + : _changes(changes) 1.538 + { start(); } 1.539 + 1.540 + public: 1.541 + ContextStream(DepChange& changes, No_Safepoint_Verifier& nsv) 1.542 + : _changes(changes) 1.543 + // the nsv argument makes it safe to hold oops like _klass 1.544 + { start(); } 1.545 + 1.546 + bool next(); 1.547 + 1.548 + klassOop klass() { return _klass; } 1.549 + }; 1.550 + friend class DepChange::ContextStream; 1.551 + 1.552 + void print(); 1.553 +};