annotate src/share/vm/code/dependencies.hpp @ 9618:4535697211eb

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