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