dependencies.cpp 58.3 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32
#include "precompiled.hpp"
#include "ci/ciArrayKlass.hpp"
#include "ci/ciEnv.hpp"
#include "ci/ciKlass.hpp"
#include "ci/ciMethod.hpp"
#include "code/dependencies.hpp"
#include "compiler/compileLog.hpp"
#include "oops/oop.inline.hpp"
33
#include "runtime/handles.hpp"
34
#include "runtime/handles.inline.hpp"
35
#include "runtime/thread.inline.hpp"
36
#include "utilities/copy.hpp"
D
duke 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55


#ifdef ASSERT
static bool must_be_in_vm() {
  Thread* thread = Thread::current();
  if (thread->is_Java_thread())
    return ((JavaThread*)thread)->thread_state() == _thread_in_vm;
  else
    return true;  //something like this: thread->is_VM_thread();
}
#endif //ASSERT

void Dependencies::initialize(ciEnv* env) {
  Arena* arena = env->arena();
  _oop_recorder = env->oop_recorder();
  _log = env->log();
  _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0);
  DEBUG_ONLY(_deps[end_marker] = NULL);
  for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) {
56
    _deps[i] = new(arena) GrowableArray<ciBaseObject*>(arena, 10, 0, 0);
D
duke 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  }
  _content_bytes = NULL;
  _size_in_bytes = (size_t)-1;

  assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT), "sanity");
}

void Dependencies::assert_evol_method(ciMethod* m) {
  assert_common_1(evol_method, m);
}

void Dependencies::assert_leaf_type(ciKlass* ctxk) {
  if (ctxk->is_array_klass()) {
    // As a special case, support this assertion on an array type,
    // which reduces to an assertion on its element type.
    // Note that this cannot be done with assertions that
    // relate to concreteness or abstractness.
    ciType* elemt = ctxk->as_array_klass()->base_element_type();
    if (!elemt->is_instance_klass())  return;   // Ex:  int[][]
    ctxk = elemt->as_instance_klass();
    //if (ctxk->is_final())  return;            // Ex:  String[][]
  }
  check_ctxk(ctxk);
  assert_common_1(leaf_type, ctxk);
}

void Dependencies::assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck) {
  check_ctxk_abstract(ctxk);
  assert_common_2(abstract_with_unique_concrete_subtype, ctxk, conck);
}

void Dependencies::assert_abstract_with_no_concrete_subtype(ciKlass* ctxk) {
  check_ctxk_abstract(ctxk);
  assert_common_1(abstract_with_no_concrete_subtype, ctxk);
}

void Dependencies::assert_concrete_with_no_concrete_subtype(ciKlass* ctxk) {
  check_ctxk_concrete(ctxk);
  assert_common_1(concrete_with_no_concrete_subtype, ctxk);
}

void Dependencies::assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm) {
  check_ctxk(ctxk);
  assert_common_2(unique_concrete_method, ctxk, uniqm);
}

void Dependencies::assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2) {
  check_ctxk(ctxk);
  assert_common_3(abstract_with_exclusive_concrete_subtypes_2, ctxk, k1, k2);
}

void Dependencies::assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2) {
  check_ctxk(ctxk);
  assert_common_3(exclusive_concrete_methods_2, ctxk, m1, m2);
}

void Dependencies::assert_has_no_finalizable_subclasses(ciKlass* ctxk) {
  check_ctxk(ctxk);
  assert_common_1(no_finalizable_subclasses, ctxk);
}

118 119 120
void Dependencies::assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) {
  check_ctxk(call_site->klass());
  assert_common_2(call_site_target_value, call_site, method_handle);
121 122
}

D
duke 已提交
123 124 125
// Helper function.  If we are adding a new dep. under ctxk2,
// try to find an old dep. under a broader* ctxk1.  If there is
//
126
bool Dependencies::maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,
D
duke 已提交
127
                                    int ctxk_i, ciKlass* ctxk2) {
128
  ciKlass* ctxk1 = deps->at(ctxk_i)->as_metadata()->as_klass();
D
duke 已提交
129 130 131 132 133 134 135 136 137 138 139
  if (ctxk2->is_subtype_of(ctxk1)) {
    return true;  // success, and no need to change
  } else if (ctxk1->is_subtype_of(ctxk2)) {
    // new context class fully subsumes previous one
    deps->at_put(ctxk_i, ctxk2);
    return true;
  } else {
    return false;
  }
}

140
void Dependencies::assert_common_1(DepType dept, ciBaseObject* x) {
D
duke 已提交
141 142
  assert(dep_args(dept) == 1, "sanity");
  log_dependency(dept, x);
143
  GrowableArray<ciBaseObject*>* deps = _deps[dept];
D
duke 已提交
144 145 146 147 148 149 150 151 152

  // see if the same (or a similar) dep is already recorded
  if (note_dep_seen(dept, x)) {
    assert(deps->find(x) >= 0, "sanity");
  } else {
    deps->append(x);
  }
}

153
void Dependencies::assert_common_2(DepType dept,
154
                                   ciBaseObject* x0, ciBaseObject* x1) {
D
duke 已提交
155
  assert(dep_args(dept) == 2, "sanity");
156
  log_dependency(dept, x0, x1);
157
  GrowableArray<ciBaseObject*>* deps = _deps[dept];
D
duke 已提交
158 159

  // see if the same (or a similar) dep is already recorded
160 161 162 163 164 165 166
  bool has_ctxk = has_explicit_context_arg(dept);
  if (has_ctxk) {
    assert(dep_context_arg(dept) == 0, "sanity");
    if (note_dep_seen(dept, x1)) {
      // look in this bucket for redundant assertions
      const int stride = 2;
      for (int i = deps->length(); (i -= stride) >= 0; ) {
167
        ciBaseObject* y1 = deps->at(i+1);
168
        if (x1 == y1) {  // same subject; check the context
169
          if (maybe_merge_ctxk(deps, i+0, x0->as_metadata()->as_klass())) {
170 171 172 173 174 175 176 177 178 179 180
            return;
          }
        }
      }
    }
  } else {
    assert(dep_implicit_context_arg(dept) == 0, "sanity");
    if (note_dep_seen(dept, x0) && note_dep_seen(dept, x1)) {
      // look in this bucket for redundant assertions
      const int stride = 2;
      for (int i = deps->length(); (i -= stride) >= 0; ) {
181 182
        ciBaseObject* y0 = deps->at(i+0);
        ciBaseObject* y1 = deps->at(i+1);
183
        if (x0 == y0 && x1 == y1) {
D
duke 已提交
184 185 186 187 188 189 190
          return;
        }
      }
    }
  }

  // append the assertion in the correct bucket:
191 192
  deps->append(x0);
  deps->append(x1);
D
duke 已提交
193 194
}

195
void Dependencies::assert_common_3(DepType dept,
196
                                   ciKlass* ctxk, ciBaseObject* x, ciBaseObject* x2) {
D
duke 已提交
197 198 199
  assert(dep_context_arg(dept) == 0, "sanity");
  assert(dep_args(dept) == 3, "sanity");
  log_dependency(dept, ctxk, x, x2);
200
  GrowableArray<ciBaseObject*>* deps = _deps[dept];
D
duke 已提交
201 202 203 204 205

  // try to normalize an unordered pair:
  bool swap = false;
  switch (dept) {
  case abstract_with_exclusive_concrete_subtypes_2:
206
    swap = (x->ident() > x2->ident() && x->as_metadata()->as_klass() != ctxk);
D
duke 已提交
207 208
    break;
  case exclusive_concrete_methods_2:
209
    swap = (x->ident() > x2->ident() && x->as_metadata()->as_method()->holder() != ctxk);
D
duke 已提交
210 211
    break;
  }
212
  if (swap) { ciBaseObject* t = x; x = x2; x2 = t; }
D
duke 已提交
213 214 215 216 217 218

  // see if the same (or a similar) dep is already recorded
  if (note_dep_seen(dept, x) && note_dep_seen(dept, x2)) {
    // look in this bucket for redundant assertions
    const int stride = 3;
    for (int i = deps->length(); (i -= stride) >= 0; ) {
219 220
      ciBaseObject* y  = deps->at(i+1);
      ciBaseObject* y2 = deps->at(i+2);
D
duke 已提交
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
      if (x == y && x2 == y2) {  // same subjects; check the context
        if (maybe_merge_ctxk(deps, i+0, ctxk)) {
          return;
        }
      }
    }
  }
  // append the assertion in the correct bucket:
  deps->append(ctxk);
  deps->append(x);
  deps->append(x2);
}

/// Support for encoding dependencies into an nmethod:

void Dependencies::copy_to(nmethod* nm) {
  address beg = nm->dependencies_begin();
  address end = nm->dependencies_end();
  guarantee(end - beg >= (ptrdiff_t) size_in_bytes(), "bad sizing");
  Copy::disjoint_words((HeapWord*) content_bytes(),
                       (HeapWord*) beg,
                       size_in_bytes() / sizeof(HeapWord));
  assert(size_in_bytes() % sizeof(HeapWord) == 0, "copy by words");
}

246
static int sort_dep(ciBaseObject** p1, ciBaseObject** p2, int narg) {
D
duke 已提交
247 248 249 250 251 252
  for (int i = 0; i < narg; i++) {
    int diff = p1[i]->ident() - p2[i]->ident();
    if (diff != 0)  return diff;
  }
  return 0;
}
253
static int sort_dep_arg_1(ciBaseObject** p1, ciBaseObject** p2)
D
duke 已提交
254
{ return sort_dep(p1, p2, 1); }
255
static int sort_dep_arg_2(ciBaseObject** p1, ciBaseObject** p2)
D
duke 已提交
256
{ return sort_dep(p1, p2, 2); }
257
static int sort_dep_arg_3(ciBaseObject** p1, ciBaseObject** p2)
D
duke 已提交
258 259 260 261 262
{ return sort_dep(p1, p2, 3); }

void Dependencies::sort_all_deps() {
  for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
    DepType dept = (DepType)deptv;
263
    GrowableArray<ciBaseObject*>* deps = _deps[dept];
D
duke 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277
    if (deps->length() <= 1)  continue;
    switch (dep_args(dept)) {
    case 1: deps->sort(sort_dep_arg_1, 1); break;
    case 2: deps->sort(sort_dep_arg_2, 2); break;
    case 3: deps->sort(sort_dep_arg_3, 3); break;
    default: ShouldNotReachHere();
    }
  }
}

size_t Dependencies::estimate_size_in_bytes() {
  size_t est_size = 100;
  for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
    DepType dept = (DepType)deptv;
278
    GrowableArray<ciBaseObject*>* deps = _deps[dept];
D
duke 已提交
279 280 281 282 283
    est_size += deps->length()*2;  // tags and argument(s)
  }
  return est_size;
}

284
ciKlass* Dependencies::ctxk_encoded_as_null(DepType dept, ciBaseObject* x) {
D
duke 已提交
285 286
  switch (dept) {
  case abstract_with_exclusive_concrete_subtypes_2:
287
    return x->as_metadata()->as_klass();
D
duke 已提交
288 289
  case unique_concrete_method:
  case exclusive_concrete_methods_2:
290
    return x->as_metadata()->as_method()->holder();
D
duke 已提交
291 292 293 294
  }
  return NULL;  // let NULL be NULL
}

295
Klass* Dependencies::ctxk_encoded_as_null(DepType dept, Metadata* x) {
D
duke 已提交
296 297 298 299
  assert(must_be_in_vm(), "raw oops here");
  switch (dept) {
  case abstract_with_exclusive_concrete_subtypes_2:
    assert(x->is_klass(), "sanity");
300
    return (Klass*) x;
D
duke 已提交
301 302 303
  case unique_concrete_method:
  case exclusive_concrete_methods_2:
    assert(x->is_method(), "sanity");
304
    return ((Method*)x)->method_holder();
D
duke 已提交
305 306 307 308 309 310 311 312 313 314 315 316
  }
  return NULL;  // let NULL be NULL
}

void Dependencies::encode_content_bytes() {
  sort_all_deps();

  // cast is safe, no deps can overflow INT_MAX
  CompressedWriteStream bytes((int)estimate_size_in_bytes());

  for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
    DepType dept = (DepType)deptv;
317
    GrowableArray<ciBaseObject*>* deps = _deps[dept];
D
duke 已提交
318 319 320 321 322 323 324 325
    if (deps->length() == 0)  continue;
    int stride = dep_args(dept);
    int ctxkj  = dep_context_arg(dept);  // -1 if no context arg
    assert(stride > 0, "sanity");
    for (int i = 0; i < deps->length(); i += stride) {
      jbyte code_byte = (jbyte)dept;
      int skipj = -1;
      if (ctxkj >= 0 && ctxkj+1 < stride) {
326 327
        ciKlass*  ctxk = deps->at(i+ctxkj+0)->as_metadata()->as_klass();
        ciBaseObject* x     = deps->at(i+ctxkj+1);  // following argument
D
duke 已提交
328 329 330 331 332 333 334 335
        if (ctxk == ctxk_encoded_as_null(dept, x)) {
          skipj = ctxkj;  // we win:  maybe one less oop to keep track of
          code_byte |= default_context_type_bit;
        }
      }
      bytes.write_byte(code_byte);
      for (int j = 0; j < stride; j++) {
        if (j == skipj)  continue;
336
        ciBaseObject* v = deps->at(i+j);
337
        int idx;
338
        if (v->is_object()) {
339
          idx = _oop_recorder->find_index(v->as_object()->constant_encoding());
340 341
        } else {
          ciMetadata* meta = v->as_metadata();
342
          idx = _oop_recorder->find_index(meta->constant_encoding());
343
        }
344
        bytes.write_int(idx);
D
duke 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
      }
    }
  }

  // write a sentinel byte to mark the end
  bytes.write_byte(end_marker);

  // round it out to a word boundary
  while (bytes.position() % sizeof(HeapWord) != 0) {
    bytes.write_byte(end_marker);
  }

  // check whether the dept byte encoding really works
  assert((jbyte)default_context_type_bit != 0, "byte overflow");

  _content_bytes = bytes.buffer();
  _size_in_bytes = bytes.position();
}


const char* Dependencies::_dep_name[TYPE_LIMIT] = {
  "end_marker",
  "evol_method",
  "leaf_type",
  "abstract_with_unique_concrete_subtype",
  "abstract_with_no_concrete_subtype",
  "concrete_with_no_concrete_subtype",
  "unique_concrete_method",
  "abstract_with_exclusive_concrete_subtypes_2",
  "exclusive_concrete_methods_2",
375 376
  "no_finalizable_subclasses",
  "call_site_target_value"
D
duke 已提交
377 378 379 380 381 382 383 384 385 386 387 388
};

int Dependencies::_dep_args[TYPE_LIMIT] = {
  -1,// end_marker
  1, // evol_method m
  1, // leaf_type ctxk
  2, // abstract_with_unique_concrete_subtype ctxk, k
  1, // abstract_with_no_concrete_subtype ctxk
  1, // concrete_with_no_concrete_subtype ctxk
  2, // unique_concrete_method ctxk, m
  3, // unique_concrete_subtypes_2 ctxk, k1, k2
  3, // unique_concrete_methods_2 ctxk, m1, m2
389
  1, // no_finalizable_subclasses ctxk
390
  2  // call_site_target_value call_site, method_handle
D
duke 已提交
391 392 393 394 395 396 397 398 399 400 401 402
};

const char* Dependencies::dep_name(Dependencies::DepType dept) {
  if (!dept_in_mask(dept, all_types))  return "?bad-dep?";
  return _dep_name[dept];
}

int Dependencies::dep_args(Dependencies::DepType dept) {
  if (!dept_in_mask(dept, all_types))  return -1;
  return _dep_args[dept];
}

403
void Dependencies::check_valid_dependency_type(DepType dept) {
404
  guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, err_msg("invalid dependency type: %d", (int) dept));
405 406
}

D
duke 已提交
407 408 409
// for the sake of the compiler log, print out current dependencies:
void Dependencies::log_all_dependencies() {
  if (log() == NULL)  return;
410
  ResourceMark rm;
D
duke 已提交
411 412
  for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
    DepType dept = (DepType)deptv;
413
    GrowableArray<ciBaseObject*>* deps = _deps[dept];
414 415 416 417
    int deplen = deps->length();
    if (deplen == 0) {
      continue;
    }
D
duke 已提交
418
    int stride = dep_args(dept);
419
    GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(stride);
D
duke 已提交
420 421 422
    for (int i = 0; i < deps->length(); i += stride) {
      for (int j = 0; j < stride; j++) {
        // flush out the identities before printing
423
        ciargs->push(deps->at(i+j));
D
duke 已提交
424
      }
425 426
      write_dependency_to(log(), dept, ciargs);
      ciargs->clear();
D
duke 已提交
427
    }
428
    guarantee(deplen == deps->length(), "deps array cannot grow inside nested ResoureMark scope");
D
duke 已提交
429 430 431 432 433
  }
}

void Dependencies::write_dependency_to(CompileLog* log,
                                       DepType dept,
434
                                       GrowableArray<DepArgument>* args,
435
                                       Klass* witness) {
D
duke 已提交
436 437 438
  if (log == NULL) {
    return;
  }
439
  ResourceMark rm;
D
duke 已提交
440
  ciEnv* env = ciEnv::current();
441 442 443 444 445
  GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(args->length());
  for (GrowableArrayIterator<DepArgument> it = args->begin(); it != args->end(); ++it) {
    DepArgument arg = *it;
    if (arg.is_oop()) {
      ciargs->push(env->get_object(arg.oop_value()));
446
    } else {
447
      ciargs->push(env->get_metadata(arg.metadata_value()));
448
    }
D
duke 已提交
449
  }
450 451 452
  int argslen = ciargs->length();
  Dependencies::write_dependency_to(log, dept, ciargs, witness);
  guarantee(argslen == ciargs->length(), "ciargs array cannot grow inside nested ResoureMark scope");
D
duke 已提交
453 454 455 456
}

void Dependencies::write_dependency_to(CompileLog* log,
                                       DepType dept,
457
                                       GrowableArray<ciBaseObject*>* args,
458
                                       Klass* witness) {
459 460 461 462 463 464 465 466 467
  if (log == NULL) {
    return;
  }
  ResourceMark rm;
  GrowableArray<int>* argids = new GrowableArray<int>(args->length());
  for (GrowableArrayIterator<ciBaseObject*> it = args->begin(); it != args->end(); ++it) {
    ciBaseObject* obj = *it;
    if (obj->is_object()) {
      argids->push(log->identify(obj->as_object()));
468
    } else {
469
      argids->push(log->identify(obj->as_metadata()));
470
    }
D
duke 已提交
471 472 473 474 475 476 477
  }
  if (witness != NULL) {
    log->begin_elem("dependency_failed");
  } else {
    log->begin_elem("dependency");
  }
  log->print(" type='%s'", dep_name(dept));
478 479 480
  const int ctxkj = dep_context_arg(dept);  // -1 if no context arg
  if (ctxkj >= 0 && ctxkj < argids->length()) {
    log->print(" ctxk='%d'", argids->at(ctxkj));
D
duke 已提交
481 482
  }
  // write remaining arguments, if any.
483
  for (int j = 0; j < argids->length(); j++) {
D
duke 已提交
484 485
    if (j == ctxkj)  continue;  // already logged
    if (j == 1) {
486
      log->print(  " x='%d'",    argids->at(j));
D
duke 已提交
487
    } else {
488
      log->print(" x%d='%d'", j, argids->at(j));
D
duke 已提交
489 490 491 492 493 494 495 496 497 498 499
    }
  }
  if (witness != NULL) {
    log->object("witness", witness);
    log->stamp();
  }
  log->end_elem();
}

void Dependencies::write_dependency_to(xmlStream* xtty,
                                       DepType dept,
500
                                       GrowableArray<DepArgument>* args,
501
                                       Klass* witness) {
502 503 504 505
  if (xtty == NULL) {
    return;
  }
  ResourceMark rm;
D
duke 已提交
506 507 508 509 510 511 512 513 514
  ttyLocker ttyl;
  int ctxkj = dep_context_arg(dept);  // -1 if no context arg
  if (witness != NULL) {
    xtty->begin_elem("dependency_failed");
  } else {
    xtty->begin_elem("dependency");
  }
  xtty->print(" type='%s'", dep_name(dept));
  if (ctxkj >= 0) {
515
    xtty->object("ctxk", args->at(ctxkj).metadata_value());
D
duke 已提交
516 517
  }
  // write remaining arguments, if any.
518
  for (int j = 0; j < args->length(); j++) {
D
duke 已提交
519
    if (j == ctxkj)  continue;  // already logged
520
    DepArgument arg = args->at(j);
D
duke 已提交
521
    if (j == 1) {
522 523
      if (arg.is_oop()) {
        xtty->object("x", arg.oop_value());
524
      } else {
525
        xtty->object("x", arg.metadata_value());
526
      }
D
duke 已提交
527 528
    } else {
      char xn[10]; sprintf(xn, "x%d", j);
529 530
      if (arg.is_oop()) {
        xtty->object(xn, arg.oop_value());
531
      } else {
532
        xtty->object(xn, arg.metadata_value());
533
      }
D
duke 已提交
534 535 536 537 538 539 540 541 542
    }
  }
  if (witness != NULL) {
    xtty->object("witness", witness);
    xtty->stamp();
  }
  xtty->end_elem();
}

543
void Dependencies::print_dependency(DepType dept, GrowableArray<DepArgument>* args,
544
                                    Klass* witness) {
D
duke 已提交
545 546 547 548 549 550 551
  ResourceMark rm;
  ttyLocker ttyl;   // keep the following output all in one block
  tty->print_cr("%s of type %s",
                (witness == NULL)? "Dependency": "Failed dependency",
                dep_name(dept));
  // print arguments
  int ctxkj = dep_context_arg(dept);  // -1 if no context arg
552 553
  for (int j = 0; j < args->length(); j++) {
    DepArgument arg = args->at(j);
D
duke 已提交
554
    bool put_star = false;
555
    if (arg.is_null())  continue;
D
duke 已提交
556 557
    const char* what;
    if (j == ctxkj) {
558
      assert(arg.is_metadata(), "must be");
D
duke 已提交
559
      what = "context";
560 561
      put_star = !Dependencies::is_concrete_klass((Klass*)arg.metadata_value());
    } else if (arg.is_method()) {
D
duke 已提交
562
      what = "method ";
563
      put_star = !Dependencies::is_concrete_method((Method*)arg.metadata_value(), NULL);
564
    } else if (arg.is_klass()) {
D
duke 已提交
565 566 567 568 569
      what = "class  ";
    } else {
      what = "object ";
    }
    tty->print("  %s = %s", what, (put_star? "*": ""));
570
    if (arg.is_klass())
H
hseigel 已提交
571
      tty->print("%s", ((Klass*)arg.metadata_value())->external_name());
572 573
    else if (arg.is_method())
      ((Method*)arg.metadata_value())->print_value();
D
duke 已提交
574
    else
575
      ShouldNotReachHere(); // Provide impl for this type.
D
duke 已提交
576 577 578 579 580 581
    tty->cr();
  }
  if (witness != NULL) {
    bool put_star = !Dependencies::is_concrete_klass(witness);
    tty->print_cr("  witness = %s%s",
                  (put_star? "*": ""),
H
hseigel 已提交
582
                  witness->external_name());
D
duke 已提交
583 584 585
  }
}

586
void Dependencies::DepStream::log_dependency(Klass* witness) {
D
duke 已提交
587
  if (_deps == NULL && xtty == NULL)  return;  // fast cutout for runtime
588
  ResourceMark rm;
589 590
  const int nargs = argument_count();
  GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs);
D
duke 已提交
591
  for (int j = 0; j < nargs; j++) {
592
    if (type() == call_site_target_value) {
593
      args->push(argument_oop(j));
594
    } else {
595
      args->push(argument(j));
596
    }
597
  }
598
  int argslen = args->length();
D
duke 已提交
599
  if (_deps != NULL && _deps->log() != NULL) {
600
    Dependencies::write_dependency_to(_deps->log(), type(), args, witness);
D
duke 已提交
601
  } else {
602
    Dependencies::write_dependency_to(xtty, type(), args, witness);
D
duke 已提交
603
  }
604
  guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope");
D
duke 已提交
605 606
}

607
void Dependencies::DepStream::print_dependency(Klass* witness, bool verbose) {
608
  ResourceMark rm;
D
duke 已提交
609
  int nargs = argument_count();
610
  GrowableArray<DepArgument>* args = new GrowableArray<DepArgument>(nargs);
D
duke 已提交
611
  for (int j = 0; j < nargs; j++) {
612
    args->push(argument(j));
D
duke 已提交
613
  }
614 615
  int argslen = args->length();
  Dependencies::print_dependency(type(), args, witness);
D
duke 已提交
616 617 618 619 620 621 622
  if (verbose) {
    if (_code != NULL) {
      tty->print("  code: ");
      _code->print_value_on(tty);
      tty->cr();
    }
  }
623
  guarantee(argslen == args->length(), "args array cannot grow inside nested ResoureMark scope");
D
duke 已提交
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
}


/// Dependency stream support (decodes dependencies from an nmethod):

#ifdef ASSERT
void Dependencies::DepStream::initial_asserts(size_t byte_limit) {
  assert(must_be_in_vm(), "raw oops here");
  _byte_limit = byte_limit;
  _type       = (DepType)(end_marker-1);  // defeat "already at end" assert
  assert((_code!=NULL) + (_deps!=NULL) == 1, "one or t'other");
}
#endif //ASSERT

bool Dependencies::DepStream::next() {
  assert(_type != end_marker, "already at end");
  if (_bytes.position() == 0 && _code != NULL
      && _code->dependencies_size() == 0) {
    // Method has no dependencies at all.
    return false;
  }
  int code_byte = (_bytes.read_byte() & 0xFF);
  if (code_byte == end_marker) {
    DEBUG_ONLY(_type = end_marker);
    return false;
  } else {
    int ctxk_bit = (code_byte & Dependencies::default_context_type_bit);
    code_byte -= ctxk_bit;
    DepType dept = (DepType)code_byte;
    _type = dept;
654
    Dependencies::check_valid_dependency_type(dept);
D
duke 已提交
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
    int stride = _dep_args[dept];
    assert(stride == dep_args(dept), "sanity");
    int skipj = -1;
    if (ctxk_bit != 0) {
      skipj = 0;  // currently the only context argument is at zero
      assert(skipj == dep_context_arg(dept), "zero arg always ctxk");
    }
    for (int j = 0; j < stride; j++) {
      _xi[j] = (j == skipj)? 0: _bytes.read_int();
    }
    DEBUG_ONLY(_xi[stride] = -1);   // help detect overruns
    return true;
  }
}

670 671 672 673 674 675 676 677 678 679
inline Metadata* Dependencies::DepStream::recorded_metadata_at(int i) {
  Metadata* o = NULL;
  if (_code != NULL) {
    o = _code->metadata_at(i);
  } else {
    o = _deps->oop_recorder()->metadata_at(i);
  }
  return o;
}

D
duke 已提交
680 681 682
inline oop Dependencies::DepStream::recorded_oop_at(int i) {
  return (_code != NULL)
         ? _code->oop_at(i)
683 684 685 686 687
    : JNIHandles::resolve(_deps->oop_recorder()->oop_at(i));
}

Metadata* Dependencies::DepStream::argument(int i) {
  Metadata* result = recorded_metadata_at(argument_index(i));
688 689 690 691 692 693 694 695

  if (result == NULL) { // Explicit context argument can be compressed
    int ctxkj = dep_context_arg(type());  // -1 if no explicit context arg
    if (ctxkj >= 0 && i == ctxkj && ctxkj+1 < argument_count()) {
      result = ctxk_encoded_as_null(type(), argument(ctxkj+1));
    }
  }

696 697
  assert(result == NULL || result->is_klass() || result->is_method(), "must be");
  return result;
D
duke 已提交
698 699
}

700 701 702 703
oop Dependencies::DepStream::argument_oop(int i) {
  oop result = recorded_oop_at(argument_index(i));
  assert(result == NULL || result->is_oop(), "must be");
  return result;
D
duke 已提交
704 705
}

706
Klass* Dependencies::DepStream::context_type() {
D
duke 已提交
707
  assert(must_be_in_vm(), "raw oops here");
708 709 710

  // Most dependencies have an explicit context type argument.
  {
711
    int ctxkj = dep_context_arg(type());  // -1 if no explicit context arg
712
    if (ctxkj >= 0) {
713
      Metadata* k = argument(ctxkj);
714 715
      assert(k != NULL && k->is_klass(), "type check");
      return (Klass*)k;
716 717 718 719 720 721
    }
  }

  // Some dependencies are using the klass of the first object
  // argument as implicit context type (e.g. call_site_target_value).
  {
722
    int ctxkj = dep_implicit_context_arg(type());
723
    if (ctxkj >= 0) {
724
      Klass* k = argument_oop(ctxkj)->klass();
725
      assert(k != NULL && k->is_klass(), "type check");
726
      return (Klass*) k;
D
duke 已提交
727 728
    }
  }
729 730 731 732

  // And some dependencies don't have a context type at all,
  // e.g. evol_method.
  return NULL;
D
duke 已提交
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
}

/// Checking dependencies:

// This hierarchy walker inspects subtypes of a given type,
// trying to find a "bad" class which breaks a dependency.
// Such a class is called a "witness" to the broken dependency.
// While searching around, we ignore "participants", which
// are already known to the dependency.
class ClassHierarchyWalker {
 public:
  enum { PARTICIPANT_LIMIT = 3 };

 private:
  // optional method descriptor to check for:
748 749
  Symbol* _name;
  Symbol* _signature;
D
duke 已提交
750 751

  // special classes which are not allowed to be witnesses:
752
  Klass*    _participants[PARTICIPANT_LIMIT+1];
D
duke 已提交
753 754 755
  int       _num_participants;

  // cache of method lookups
756
  Method* _found_methods[PARTICIPANT_LIMIT+1];
D
duke 已提交
757 758 759 760

  // if non-zero, tells how many witnesses to convert to participants
  int       _record_witnesses;

761
  void initialize(Klass* participant) {
D
duke 已提交
762 763 764 765 766 767 768 769 770 771 772 773
    _record_witnesses = 0;
    _participants[0]  = participant;
    _found_methods[0] = NULL;
    _num_participants = 0;
    if (participant != NULL) {
      // Terminating NULL.
      _participants[1] = NULL;
      _found_methods[1] = NULL;
      _num_participants = 1;
    }
  }

774
  void initialize_from_method(Method* m) {
D
duke 已提交
775 776 777 778 779 780 781 782
    assert(m != NULL && m->is_method(), "sanity");
    _name      = m->name();
    _signature = m->signature();
  }

 public:
  // The walker is initialized to recognize certain methods and/or types
  // as friendly participants.
783
  ClassHierarchyWalker(Klass* participant, Method* m) {
D
duke 已提交
784 785 786
    initialize_from_method(m);
    initialize(participant);
  }
787
  ClassHierarchyWalker(Method* m) {
D
duke 已提交
788 789 790
    initialize_from_method(m);
    initialize(NULL);
  }
791
  ClassHierarchyWalker(Klass* participant = NULL) {
D
duke 已提交
792 793 794 795 796 797 798 799 800 801 802 803
    _name      = NULL;
    _signature = NULL;
    initialize(participant);
  }

  // This is common code for two searches:  One for concrete subtypes,
  // the other for concrete method implementations and overrides.
  bool doing_subtype_search() {
    return _name == NULL;
  }

  int num_participants() { return _num_participants; }
804
  Klass* participant(int n) {
D
duke 已提交
805 806 807 808 809
    assert((uint)n <= (uint)_num_participants, "oob");
    return _participants[n];
  }

  // Note:  If n==num_participants, returns NULL.
810
  Method* found_method(int n) {
D
duke 已提交
811
    assert((uint)n <= (uint)_num_participants, "oob");
812
    Method* fm = _found_methods[n];
D
duke 已提交
813 814 815 816 817 818 819 820
    assert(n == _num_participants || fm != NULL, "proper usage");
    assert(fm == NULL || fm->method_holder() == _participants[n], "sanity");
    return fm;
  }

#ifdef ASSERT
  // Assert that m is inherited into ctxk, without intervening overrides.
  // (May return true even if this is not true, in corner cases where we punt.)
821
  bool check_method_context(Klass* ctxk, Method* m) {
D
duke 已提交
822 823 824 825 826 827 828
    if (m->method_holder() == ctxk)
      return true;  // Quick win.
    if (m->is_private())
      return false; // Quick lose.  Should not happen.
    if (!(m->is_public() || m->is_protected()))
      // The override story is complex when packages get involved.
      return true;  // Must punt the assertion to true.
H
hseigel 已提交
829
    Klass* k = ctxk;
830
    Method* lm = k->lookup_method(m->name(), m->signature());
D
duke 已提交
831
    if (lm == NULL && k->oop_is_instance()) {
832 833
      // It might be an interface method
        lm = ((InstanceKlass*)k)->lookup_method_in_ordered_interfaces(m->name(),
D
duke 已提交
834 835 836 837 838 839
                                                                m->signature());
    }
    if (lm == m)
      // Method m is inherited into ctxk.
      return true;
    if (lm != NULL) {
840
      if (!(lm->is_public() || lm->is_protected())) {
D
duke 已提交
841 842
        // Method is [package-]private, so the override story is complex.
        return true;  // Must punt the assertion to true.
843 844 845 846 847
      }
      if (lm->is_static()) {
        // Static methods don't override non-static so punt
        return true;
      }
848 849
      if (   !Dependencies::is_concrete_method(lm, k)
          && !Dependencies::is_concrete_method(m, ctxk)
850
          && lm->method_holder()->is_subtype_of(m->method_holder()))
D
duke 已提交
851 852 853 854 855
        // Method m is overridden by lm, but both are non-concrete.
        return true;
    }
    ResourceMark rm;
    tty->print_cr("Dependency method not found in the associated context:");
H
hseigel 已提交
856
    tty->print_cr("  context = %s", ctxk->external_name());
D
duke 已提交
857 858 859 860 861 862 863 864
    tty->print(   "  method = "); m->print_short_name(tty); tty->cr();
    if (lm != NULL) {
      tty->print( "  found = "); lm->print_short_name(tty); tty->cr();
    }
    return false;
  }
#endif

865
  void add_participant(Klass* participant) {
D
duke 已提交
866 867 868 869 870 871 872 873 874 875 876 877 878
    assert(_num_participants + _record_witnesses < PARTICIPANT_LIMIT, "oob");
    int np = _num_participants++;
    _participants[np] = participant;
    _participants[np+1] = NULL;
    _found_methods[np+1] = NULL;
  }

  void record_witnesses(int add) {
    if (add > PARTICIPANT_LIMIT)  add = PARTICIPANT_LIMIT;
    assert(_num_participants + add < PARTICIPANT_LIMIT, "oob");
    _record_witnesses = add;
  }

879
  bool is_witness(Klass* k) {
D
duke 已提交
880 881 882
    if (doing_subtype_search()) {
      return Dependencies::is_concrete_klass(k);
    } else {
883 884 885 886 887 888 889 890 891 892 893
      // Search class hierarchy first.
      Method* m = InstanceKlass::cast(k)->find_instance_method(_name, _signature);
      if (!Dependencies::is_concrete_method(m, k)) {
        // Check interface defaults also, if any exist.
        Array<Method*>* default_methods = InstanceKlass::cast(k)->default_methods();
        if (default_methods == NULL)
            return false;
        m = InstanceKlass::cast(k)->find_method(default_methods, _name, _signature);
        if (!Dependencies::is_concrete_method(m, NULL))
            return false;
      }
D
duke 已提交
894 895 896 897 898 899 900
      _found_methods[_num_participants] = m;
      // Note:  If add_participant(k) is called,
      // the method m will already be memoized for it.
      return true;
    }
  }

901
  bool is_participant(Klass* k) {
D
duke 已提交
902 903 904 905 906 907 908 909
    if (k == _participants[0]) {
      return true;
    } else if (_num_participants <= 1) {
      return false;
    } else {
      return in_list(k, &_participants[1]);
    }
  }
910
  bool ignore_witness(Klass* witness) {
D
duke 已提交
911 912 913 914 915 916 917 918
    if (_record_witnesses == 0) {
      return false;
    } else {
      --_record_witnesses;
      add_participant(witness);
      return true;
    }
  }
919
  static bool in_list(Klass* x, Klass** list) {
D
duke 已提交
920
    for (int i = 0; ; i++) {
921
      Klass* y = list[i];
D
duke 已提交
922 923 924 925 926 927 928 929
      if (y == NULL)  break;
      if (y == x)  return true;
    }
    return false;  // not in list
  }

 private:
  // the actual search method:
930
  Klass* find_witness_anywhere(Klass* context_type,
D
duke 已提交
931 932 933
                                 bool participants_hide_witnesses,
                                 bool top_level_call = true);
  // the spot-checking version:
934 935
  Klass* find_witness_in(KlassDepChange& changes,
                         Klass* context_type,
D
duke 已提交
936 937
                           bool participants_hide_witnesses);
 public:
938
  Klass* find_witness_subtype(Klass* context_type, KlassDepChange* changes = NULL) {
D
duke 已提交
939 940 941 942 943 944 945 946 947 948 949 950
    assert(doing_subtype_search(), "must set up a subtype search");
    // When looking for unexpected concrete types,
    // do not look beneath expected ones.
    const bool participants_hide_witnesses = true;
    // CX > CC > C' is OK, even if C' is new.
    // CX > { CC,  C' } is not OK if C' is new, and C' is the witness.
    if (changes != NULL) {
      return find_witness_in(*changes, context_type, participants_hide_witnesses);
    } else {
      return find_witness_anywhere(context_type, participants_hide_witnesses);
    }
  }
951
  Klass* find_witness_definer(Klass* context_type, KlassDepChange* changes = NULL) {
D
duke 已提交
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
    assert(!doing_subtype_search(), "must set up a method definer search");
    // When looking for unexpected concrete methods,
    // look beneath expected ones, to see if there are overrides.
    const bool participants_hide_witnesses = true;
    // CX.m > CC.m > C'.m is not OK, if C'.m is new, and C' is the witness.
    if (changes != NULL) {
      return find_witness_in(*changes, context_type, !participants_hide_witnesses);
    } else {
      return find_witness_anywhere(context_type, !participants_hide_witnesses);
    }
  }
};

#ifndef PRODUCT
static int deps_find_witness_calls = 0;
static int deps_find_witness_steps = 0;
static int deps_find_witness_recursions = 0;
static int deps_find_witness_singles = 0;
static int deps_find_witness_print = 0; // set to -1 to force a final print
static bool count_find_witness_calls() {
  if (TraceDependencies || LogCompilation) {
    int pcount = deps_find_witness_print + 1;
    bool final_stats      = (pcount == 0);
    bool initial_call     = (pcount == 1);
    bool occasional_print = ((pcount & ((1<<10) - 1)) == 0);
    if (pcount < 0)  pcount = 1; // crude overflow protection
    deps_find_witness_print = pcount;
    if (VerifyDependencies && initial_call) {
      tty->print_cr("Warning:  TraceDependencies results may be inflated by VerifyDependencies");
    }
    if (occasional_print || final_stats) {
      // Every now and then dump a little info about dependency searching.
      if (xtty != NULL) {
985 986
       ttyLocker ttyl;
       xtty->elem("deps_find_witness calls='%d' steps='%d' recursions='%d' singles='%d'",
D
duke 已提交
987 988 989 990 991 992
                   deps_find_witness_calls,
                   deps_find_witness_steps,
                   deps_find_witness_recursions,
                   deps_find_witness_singles);
      }
      if (final_stats || (TraceDependencies && WizardMode)) {
993
        ttyLocker ttyl;
D
duke 已提交
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
        tty->print_cr("Dependency check (find_witness) "
                      "calls=%d, steps=%d (avg=%.1f), recursions=%d, singles=%d",
                      deps_find_witness_calls,
                      deps_find_witness_steps,
                      (double)deps_find_witness_steps / deps_find_witness_calls,
                      deps_find_witness_recursions,
                      deps_find_witness_singles);
      }
    }
    return true;
  }
  return false;
}
#else
#define count_find_witness_calls() (0)
#endif //PRODUCT


1012 1013
Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes,
                                               Klass* context_type,
D
duke 已提交
1014 1015
                                               bool participants_hide_witnesses) {
  assert(changes.involves_context(context_type), "irrelevant dependency");
1016
  Klass* new_type = changes.new_type();
D
duke 已提交
1017

1018
  (void)count_find_witness_calls();
D
duke 已提交
1019 1020 1021 1022 1023 1024 1025
  NOT_PRODUCT(deps_find_witness_singles++);

  // Current thread must be in VM (not native mode, as in CI):
  assert(must_be_in_vm(), "raw oops here");
  // Must not move the class hierarchy during this check:
  assert_locked_or_safepoint(Compile_lock);

1026
  int nof_impls = InstanceKlass::cast(context_type)->nof_implementors();
1027 1028 1029 1030 1031 1032 1033
  if (nof_impls > 1) {
    // Avoid this case: *I.m > { A.m, C }; B.m > C
    // %%% Until this is fixed more systematically, bail out.
    // See corresponding comment in find_witness_anywhere.
    return context_type;
  }

D
duke 已提交
1034 1035 1036 1037
  assert(!is_participant(new_type), "only old classes are participants");
  if (participants_hide_witnesses) {
    // If the new type is a subtype of a participant, we are done.
    for (int i = 0; i < num_participants(); i++) {
1038
      Klass* part = participant(i);
D
duke 已提交
1039
      if (part == NULL)  continue;
H
hseigel 已提交
1040
      assert(changes.involves_context(part) == new_type->is_subtype_of(part),
D
duke 已提交
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
             "correct marking of participants, b/c new_type is unique");
      if (changes.involves_context(part)) {
        // new guy is protected from this check by previous participant
        return NULL;
      }
    }
  }

  if (is_witness(new_type) &&
      !ignore_witness(new_type)) {
    return new_type;
  }

  return NULL;
}


// Walk hierarchy under a context type, looking for unexpected types.
// Do not report participant types, and recursively walk beneath
// them only if participants_hide_witnesses is false.
// If top_level_call is false, skip testing the context type,
// because the caller has already considered it.
1063
Klass* ClassHierarchyWalker::find_witness_anywhere(Klass* context_type,
D
duke 已提交
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
                                                     bool participants_hide_witnesses,
                                                     bool top_level_call) {
  // Current thread must be in VM (not native mode, as in CI):
  assert(must_be_in_vm(), "raw oops here");
  // Must not move the class hierarchy during this check:
  assert_locked_or_safepoint(Compile_lock);

  bool do_counts = count_find_witness_calls();

  // Check the root of the sub-hierarchy first.
  if (top_level_call) {
    if (do_counts) {
      NOT_PRODUCT(deps_find_witness_calls++);
      NOT_PRODUCT(deps_find_witness_steps++);
    }
    if (is_participant(context_type)) {
      if (participants_hide_witnesses)  return NULL;
      // else fall through to search loop...
    } else if (is_witness(context_type) && !ignore_witness(context_type)) {
      // The context is an abstract class or interface, to start with.
      return context_type;
    }
  }

  // Now we must check each implementor and each subclass.
  // Use a short worklist to avoid blowing the stack.
  // Each worklist entry is a *chain* of subklass siblings to process.
1091
  const int CHAINMAX = 100;  // >= 1 + InstanceKlass::implementors_limit
D
duke 已提交
1092 1093 1094 1095 1096
  Klass* chains[CHAINMAX];
  int    chaini = 0;  // index into worklist
  Klass* chain;       // scratch variable
#define ADD_SUBCLASS_CHAIN(k)                     {  \
    assert(chaini < CHAINMAX, "oob");                \
1097
    chain = InstanceKlass::cast(k)->subklass();      \
D
duke 已提交
1098 1099 1100 1101 1102 1103 1104 1105
    if (chain != NULL)  chains[chaini++] = chain;    }

  // Look for non-abstract subclasses.
  // (Note:  Interfaces do not have subclasses.)
  ADD_SUBCLASS_CHAIN(context_type);

  // If it is an interface, search its direct implementors.
  // (Their subclasses are additional indirect implementors.
1106
  // See InstanceKlass::add_implementor.)
D
duke 已提交
1107
  // (Note:  nof_implementors is always zero for non-interfaces.)
1108
  int nof_impls = InstanceKlass::cast(context_type)->nof_implementors();
D
duke 已提交
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
  if (nof_impls > 1) {
    // Avoid this case: *I.m > { A.m, C }; B.m > C
    // Here, I.m has 2 concrete implementations, but m appears unique
    // as A.m, because the search misses B.m when checking C.
    // The inherited method B.m was getting missed by the walker
    // when interface 'I' was the starting point.
    // %%% Until this is fixed more systematically, bail out.
    // (Old CHA had the same limitation.)
    return context_type;
  }
1119
  if (nof_impls > 0) {
1120
    Klass* impl = InstanceKlass::cast(context_type)->implementor();
1121 1122 1123 1124
    assert(impl != NULL, "just checking");
    // If impl is the same as the context_type, then more than one
    // implementor has seen. No exact info in this case.
    if (impl == context_type) {
D
duke 已提交
1125 1126 1127 1128 1129
      return context_type;  // report an inexact witness to this sad affair
    }
    if (do_counts)
      { NOT_PRODUCT(deps_find_witness_steps++); }
    if (is_participant(impl)) {
1130 1131 1132
      if (!participants_hide_witnesses) {
        ADD_SUBCLASS_CHAIN(impl);
      }
D
duke 已提交
1133 1134
    } else if (is_witness(impl) && !ignore_witness(impl)) {
      return impl;
1135 1136
    } else {
      ADD_SUBCLASS_CHAIN(impl);
D
duke 已提交
1137 1138 1139 1140 1141 1142
    }
  }

  // Recursively process each non-trivial sibling chain.
  while (chaini > 0) {
    Klass* chain = chains[--chaini];
1143
    for (Klass* sub = chain; sub != NULL; sub = sub->next_sibling()) {
D
duke 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
      if (do_counts) { NOT_PRODUCT(deps_find_witness_steps++); }
      if (is_participant(sub)) {
        if (participants_hide_witnesses)  continue;
        // else fall through to process this guy's subclasses
      } else if (is_witness(sub) && !ignore_witness(sub)) {
        return sub;
      }
      if (chaini < (VerifyDependencies? 2: CHAINMAX)) {
        // Fast path.  (Partially disabled if VerifyDependencies.)
        ADD_SUBCLASS_CHAIN(sub);
      } else {
        // Worklist overflow.  Do a recursive call.  Should be rare.
        // The recursive call will have its own worklist, of course.
        // (Note that sub has already been tested, so that there is
        // no need for the recursive call to re-test.  That's handy,
        // since the recursive call sees sub as the context_type.)
        if (do_counts) { NOT_PRODUCT(deps_find_witness_recursions++); }
1161
        Klass* witness = find_witness_anywhere(sub,
D
duke 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
                                                 participants_hide_witnesses,
                                                 /*top_level_call=*/ false);
        if (witness != NULL)  return witness;
      }
    }
  }

  // No witness found.  The dependency remains unbroken.
  return NULL;
#undef ADD_SUBCLASS_CHAIN
}


1175
bool Dependencies::is_concrete_klass(Klass* k) {
H
hseigel 已提交
1176
  if (k->is_abstract())  return false;
D
duke 已提交
1177 1178 1179 1180 1181 1182 1183
  // %%% We could treat classes which are concrete but
  // have not yet been instantiated as virtually abstract.
  // This would require a deoptimization barrier on first instantiation.
  //if (k->is_not_instantiated())  return false;
  return true;
}

1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
bool Dependencies::is_concrete_method(Method* m, Klass * k) {
  // NULL is not a concrete method,
  // statics are irrelevant to virtual call sites,
  // abstract methods are not concrete,
  // overpass (error) methods are not concrete if k is abstract
  //
  // note "true" is conservative answer --
  //     overpass clause is false if k == NULL, implies return true if
  //     answer depends on overpass clause.
  return ! ( m == NULL || m -> is_static() || m -> is_abstract() ||
             m->is_overpass() && k != NULL && k -> is_abstract() );
D
duke 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
}


Klass* Dependencies::find_finalizable_subclass(Klass* k) {
  if (k->is_interface())  return NULL;
  if (k->has_finalizer()) return k;
  k = k->subklass();
  while (k != NULL) {
    Klass* result = find_finalizable_subclass(k);
    if (result != NULL) return result;
    k = k->next_sibling();
  }
  return NULL;
}


bool Dependencies::is_concrete_klass(ciInstanceKlass* k) {
  if (k->is_abstract())  return false;
1213
  // We could also return false if k does not yet appear to be
D
duke 已提交
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
  // instantiated, if the VM version supports this distinction also.
  //if (k->is_not_instantiated())  return false;
  return true;
}

bool Dependencies::has_finalizable_subclass(ciInstanceKlass* k) {
  return k->has_finalizable_subclass();
}


// Any use of the contents (bytecodes) of a method must be
// marked by an "evol_method" dependency, if those contents
// can change.  (Note: A method is always dependent on itself.)
1227
Klass* Dependencies::check_evol_method(Method* m) {
D
duke 已提交
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246
  assert(must_be_in_vm(), "raw oops here");
  // Did somebody do a JVMTI RedefineClasses while our backs were turned?
  // Or is there a now a breakpoint?
  // (Assumes compiled code cannot handle bkpts; change if UseFastBreakpoints.)
  if (m->is_old()
      || m->number_of_breakpoints() > 0) {
    return m->method_holder();
  } else {
    return NULL;
  }
}

// This is a strong assertion:  It is that the given type
// has no subtypes whatever.  It is most useful for
// optimizing checks on reflected types or on array types.
// (Checks on types which are derived from real instances
// can be optimized more strongly than this, because we
// know that the checked type comes from a concrete type,
// and therefore we can disregard abstract types.)
1247
Klass* Dependencies::check_leaf_type(Klass* ctxk) {
D
duke 已提交
1248 1249
  assert(must_be_in_vm(), "raw oops here");
  assert_locked_or_safepoint(Compile_lock);
1250
  InstanceKlass* ctx = InstanceKlass::cast(ctxk);
D
duke 已提交
1251 1252
  Klass* sub = ctx->subklass();
  if (sub != NULL) {
1253
    return sub;
D
duke 已提交
1254 1255 1256
  } else if (ctx->nof_implementors() != 0) {
    // if it is an interface, it must be unimplemented
    // (if it is not an interface, nof_implementors is always zero)
1257
    Klass* impl = ctx->implementor();
1258 1259
    assert(impl != NULL, "must be set");
    return impl;
D
duke 已提交
1260 1261 1262 1263 1264 1265 1266 1267 1268
  } else {
    return NULL;
  }
}

// Test the assertion that conck is the only concrete subtype* of ctxk.
// The type conck itself is allowed to have have further concrete subtypes.
// This allows the compiler to narrow occurrences of ctxk by conck,
// when dealing with the types of actual instances.
1269 1270
Klass* Dependencies::check_abstract_with_unique_concrete_subtype(Klass* ctxk,
                                                                   Klass* conck,
1271
                                                                   KlassDepChange* changes) {
D
duke 已提交
1272 1273 1274 1275 1276 1277 1278
  ClassHierarchyWalker wf(conck);
  return wf.find_witness_subtype(ctxk, changes);
}

// If a non-concrete class has no concrete subtypes, it is not (yet)
// instantiatable.  This can allow the compiler to make some paths go
// dead, if they are gated by a test of the type.
1279
Klass* Dependencies::check_abstract_with_no_concrete_subtype(Klass* ctxk,
1280
                                                               KlassDepChange* changes) {
D
duke 已提交
1281 1282 1283 1284 1285 1286 1287 1288
  // Find any concrete subtype, with no participants:
  ClassHierarchyWalker wf;
  return wf.find_witness_subtype(ctxk, changes);
}


// If a concrete class has no concrete subtypes, it can always be
// exactly typed.  This allows the use of a cheaper type test.
1289
Klass* Dependencies::check_concrete_with_no_concrete_subtype(Klass* ctxk,
1290
                                                               KlassDepChange* changes) {
D
duke 已提交
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
  // Find any concrete subtype, with only the ctxk as participant:
  ClassHierarchyWalker wf(ctxk);
  return wf.find_witness_subtype(ctxk, changes);
}


// Find the unique concrete proper subtype of ctxk, or NULL if there
// is more than one concrete proper subtype.  If there are no concrete
// proper subtypes, return ctxk itself, whether it is concrete or not.
// The returned subtype is allowed to have have further concrete subtypes.
// That is, return CC1 for CX > CC1 > CC2, but NULL for CX > { CC1, CC2 }.
1302
Klass* Dependencies::find_unique_concrete_subtype(Klass* ctxk) {
D
duke 已提交
1303 1304
  ClassHierarchyWalker wf(ctxk);   // Ignore ctxk when walking.
  wf.record_witnesses(1);          // Record one other witness when walking.
1305
  Klass* wit = wf.find_witness_subtype(ctxk);
D
duke 已提交
1306
  if (wit != NULL)  return NULL;   // Too many witnesses.
1307
  Klass* conck = wf.participant(0);
D
duke 已提交
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
  if (conck == NULL) {
#ifndef PRODUCT
    // Make sure the dependency mechanism will pass this discovery:
    if (VerifyDependencies) {
      // Turn off dependency tracing while actually testing deps.
      FlagSetting fs(TraceDependencies, false);
      if (!Dependencies::is_concrete_klass(ctxk)) {
        guarantee(NULL ==
                  (void *)check_abstract_with_no_concrete_subtype(ctxk),
                  "verify dep.");
      } else {
        guarantee(NULL ==
                  (void *)check_concrete_with_no_concrete_subtype(ctxk),
                  "verify dep.");
      }
    }
#endif //PRODUCT
    return ctxk;                   // Return ctxk as a flag for "no subtypes".
  } else {
#ifndef PRODUCT
    // Make sure the dependency mechanism will pass this discovery:
    if (VerifyDependencies) {
      // Turn off dependency tracing while actually testing deps.
      FlagSetting fs(TraceDependencies, false);
      if (!Dependencies::is_concrete_klass(ctxk)) {
        guarantee(NULL == (void *)
                  check_abstract_with_unique_concrete_subtype(ctxk, conck),
                  "verify dep.");
      }
    }
#endif //PRODUCT
    return conck;
  }
}

// Test the assertion that the k[12] are the only concrete subtypes of ctxk,
// except possibly for further subtypes of k[12] themselves.
// The context type must be abstract.  The types k1 and k2 are themselves
// allowed to have further concrete subtypes.
1347 1348 1349 1350
Klass* Dependencies::check_abstract_with_exclusive_concrete_subtypes(
                                                Klass* ctxk,
                                                Klass* k1,
                                                Klass* k2,
1351
                                                KlassDepChange* changes) {
D
duke 已提交
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
  ClassHierarchyWalker wf;
  wf.add_participant(k1);
  wf.add_participant(k2);
  return wf.find_witness_subtype(ctxk, changes);
}

// Search ctxk for concrete implementations.  If there are klen or fewer,
// pack them into the given array and return the number.
// Otherwise, return -1, meaning the given array would overflow.
// (Note that a return of 0 means there are exactly no concrete subtypes.)
// In this search, if ctxk is concrete, it will be reported alone.
// For any type CC reported, no proper subtypes of CC will be reported.
1364
int Dependencies::find_exclusive_concrete_subtypes(Klass* ctxk,
D
duke 已提交
1365
                                                   int klen,
1366
                                                   Klass* karray[]) {
D
duke 已提交
1367 1368
  ClassHierarchyWalker wf;
  wf.record_witnesses(klen);
1369
  Klass* wit = wf.find_witness_subtype(ctxk);
D
duke 已提交
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
  if (wit != NULL)  return -1;  // Too many witnesses.
  int num = wf.num_participants();
  assert(num <= klen, "oob");
  // Pack the result array with the good news.
  for (int i = 0; i < num; i++)
    karray[i] = wf.participant(i);
#ifndef PRODUCT
  // Make sure the dependency mechanism will pass this discovery:
  if (VerifyDependencies) {
    // Turn off dependency tracing while actually testing deps.
    FlagSetting fs(TraceDependencies, false);
    switch (Dependencies::is_concrete_klass(ctxk)? -1: num) {
    case -1: // ctxk was itself concrete
      guarantee(num == 1 && karray[0] == ctxk, "verify dep.");
      break;
    case 0:
      guarantee(NULL == (void *)check_abstract_with_no_concrete_subtype(ctxk),
                "verify dep.");
      break;
    case 1:
      guarantee(NULL == (void *)
                check_abstract_with_unique_concrete_subtype(ctxk, karray[0]),
                "verify dep.");
      break;
    case 2:
      guarantee(NULL == (void *)
                check_abstract_with_exclusive_concrete_subtypes(ctxk,
                                                                karray[0],
                                                                karray[1]),
                "verify dep.");
      break;
    default:
      ShouldNotReachHere();  // klen > 2 yet supported
    }
  }
#endif //PRODUCT
  return num;
}

// If a class (or interface) has a unique concrete method uniqm, return NULL.
// Otherwise, return a class that contains an interfering method.
1411
Klass* Dependencies::check_unique_concrete_method(Klass* ctxk, Method* uniqm,
1412
                                                    KlassDepChange* changes) {
D
duke 已提交
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
  // Here is a missing optimization:  If uniqm->is_final(),
  // we don't really need to search beneath it for overrides.
  // This is probably not important, since we don't use dependencies
  // to track final methods.  (They can't be "definalized".)
  ClassHierarchyWalker wf(uniqm->method_holder(), uniqm);
  return wf.find_witness_definer(ctxk, changes);
}

// Find the set of all non-abstract methods under ctxk that match m.
// (The method m must be defined or inherited in ctxk.)
// Include m itself in the set, unless it is abstract.
// If this set has exactly one element, return that element.
1425
Method* Dependencies::find_unique_concrete_method(Klass* ctxk, Method* m) {
D
duke 已提交
1426 1427 1428
  ClassHierarchyWalker wf(m);
  assert(wf.check_method_context(ctxk, m), "proper context");
  wf.record_witnesses(1);
1429
  Klass* wit = wf.find_witness_definer(ctxk);
D
duke 已提交
1430
  if (wit != NULL)  return NULL;  // Too many witnesses.
1431
  Method* fm = wf.found_method(0);  // Will be NULL if num_parts == 0.
1432
  if (Dependencies::is_concrete_method(m, ctxk)) {
D
duke 已提交
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451
    if (fm == NULL) {
      // It turns out that m was always the only implementation.
      fm = m;
    } else if (fm != m) {
      // Two conflicting implementations after all.
      // (This can happen if m is inherited into ctxk and fm overrides it.)
      return NULL;
    }
  }
#ifndef PRODUCT
  // Make sure the dependency mechanism will pass this discovery:
  if (VerifyDependencies && fm != NULL) {
    guarantee(NULL == (void *)check_unique_concrete_method(ctxk, fm),
              "verify dep.");
  }
#endif //PRODUCT
  return fm;
}

1452 1453 1454
Klass* Dependencies::check_exclusive_concrete_methods(Klass* ctxk,
                                                        Method* m1,
                                                        Method* m2,
1455
                                                        KlassDepChange* changes) {
D
duke 已提交
1456 1457 1458 1459 1460 1461
  ClassHierarchyWalker wf(m1);
  wf.add_participant(m1->method_holder());
  wf.add_participant(m2->method_holder());
  return wf.find_witness_definer(ctxk, changes);
}

1462 1463
Klass* Dependencies::check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes) {
  Klass* search_at = ctxk;
D
duke 已提交
1464
  if (changes != NULL)
1465 1466
    search_at = changes->new_type(); // just look at the new bit
  return find_finalizable_subclass(search_at);
D
duke 已提交
1467 1468
}

1469
Klass* Dependencies::check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes) {
1470 1471 1472 1473 1474
  assert(call_site    ->is_a(SystemDictionary::CallSite_klass()),     "sanity");
  assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "sanity");
  if (changes == NULL) {
    // Validate all CallSites
    if (java_lang_invoke_CallSite::target(call_site) != method_handle)
1475
      return call_site->klass();  // assertion failed
1476 1477 1478 1479
  } else {
    // Validate the given CallSite
    if (call_site == changes->call_site() && java_lang_invoke_CallSite::target(call_site) != changes->method_handle()) {
      assert(method_handle != changes->method_handle(), "must be");
1480
      return call_site->klass();  // assertion failed
1481 1482 1483 1484 1485 1486
    }
  }
  return NULL;  // assertion still valid
}


1487
void Dependencies::DepStream::trace_and_log_witness(Klass* witness) {
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
  if (witness != NULL) {
    if (TraceDependencies) {
      print_dependency(witness, /*verbose=*/ true);
    }
    // The following is a no-op unless logging is enabled:
    log_dependency(witness);
  }
}


1498
Klass* Dependencies::DepStream::check_klass_dependency(KlassDepChange* changes) {
D
duke 已提交
1499
  assert_locked_or_safepoint(Compile_lock);
1500
  Dependencies::check_valid_dependency_type(type());
D
duke 已提交
1501

1502
  Klass* witness = NULL;
D
duke 已提交
1503 1504 1505 1506 1507 1508 1509 1510
  switch (type()) {
  case evol_method:
    witness = check_evol_method(method_argument(0));
    break;
  case leaf_type:
    witness = check_leaf_type(context_type());
    break;
  case abstract_with_unique_concrete_subtype:
1511
    witness = check_abstract_with_unique_concrete_subtype(context_type(), type_argument(1), changes);
D
duke 已提交
1512 1513
    break;
  case abstract_with_no_concrete_subtype:
1514
    witness = check_abstract_with_no_concrete_subtype(context_type(), changes);
D
duke 已提交
1515 1516
    break;
  case concrete_with_no_concrete_subtype:
1517
    witness = check_concrete_with_no_concrete_subtype(context_type(), changes);
D
duke 已提交
1518 1519
    break;
  case unique_concrete_method:
1520
    witness = check_unique_concrete_method(context_type(), method_argument(1), changes);
D
duke 已提交
1521 1522
    break;
  case abstract_with_exclusive_concrete_subtypes_2:
1523
    witness = check_abstract_with_exclusive_concrete_subtypes(context_type(), type_argument(1), type_argument(2), changes);
D
duke 已提交
1524 1525
    break;
  case exclusive_concrete_methods_2:
1526
    witness = check_exclusive_concrete_methods(context_type(), method_argument(1), method_argument(2), changes);
D
duke 已提交
1527 1528
    break;
  case no_finalizable_subclasses:
1529
    witness = check_has_no_finalizable_subclasses(context_type(), changes);
D
duke 已提交
1530
    break;
1531
  default:
D
duke 已提交
1532 1533 1534
    witness = NULL;
    break;
  }
1535
  trace_and_log_witness(witness);
D
duke 已提交
1536 1537 1538 1539
  return witness;
}


1540
Klass* Dependencies::DepStream::check_call_site_dependency(CallSiteDepChange* changes) {
1541 1542
  assert_locked_or_safepoint(Compile_lock);
  Dependencies::check_valid_dependency_type(type());
D
duke 已提交
1543

1544
  Klass* witness = NULL;
1545 1546
  switch (type()) {
  case call_site_target_value:
1547
    witness = check_call_site_target_value(argument_oop(0), argument_oop(1), changes);
1548 1549 1550 1551 1552 1553 1554
    break;
  default:
    witness = NULL;
    break;
  }
  trace_and_log_witness(witness);
  return witness;
D
duke 已提交
1555 1556 1557
}


1558
Klass* Dependencies::DepStream::spot_check_dependency_at(DepChange& changes) {
1559 1560 1561
  // Handle klass dependency
  if (changes.is_klass_change() && changes.as_klass_change()->involves_context(context_type()))
    return check_klass_dependency(changes.as_klass_change());
D
duke 已提交
1562

1563 1564 1565 1566 1567 1568
  // Handle CallSite dependency
  if (changes.is_call_site_change())
    return check_call_site_dependency(changes.as_call_site_change());

  // irrelevant dependency; skip it
  return NULL;
D
duke 已提交
1569 1570
}

1571 1572 1573

void DepChange::print() {
  int nsup = 0, nint = 0;
D
duke 已提交
1574
  for (ContextStream str(*this); str.next(); ) {
1575
    Klass* k = str.klass();
1576 1577
    switch (str.change_type()) {
    case Change_new_type:
1578
      tty->print_cr("  dependee = %s", InstanceKlass::cast(k)->external_name());
1579 1580 1581 1582 1583
      break;
    case Change_new_sub:
      if (!WizardMode) {
        ++nsup;
      } else {
1584
        tty->print_cr("  context super = %s", InstanceKlass::cast(k)->external_name());
1585 1586 1587 1588 1589 1590
      }
      break;
    case Change_new_impl:
      if (!WizardMode) {
        ++nint;
      } else {
1591
        tty->print_cr("  context interface = %s", InstanceKlass::cast(k)->external_name());
1592 1593 1594 1595 1596 1597
      }
      break;
    }
  }
  if (nsup + nint != 0) {
    tty->print_cr("  context supers = %d, interfaces = %d", nsup, nint);
D
duke 已提交
1598 1599 1600
  }
}

1601
void DepChange::ContextStream::start() {
1602
  Klass* new_type = _changes.is_klass_change() ? _changes.as_klass_change()->new_type() : (Klass*) NULL;
1603 1604 1605 1606 1607
  _change_type = (new_type == NULL ? NO_CHANGE : Start_Klass);
  _klass = new_type;
  _ti_base = NULL;
  _ti_index = 0;
  _ti_limit = 0;
D
duke 已提交
1608 1609 1610 1611 1612
}

bool DepChange::ContextStream::next() {
  switch (_change_type) {
  case Start_Klass:             // initial state; _klass is the new type
1613
    _ti_base = InstanceKlass::cast(_klass)->transitive_interfaces();
D
duke 已提交
1614 1615 1616 1617 1618 1619 1620
    _ti_index = 0;
    _change_type = Change_new_type;
    return true;
  case Change_new_type:
    // fall through:
    _change_type = Change_new_sub;
  case Change_new_sub:
1621 1622
    // 6598190: brackets workaround Sun Studio C++ compiler bug 6629277
    {
1623
      _klass = InstanceKlass::cast(_klass)->super();
1624 1625 1626
      if (_klass != NULL) {
        return true;
      }
D
duke 已提交
1627 1628 1629 1630 1631 1632
    }
    // else set up _ti_limit and fall through:
    _ti_limit = (_ti_base == NULL) ? 0 : _ti_base->length();
    _change_type = Change_new_impl;
  case Change_new_impl:
    if (_ti_index < _ti_limit) {
1633
      _klass = _ti_base->at(_ti_index++);
D
duke 已提交
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
      return true;
    }
    // fall through:
    _change_type = NO_CHANGE;  // iterator is exhausted
  case NO_CHANGE:
    break;
  default:
    ShouldNotReachHere();
  }
  return false;
}

1646 1647 1648 1649 1650 1651
void KlassDepChange::initialize() {
  // entire transaction must be under this lock:
  assert_lock_strong(Compile_lock);

  // Mark all dependee and all its superclasses
  // Mark transitive interfaces
D
duke 已提交
1652
  for (ContextStream str(*this); str.next(); ) {
1653 1654 1655
    Klass* d = str.klass();
    assert(!InstanceKlass::cast(d)->is_marked_dependent(), "checking");
    InstanceKlass::cast(d)->set_is_marked_dependent(true);
D
duke 已提交
1656
  }
1657 1658 1659 1660 1661 1662
}

KlassDepChange::~KlassDepChange() {
  // Unmark all dependee and all its superclasses
  // Unmark transitive interfaces
  for (ContextStream str(*this); str.next(); ) {
1663 1664
    Klass* d = str.klass();
    InstanceKlass::cast(d)->set_is_marked_dependent(false);
D
duke 已提交
1665 1666 1667
  }
}

1668
bool KlassDepChange::involves_context(Klass* k) {
H
hseigel 已提交
1669
  if (k == NULL || !k->oop_is_instance()) {
1670 1671
    return false;
  }
1672
  InstanceKlass* ik = InstanceKlass::cast(k);
1673
  bool is_contained = ik->is_marked_dependent();
H
hseigel 已提交
1674
  assert(is_contained == new_type()->is_subtype_of(k),
1675 1676 1677 1678
         "correct marking of potential context types");
  return is_contained;
}

D
duke 已提交
1679 1680 1681 1682 1683 1684 1685 1686 1687
#ifndef PRODUCT
void Dependencies::print_statistics() {
  if (deps_find_witness_print != 0) {
    // Call one final time, to flush out the data.
    deps_find_witness_print = -1;
    count_find_witness_calls();
  }
}
#endif