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