Path: blob/master/src/hotspot/share/code/dependencies.hpp
64440 views
/*1* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_CODE_DEPENDENCIES_HPP25#define SHARE_CODE_DEPENDENCIES_HPP2627#include "ci/ciCallSite.hpp"28#include "ci/ciKlass.hpp"29#include "ci/ciMethod.hpp"30#include "ci/ciMethodHandle.hpp"31#include "code/compressedStream.hpp"32#include "code/nmethod.hpp"33#include "memory/resourceArea.hpp"34#include "runtime/safepointVerifiers.hpp"35#include "utilities/growableArray.hpp"36#include "utilities/hashtable.hpp"3738//** Dependencies represent assertions (approximate invariants) within39// the runtime system, e.g. class hierarchy changes. An example is an40// assertion that a given method is not overridden; another example is41// that a type has only one concrete subtype. Compiled code which42// relies on such assertions must be discarded if they are overturned43// by changes in the runtime system. We can think of these assertions44// as approximate invariants, because we expect them to be overturned45// very infrequently. We are willing to perform expensive recovery46// operations when they are overturned. The benefit, of course, is47// performing optimistic optimizations (!) on the object code.48//49// Changes in the class hierarchy due to dynamic linking or50// class evolution can violate dependencies. There is enough51// indexing between classes and nmethods to make dependency52// checking reasonably efficient.5354class ciEnv;55class nmethod;56class OopRecorder;57class xmlStream;58class CompileLog;59class CompileTask;60class DepChange;61class KlassDepChange;62class NewKlassDepChange;63class KlassInitDepChange;64class CallSiteDepChange;65class NoSafepointVerifier;6667class Dependencies: public ResourceObj {68public:69// Note: In the comments on dependency types, most uses of the terms70// subtype and supertype are used in a "non-strict" or "inclusive"71// sense, and are starred to remind the reader of this fact.72// Strict uses of the terms use the word "proper".73//74// Specifically, every class is its own subtype* and supertype*.75// (This trick is easier than continually saying things like "Y is a76// subtype of X or X itself".)77//78// Sometimes we write X > Y to mean X is a proper supertype of Y.79// The notation X > {Y, Z} means X has proper subtypes Y, Z.80// The notation X.m > Y means that Y inherits m from X, while81// X.m > Y.m means Y overrides X.m. A star denotes abstractness,82// as *I > A, meaning (abstract) interface I is a super type of A,83// or A.*m > B.m, meaning B.m implements abstract method A.m.84//85// In this module, the terms "subtype" and "supertype" refer to86// Java-level reference type conversions, as detected by87// "instanceof" and performed by "checkcast" operations. The method88// Klass::is_subtype_of tests these relations. Note that "subtype"89// is richer than "subclass" (as tested by Klass::is_subclass_of),90// since it takes account of relations involving interface and array91// types.92//93// To avoid needless complexity, dependencies involving array types94// are not accepted. If you need to make an assertion about an95// array type, make the assertion about its corresponding element96// types. Any assertion that might change about an array type can97// be converted to an assertion about its element type.98//99// Most dependencies are evaluated over a "context type" CX, which100// stands for the set Subtypes(CX) of every Java type that is a subtype*101// of CX. When the system loads a new class or interface N, it is102// responsible for re-evaluating changed dependencies whose context103// type now includes N, that is, all super types of N.104//105enum DepType {106end_marker = 0,107108// An 'evol' dependency simply notes that the contents of the109// method were used. If it evolves (is replaced), the nmethod110// must be recompiled. No other dependencies are implied.111evol_method,112FIRST_TYPE = evol_method,113114// A context type CX is a leaf it if has no proper subtype.115leaf_type,116117// An abstract class CX has exactly one concrete subtype CC.118abstract_with_unique_concrete_subtype,119120// Given a method M1 and a context class CX, the set MM(CX, M1) of121// "concrete matching methods" in CX of M1 is the set of every122// concrete M2 for which it is possible to create an invokevirtual123// or invokeinterface call site that can reach either M1 or M2.124// That is, M1 and M2 share a name, signature, and vtable index.125// We wish to notice when the set MM(CX, M1) is just {M1}, or126// perhaps a set of two {M1,M2}, and issue dependencies on this.127128// The set MM(CX, M1) can be computed by starting with any matching129// concrete M2 that is inherited into CX, and then walking the130// subtypes* of CX looking for concrete definitions.131132// The parameters to this dependency are the method M1 and the133// context class CX. M1 must be either inherited in CX or defined134// in a subtype* of CX. It asserts that MM(CX, M1) is no greater135// than {M1}.136unique_concrete_method_2, // one unique concrete method under CX137138// In addition to the method M1 and the context class CX, the parameters139// to this dependency are the resolved class RC1 and the140// resolved method RM1. It asserts that MM(CX, M1, RC1, RM1)141// is no greater than {M1}. RC1 and RM1 are used to improve the precision142// of the analysis.143unique_concrete_method_4, // one unique concrete method under CX144145// This dependency asserts that interface CX has a unique implementor class.146unique_implementor, // one unique implementor under CX147148// This dependency asserts that no instances of class or it's149// subclasses require finalization registration.150no_finalizable_subclasses,151152// This dependency asserts when the CallSite.target value changed.153call_site_target_value,154155TYPE_LIMIT156};157enum {158LG2_TYPE_LIMIT = 4, // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))159160// handy categorizations of dependency types:161all_types = ((1 << TYPE_LIMIT) - 1) & ((~0u) << FIRST_TYPE),162163non_klass_types = (1 << call_site_target_value),164klass_types = all_types & ~non_klass_types,165166non_ctxk_types = (1 << evol_method) | (1 << call_site_target_value),167implicit_ctxk_types = 0,168explicit_ctxk_types = all_types & ~(non_ctxk_types | implicit_ctxk_types),169170max_arg_count = 4, // current maximum number of arguments (incl. ctxk)171172// A "context type" is a class or interface that173// provides context for evaluating a dependency.174// When present, it is one of the arguments (dep_context_arg).175//176// If a dependency does not have a context type, there is a177// default context, depending on the type of the dependency.178// This bit signals that a default context has been compressed away.179default_context_type_bit = (1<<LG2_TYPE_LIMIT)180};181182static const char* dep_name(DepType dept);183static int dep_args(DepType dept);184185static bool is_klass_type( DepType dept) { return dept_in_mask(dept, klass_types ); }186187static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }188static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }189190static int dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }191static int dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }192193static void check_valid_dependency_type(DepType dept);194195#if INCLUDE_JVMCI196// A Metadata* or object value recorded in an OopRecorder197class DepValue {198private:199// Unique identifier of the value within the associated OopRecorder that200// encodes both the category of the value (0: invalid, positive: metadata, negative: object)201// and the index within a category specific array (metadata: index + 1, object: -(index + 1))202int _id;203204public:205DepValue() : _id(0) {}206DepValue(OopRecorder* rec, Metadata* metadata, DepValue* candidate = NULL) {207assert(candidate == NULL || candidate->is_metadata(), "oops");208if (candidate != NULL && candidate->as_metadata(rec) == metadata) {209_id = candidate->_id;210} else {211_id = rec->find_index(metadata) + 1;212}213}214DepValue(OopRecorder* rec, jobject obj, DepValue* candidate = NULL) {215assert(candidate == NULL || candidate->is_object(), "oops");216if (candidate != NULL && candidate->as_object(rec) == obj) {217_id = candidate->_id;218} else {219_id = -(rec->find_index(obj) + 1);220}221}222223// Used to sort values in ascending order of index() with metadata values preceding object values224int sort_key() const { return -_id; }225226bool operator == (const DepValue& other) const { return other._id == _id; }227228bool is_valid() const { return _id != 0; }229int index() const { assert(is_valid(), "oops"); return _id < 0 ? -(_id + 1) : _id - 1; }230bool is_metadata() const { assert(is_valid(), "oops"); return _id > 0; }231bool is_object() const { assert(is_valid(), "oops"); return _id < 0; }232233Metadata* as_metadata(OopRecorder* rec) const { assert(is_metadata(), "oops"); return rec->metadata_at(index()); }234Klass* as_klass(OopRecorder* rec) const {235Metadata* m = as_metadata(rec);236assert(m != NULL, "as_metadata returned NULL");237assert(m->is_klass(), "oops");238return (Klass*) m;239}240Method* as_method(OopRecorder* rec) const {241Metadata* m = as_metadata(rec);242assert(m != NULL, "as_metadata returned NULL");243assert(m->is_method(), "oops");244return (Method*) m;245}246jobject as_object(OopRecorder* rec) const { assert(is_object(), "oops"); return rec->oop_at(index()); }247};248#endif // INCLUDE_JVMCI249250private:251// State for writing a new set of dependencies:252GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept))253GrowableArray<ciBaseObject*>* _deps[TYPE_LIMIT];254#if INCLUDE_JVMCI255bool _using_dep_values;256GrowableArray<DepValue>* _dep_values[TYPE_LIMIT];257#endif258259static const char* _dep_name[TYPE_LIMIT];260static int _dep_args[TYPE_LIMIT];261262static bool dept_in_mask(DepType dept, int mask) {263return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;264}265266bool note_dep_seen(int dept, ciBaseObject* x) {267assert(dept < BitsPerInt, "oob");268int x_id = x->ident();269assert(_dep_seen != NULL, "deps must be writable");270int seen = _dep_seen->at_grow(x_id, 0);271_dep_seen->at_put(x_id, seen | (1<<dept));272// return true if we've already seen dept/x273return (seen & (1<<dept)) != 0;274}275276#if INCLUDE_JVMCI277bool note_dep_seen(int dept, DepValue x) {278assert(dept < BitsPerInt, "oops");279// place metadata deps at even indexes, object deps at odd indexes280int x_id = x.is_metadata() ? x.index() * 2 : (x.index() * 2) + 1;281assert(_dep_seen != NULL, "deps must be writable");282int seen = _dep_seen->at_grow(x_id, 0);283_dep_seen->at_put(x_id, seen | (1<<dept));284// return true if we've already seen dept/x285return (seen & (1<<dept)) != 0;286}287#endif288289bool maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,290int ctxk_i, ciKlass* ctxk);291#if INCLUDE_JVMCI292bool maybe_merge_ctxk(GrowableArray<DepValue>* deps,293int ctxk_i, DepValue ctxk);294#endif295296void sort_all_deps();297size_t estimate_size_in_bytes();298299// Initialize _deps, etc.300void initialize(ciEnv* env);301302// State for making a new set of dependencies:303OopRecorder* _oop_recorder;304305// Logging support306CompileLog* _log;307308address _content_bytes; // everything but the oop references, encoded309size_t _size_in_bytes;310311public:312// Make a new empty dependencies set.313Dependencies(ciEnv* env) {314initialize(env);315}316#if INCLUDE_JVMCI317Dependencies(Arena* arena, OopRecorder* oop_recorder, CompileLog* log);318#endif319320private:321// Check for a valid context type.322// Enforce the restriction against array types.323static void check_ctxk(ciKlass* ctxk) {324assert(ctxk->is_instance_klass(), "java types only");325}326static void check_ctxk_concrete(ciKlass* ctxk) {327assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");328}329static void check_ctxk_abstract(ciKlass* ctxk) {330check_ctxk(ctxk);331assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");332}333static void check_unique_method(ciKlass* ctxk, ciMethod* m) {334assert(!m->can_be_statically_bound(ctxk->as_instance_klass()) || ctxk->is_interface(), "redundant");335}336static void check_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk) {337assert(ctxk->implementor() == uniqk, "not a unique implementor");338}339340void assert_common_1(DepType dept, ciBaseObject* x);341void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);342void assert_common_4(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2, ciBaseObject* x3);343344public:345// Adding assertions to a new dependency set at compile time:346void assert_evol_method(ciMethod* m);347void assert_leaf_type(ciKlass* ctxk);348void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);349void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);350void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm, ciKlass* resolved_klass, ciMethod* resolved_method);351void assert_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk);352void assert_has_no_finalizable_subclasses(ciKlass* ctxk);353void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);354#if INCLUDE_JVMCI355private:356static void check_ctxk(Klass* ctxk) {357assert(ctxk->is_instance_klass(), "java types only");358}359static void check_ctxk_abstract(Klass* ctxk) {360check_ctxk(ctxk);361assert(ctxk->is_abstract(), "must be abstract");362}363static void check_unique_method(Klass* ctxk, Method* m) {364assert(!m->can_be_statically_bound(InstanceKlass::cast(ctxk)), "redundant");365}366367void assert_common_1(DepType dept, DepValue x);368void assert_common_2(DepType dept, DepValue x0, DepValue x1);369370public:371void assert_evol_method(Method* m);372void assert_has_no_finalizable_subclasses(Klass* ctxk);373void assert_leaf_type(Klass* ctxk);374void assert_unique_implementor(InstanceKlass* ctxk, InstanceKlass* uniqk);375void assert_unique_concrete_method(Klass* ctxk, Method* uniqm);376void assert_abstract_with_unique_concrete_subtype(Klass* ctxk, Klass* conck);377void assert_call_site_target_value(oop callSite, oop methodHandle);378#endif // INCLUDE_JVMCI379380// Define whether a given method or type is concrete.381// These methods define the term "concrete" as used in this module.382// For this module, an "abstract" class is one which is non-concrete.383//384// Future optimizations may allow some classes to remain385// non-concrete until their first instantiation, and allow some386// methods to remain non-concrete until their first invocation.387// In that case, there would be a middle ground between concrete388// and abstract (as defined by the Java language and VM).389static bool is_concrete_klass(Klass* k); // k is instantiable390static bool is_concrete_method(Method* m, Klass* k); // m is invocable391static Klass* find_finalizable_subclass(InstanceKlass* ik);392393static bool is_concrete_root_method(Method* uniqm, InstanceKlass* ctxk);394static Klass* find_witness_AME(InstanceKlass* ctxk, Method* m, KlassDepChange* changes = NULL);395396// These versions of the concreteness queries work through the CI.397// The CI versions are allowed to skew sometimes from the VM398// (oop-based) versions. The cost of such a difference is a399// (safely) aborted compilation, or a deoptimization, or a missed400// optimization opportunity.401//402// In order to prevent spurious assertions, query results must403// remain stable within any single ciEnv instance. (I.e., they must404// not go back into the VM to get their value; they must cache the405// bit in the CI, either eagerly or lazily.)406static bool is_concrete_klass(ciInstanceKlass* k); // k appears instantiable407static bool has_finalizable_subclass(ciInstanceKlass* k);408409// As a general rule, it is OK to compile under the assumption that410// a given type or method is concrete, even if it at some future411// point becomes abstract. So dependency checking is one-sided, in412// that it permits supposedly concrete classes or methods to turn up413// as really abstract. (This shouldn't happen, except during class414// evolution, but that's the logic of the checking.) However, if a415// supposedly abstract class or method suddenly becomes concrete, a416// dependency on it must fail.417418// Checking old assertions at run-time (in the VM only):419static Klass* check_evol_method(Method* m);420static Klass* check_leaf_type(InstanceKlass* ctxk);421static Klass* check_abstract_with_unique_concrete_subtype(InstanceKlass* ctxk, Klass* conck, NewKlassDepChange* changes = NULL);422static Klass* check_unique_implementor(InstanceKlass* ctxk, Klass* uniqk, NewKlassDepChange* changes = NULL);423static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, NewKlassDepChange* changes = NULL);424static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, Klass* resolved_klass, Method* resolved_method, KlassDepChange* changes = NULL);425static Klass* check_has_no_finalizable_subclasses(InstanceKlass* ctxk, NewKlassDepChange* changes = NULL);426static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = NULL);427// A returned Klass* is NULL if the dependency assertion is still428// valid. A non-NULL Klass* is a 'witness' to the assertion429// failure, a point in the class hierarchy where the assertion has430// been proven false. For example, if check_leaf_type returns431// non-NULL, the value is a subtype of the supposed leaf type. This432// witness value may be useful for logging the dependency failure.433// Note that, when a dependency fails, there may be several possible434// witnesses to the failure. The value returned from the check_foo435// method is chosen arbitrarily.436437// The 'changes' value, if non-null, requests a limited spot-check438// near the indicated recent changes in the class hierarchy.439// It is used by DepStream::spot_check_dependency_at.440441// Detecting possible new assertions:442static Klass* find_unique_concrete_subtype(InstanceKlass* ctxk);443static Method* find_unique_concrete_method(InstanceKlass* ctxk, Method* m,444Klass** participant = NULL); // out parameter445static Method* find_unique_concrete_method(InstanceKlass* ctxk, Method* m, Klass* resolved_klass, Method* resolved_method);446447#ifdef ASSERT448static bool verify_method_context(InstanceKlass* ctxk, Method* m);449#endif // ASSERT450451// Create the encoding which will be stored in an nmethod.452void encode_content_bytes();453454address content_bytes() {455assert(_content_bytes != NULL, "encode it first");456return _content_bytes;457}458size_t size_in_bytes() {459assert(_content_bytes != NULL, "encode it first");460return _size_in_bytes;461}462463OopRecorder* oop_recorder() { return _oop_recorder; }464CompileLog* log() { return _log; }465466void copy_to(nmethod* nm);467468DepType validate_dependencies(CompileTask* task, char** failure_detail = NULL);469470void log_all_dependencies();471472void log_dependency(DepType dept, GrowableArray<ciBaseObject*>* args) {473ResourceMark rm;474int argslen = args->length();475write_dependency_to(log(), dept, args);476guarantee(argslen == args->length(),477"args array cannot grow inside nested ResoureMark scope");478}479480void log_dependency(DepType dept,481ciBaseObject* x0,482ciBaseObject* x1 = NULL,483ciBaseObject* x2 = NULL,484ciBaseObject* x3 = NULL) {485if (log() == NULL) {486return;487}488ResourceMark rm;489GrowableArray<ciBaseObject*>* ciargs =490new GrowableArray<ciBaseObject*>(dep_args(dept));491assert (x0 != NULL, "no log x0");492ciargs->push(x0);493494if (x1 != NULL) {495ciargs->push(x1);496}497if (x2 != NULL) {498ciargs->push(x2);499}500if (x3 != NULL) {501ciargs->push(x3);502}503assert(ciargs->length() == dep_args(dept), "");504log_dependency(dept, ciargs);505}506507class DepArgument : public ResourceObj {508private:509bool _is_oop;510bool _valid;511void* _value;512public:513DepArgument() : _is_oop(false), _valid(false), _value(NULL) {}514DepArgument(oop v): _is_oop(true), _valid(true), _value(v) {}515DepArgument(Metadata* v): _is_oop(false), _valid(true), _value(v) {}516517bool is_null() const { return _value == NULL; }518bool is_oop() const { return _is_oop; }519bool is_metadata() const { return !_is_oop; }520bool is_klass() const { return is_metadata() && metadata_value()->is_klass(); }521bool is_method() const { return is_metadata() && metadata_value()->is_method(); }522523oop oop_value() const { assert(_is_oop && _valid, "must be"); return cast_to_oop(_value); }524Metadata* metadata_value() const { assert(!_is_oop && _valid, "must be"); return (Metadata*) _value; }525};526527static void print_dependency(DepType dept,528GrowableArray<DepArgument>* args,529Klass* witness = NULL, outputStream* st = tty);530531private:532// helper for encoding common context types as zero:533static ciKlass* ctxk_encoded_as_null(DepType dept, ciBaseObject* x);534535static Klass* ctxk_encoded_as_null(DepType dept, Metadata* x);536537static void write_dependency_to(CompileLog* log,538DepType dept,539GrowableArray<ciBaseObject*>* args,540Klass* witness = NULL);541static void write_dependency_to(CompileLog* log,542DepType dept,543GrowableArray<DepArgument>* args,544Klass* witness = NULL);545static void write_dependency_to(xmlStream* xtty,546DepType dept,547GrowableArray<DepArgument>* args,548Klass* witness = NULL);549public:550// Use this to iterate over an nmethod's dependency set.551// Works on new and old dependency sets.552// Usage:553//554// ;555// Dependencies::DepType dept;556// for (Dependencies::DepStream deps(nm); deps.next(); ) {557// ...558// }559//560// The caller must be in the VM, since oops are not wrapped in handles.561class DepStream {562private:563nmethod* _code; // null if in a compiler thread564Dependencies* _deps; // null if not in a compiler thread565CompressedReadStream _bytes;566#ifdef ASSERT567size_t _byte_limit;568#endif569570// iteration variables:571DepType _type;572int _xi[max_arg_count+1];573574void initial_asserts(size_t byte_limit) NOT_DEBUG({});575576inline Metadata* recorded_metadata_at(int i);577inline oop recorded_oop_at(int i);578579Klass* check_klass_dependency(KlassDepChange* changes);580Klass* check_new_klass_dependency(NewKlassDepChange* changes);581Klass* check_klass_init_dependency(KlassInitDepChange* changes);582Klass* check_call_site_dependency(CallSiteDepChange* changes);583584void trace_and_log_witness(Klass* witness);585586public:587DepStream(Dependencies* deps)588: _code(NULL),589_deps(deps),590_bytes(deps->content_bytes())591{592initial_asserts(deps->size_in_bytes());593}594DepStream(nmethod* code)595: _code(code),596_deps(NULL),597_bytes(code->dependencies_begin())598{599initial_asserts(code->dependencies_size());600}601602bool next();603604DepType type() { return _type; }605bool is_oop_argument(int i) { return type() == call_site_target_value; }606uintptr_t get_identifier(int i);607608int argument_count() { return dep_args(type()); }609int argument_index(int i) { assert(0 <= i && i < argument_count(), "oob");610return _xi[i]; }611Metadata* argument(int i); // => recorded_oop_at(argument_index(i))612oop argument_oop(int i); // => recorded_oop_at(argument_index(i))613InstanceKlass* context_type();614615bool is_klass_type() { return Dependencies::is_klass_type(type()); }616617Method* method_argument(int i) {618Metadata* x = argument(i);619assert(x->is_method(), "type");620return (Method*) x;621}622Klass* type_argument(int i) {623Metadata* x = argument(i);624assert(x->is_klass(), "type");625return (Klass*) x;626}627628// The point of the whole exercise: Is this dep still OK?629Klass* check_dependency() {630Klass* result = check_klass_dependency(NULL);631if (result != NULL) return result;632return check_call_site_dependency(NULL);633}634635// A lighter version: Checks only around recent changes in a class636// hierarchy. (See Universe::flush_dependents_on.)637Klass* spot_check_dependency_at(DepChange& changes);638639// Log the current dependency to xtty or compilation log.640void log_dependency(Klass* witness = NULL);641642// Print the current dependency to tty.643void print_dependency(Klass* witness = NULL, bool verbose = false, outputStream* st = tty);644};645friend class Dependencies::DepStream;646647static void print_statistics();648};649650651class DependencySignature : public ResourceObj {652private:653int _args_count;654uintptr_t _argument_hash[Dependencies::max_arg_count];655Dependencies::DepType _type;656657public:658DependencySignature(Dependencies::DepStream& dep) {659_args_count = dep.argument_count();660_type = dep.type();661for (int i = 0; i < _args_count; i++) {662_argument_hash[i] = dep.get_identifier(i);663}664}665666static bool equals(DependencySignature const& s1, DependencySignature const& s2);667static unsigned hash (DependencySignature const& s1) { return s1.arg(0) >> 2; }668669int args_count() const { return _args_count; }670uintptr_t arg(int idx) const { return _argument_hash[idx]; }671Dependencies::DepType type() const { return _type; }672673};674675676// Every particular DepChange is a sub-class of this class.677class DepChange : public StackObj {678public:679// What kind of DepChange is this?680virtual bool is_klass_change() const { return false; }681virtual bool is_new_klass_change() const { return false; }682virtual bool is_klass_init_change() const { return false; }683virtual bool is_call_site_change() const { return false; }684685virtual void mark_for_deoptimization(nmethod* nm) = 0;686687// Subclass casting with assertions.688KlassDepChange* as_klass_change() {689assert(is_klass_change(), "bad cast");690return (KlassDepChange*) this;691}692NewKlassDepChange* as_new_klass_change() {693assert(is_new_klass_change(), "bad cast");694return (NewKlassDepChange*) this;695}696KlassInitDepChange* as_klass_init_change() {697assert(is_klass_init_change(), "bad cast");698return (KlassInitDepChange*) this;699}700CallSiteDepChange* as_call_site_change() {701assert(is_call_site_change(), "bad cast");702return (CallSiteDepChange*) this;703}704705void print();706707public:708enum ChangeType {709NO_CHANGE = 0, // an uninvolved klass710Change_new_type, // a newly loaded type711Change_new_sub, // a super with a new subtype712Change_new_impl, // an interface with a new implementation713CHANGE_LIMIT,714Start_Klass = CHANGE_LIMIT // internal indicator for ContextStream715};716717// Usage:718// for (DepChange::ContextStream str(changes); str.next(); ) {719// Klass* k = str.klass();720// switch (str.change_type()) {721// ...722// }723// }724class ContextStream : public StackObj {725private:726DepChange& _changes;727friend class DepChange;728729// iteration variables:730ChangeType _change_type;731Klass* _klass;732Array<InstanceKlass*>* _ti_base; // i.e., transitive_interfaces733int _ti_index;734int _ti_limit;735736// start at the beginning:737void start();738739public:740ContextStream(DepChange& changes)741: _changes(changes)742{ start(); }743744ContextStream(DepChange& changes, NoSafepointVerifier& nsv)745: _changes(changes)746// the nsv argument makes it safe to hold oops like _klass747{ start(); }748749bool next();750751ChangeType change_type() { return _change_type; }752Klass* klass() { return _klass; }753};754friend class DepChange::ContextStream;755};756757758// A class hierarchy change coming through the VM (under the Compile_lock).759// The change is structured as a single type with any number of supers760// and implemented interface types. Other than the type, any of the761// super types can be context types for a relevant dependency, which the762// type could invalidate.763class KlassDepChange : public DepChange {764private:765// each change set is rooted in exactly one type (at present):766InstanceKlass* _type;767768void initialize();769770protected:771// notes the type, marks it and all its super-types772KlassDepChange(InstanceKlass* type) : _type(type) {773initialize();774}775776// cleans up the marks777~KlassDepChange();778779public:780// What kind of DepChange is this?781virtual bool is_klass_change() const { return true; }782783virtual void mark_for_deoptimization(nmethod* nm) {784nm->mark_for_deoptimization(/*inc_recompile_counts=*/true);785}786787InstanceKlass* type() { return _type; }788789// involves_context(k) is true if k == _type or any of its super types790bool involves_context(Klass* k);791};792793// A class hierarchy change: new type is loaded.794class NewKlassDepChange : public KlassDepChange {795public:796NewKlassDepChange(InstanceKlass* new_type) : KlassDepChange(new_type) {}797798// What kind of DepChange is this?799virtual bool is_new_klass_change() const { return true; }800801InstanceKlass* new_type() { return type(); }802};803804// Change in initialization state of a loaded class.805class KlassInitDepChange : public KlassDepChange {806public:807KlassInitDepChange(InstanceKlass* type) : KlassDepChange(type) {}808809// What kind of DepChange is this?810virtual bool is_klass_init_change() const { return true; }811};812813// A CallSite has changed its target.814class CallSiteDepChange : public DepChange {815private:816Handle _call_site;817Handle _method_handle;818819public:820CallSiteDepChange(Handle call_site, Handle method_handle);821822// What kind of DepChange is this?823virtual bool is_call_site_change() const { return true; }824825virtual void mark_for_deoptimization(nmethod* nm) {826nm->mark_for_deoptimization(/*inc_recompile_counts=*/false);827}828829oop call_site() const { return _call_site(); }830oop method_handle() const { return _method_handle(); }831};832833#endif // SHARE_CODE_DEPENDENCIES_HPP834835836