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