klass.cpp 21.5 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1997, 2012, 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
#include "precompiled.hpp"
26 27
#include "classfile/javaClasses.hpp"
#include "classfile/dictionary.hpp"
28 29
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
30
#include "gc_implementation/shared/markSweep.inline.hpp"
31
#include "gc_interface/collectedHeap.inline.hpp"
32
#include "memory/metadataFactory.hpp"
33 34 35 36 37 38
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/klass.inline.hpp"
#include "oops/oop.inline2.hpp"
#include "runtime/atomic.hpp"
39 40 41 42 43 44
#include "utilities/stack.hpp"
#ifndef SERIALGC
#include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
#include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
#include "gc_implementation/parallelScavenge/psScavenge.hpp"
#endif
D
duke 已提交
45

46 47 48 49
void Klass::set_name(Symbol* n) {
  _name = n;
  if (_name != NULL) _name->increment_refcount();
}
D
duke 已提交
50

51
bool Klass::is_subclass_of(Klass* k) const {
D
duke 已提交
52
  // Run up the super chain and check
53
  if (this == k) return true;
D
duke 已提交
54

55
  Klass* t = const_cast<Klass*>(this)->super();
D
duke 已提交
56 57 58 59 60 61 62 63

  while (t != NULL) {
    if (t == k) return true;
    t = Klass::cast(t)->super();
  }
  return false;
}

64
bool Klass::search_secondary_supers(Klass* k) const {
D
duke 已提交
65 66 67 68
  // Put some extra logic here out-of-line, before the search proper.
  // This cuts down the size of the inline method.

  // This is necessary, since I am never in my own secondary_super list.
69
  if (this == k)
D
duke 已提交
70 71 72 73
    return true;
  // Scan the array-of-objects for a match
  int cnt = secondary_supers()->length();
  for (int i = 0; i < cnt; i++) {
74
    if (secondary_supers()->at(i) == k) {
D
duke 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
      ((Klass*)this)->set_secondary_super_cache(k);
      return true;
    }
  }
  return false;
}

// Return self, except for abstract classes with exactly 1
// implementor.  Then return the 1 concrete implementation.
Klass *Klass::up_cast_abstract() {
  Klass *r = this;
  while( r->is_abstract() ) {   // Receiver is abstract?
    Klass *s = r->subklass();   // Check for exactly 1 subklass
    if( !s || s->next_sibling() ) // Oops; wrong count; give up
      return this;              // Return 'this' as a no-progress flag
    r = s;                    // Loop till find concrete class
  }
  return r;                   // Return the 1 concrete class
}

T
twisti 已提交
95
// Find LCA in class hierarchy
D
duke 已提交
96 97 98
Klass *Klass::LCA( Klass *k2 ) {
  Klass *k1 = this;
  while( 1 ) {
99 100 101 102
    if( k1->is_subtype_of(k2) ) return k2;
    if( k2->is_subtype_of(k1) ) return k1;
    k1 = k1->super();
    k2 = k2->super();
D
duke 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  }
}


void Klass::check_valid_for_instantiation(bool throwError, TRAPS) {
  ResourceMark rm(THREAD);
  THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
            : vmSymbols::java_lang_InstantiationException(), external_name());
}


void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
  THROW(vmSymbols::java_lang_ArrayStoreException());
}


void Klass::initialize(TRAPS) {
  ShouldNotReachHere();
}

123
bool Klass::compute_is_subtype_of(Klass* k) {
D
duke 已提交
124 125 126 127 128
  assert(k->is_klass(), "argument must be a class");
  return is_subclass_of(k);
}


129
Method* Klass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
D
duke 已提交
130 131 132 133 134 135 136 137 138
#ifdef ASSERT
  tty->print_cr("Error: uncached_lookup_method called on a klass oop."
                " Likely error: reflection method does not correctly"
                " wrap return value in a mirror object.");
#endif
  ShouldNotReachHere();
  return NULL;
}

139 140 141 142 143 144 145
void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) {
  return Metaspace::allocate(loader_data, word_size, /*read_only*/false,
                             Metaspace::ClassType, CHECK_NULL);
}

Klass::Klass() {
  Klass* k = this;
D
duke 已提交
146 147 148

  { // Preinitialize supertype information.
    // A later call to initialize_supers() may update these settings:
149
    set_super(NULL);
D
duke 已提交
150
    for (juint i = 0; i < Klass::primary_super_limit(); i++) {
151
      _primary_supers[i] = NULL;
D
duke 已提交
152
    }
153 154 155
    set_secondary_supers(NULL);
    _primary_supers[0] = k;
    set_super_check_offset(in_bytes(primary_supers_offset()));
D
duke 已提交
156 157
  }

158 159 160 161
  set_java_mirror(NULL);
  set_modifier_flags(0);
  set_layout_helper(Klass::_lh_neutral_value);
  set_name(NULL);
D
duke 已提交
162 163
  AccessFlags af;
  af.set_flags(0);
164 165 166 167 168 169
  set_access_flags(af);
  set_subklass(NULL);
  set_next_sibling(NULL);
  set_next_link(NULL);
  set_alloc_count(0);
  TRACE_SET_KLASS_TRACE_ID(this, 0);
D
duke 已提交
170

171 172 173
  set_prototype_header(markOopDesc::prototype());
  set_biased_lock_revocation_count(0);
  set_last_biased_lock_bulk_revocation_time(0);
D
duke 已提交
174

175 176 177
  // The klass doesn't have any references at this point.
  clear_modified_oops();
  clear_accumulated_modified_oops();
D
duke 已提交
178 179 180 181 182 183
}

jint Klass::array_layout_helper(BasicType etype) {
  assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
  // Note that T_ARRAY is not allowed here.
  int  hsize = arrayOopDesc::base_offset_in_bytes(etype);
184
  int  esize = type2aelembytes(etype);
D
duke 已提交
185 186 187 188 189
  bool isobj = (etype == T_OBJECT);
  int  tag   =  isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
  int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));

  assert(lh < (int)_lh_neutral_value, "must look like an array layout");
190
  assert(layout_helper_is_array(lh), "correct kind");
D
duke 已提交
191 192 193 194 195 196 197 198 199 200 201 202
  assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
  assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
  assert(layout_helper_header_size(lh) == hsize, "correct decode");
  assert(layout_helper_element_type(lh) == etype, "correct decode");
  assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");

  return lh;
}

bool Klass::can_be_primary_super_slow() const {
  if (super() == NULL)
    return true;
203
  else if (super()->super_depth() >= primary_super_limit()-1)
D
duke 已提交
204 205 206 207 208
    return false;
  else
    return true;
}

209
void Klass::initialize_supers(Klass* k, TRAPS) {
D
duke 已提交
210 211 212 213 214 215 216
  if (FastSuperclassLimit == 0) {
    // None of the other machinery matters.
    set_super(k);
    return;
  }
  if (k == NULL) {
    set_super(NULL);
217
    _primary_supers[0] = this;
D
duke 已提交
218
    assert(super_depth() == 0, "Object must already be initialized properly");
219 220
  } else if (k != super() || k == SystemDictionary::Object_klass()) {
    assert(super() == NULL || super() == SystemDictionary::Object_klass(),
D
duke 已提交
221 222
           "initialize this only once to a non-trivial value");
    set_super(k);
223
    Klass* sup = k;
D
duke 已提交
224 225 226 227 228
    int sup_depth = sup->super_depth();
    juint my_depth  = MIN2(sup_depth + 1, (int)primary_super_limit());
    if (!can_be_primary_super_slow())
      my_depth = primary_super_limit();
    for (juint i = 0; i < my_depth; i++) {
229
      _primary_supers[i] = sup->_primary_supers[i];
D
duke 已提交
230
    }
231
    Klass* *super_check_cell;
D
duke 已提交
232
    if (my_depth < primary_super_limit()) {
233
      _primary_supers[my_depth] = this;
D
duke 已提交
234 235 236 237 238
      super_check_cell = &_primary_supers[my_depth];
    } else {
      // Overflow of the primary_supers array forces me to be secondary.
      super_check_cell = &_secondary_super_cache;
    }
239
    set_super_check_offset((address)super_check_cell - (address) this);
D
duke 已提交
240 241 242 243 244

#ifdef ASSERT
    {
      juint j = super_depth();
      assert(j == my_depth, "computed accessor gets right answer");
245
      Klass* t = this;
D
duke 已提交
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
      while (!Klass::cast(t)->can_be_primary_super()) {
        t = Klass::cast(t)->super();
        j = Klass::cast(t)->super_depth();
      }
      for (juint j1 = j+1; j1 < primary_super_limit(); j1++) {
        assert(primary_super_of_depth(j1) == NULL, "super list padding");
      }
      while (t != NULL) {
        assert(primary_super_of_depth(j) == t, "super list initialization");
        t = Klass::cast(t)->super();
        --j;
      }
      assert(j == (juint)-1, "correct depth count");
    }
#endif
  }

  if (secondary_supers() == NULL) {
    KlassHandle this_kh (THREAD, this);

    // Now compute the list of secondary supertypes.
    // Secondaries can occasionally be on the super chain,
    // if the inline "_primary_supers" array overflows.
    int extras = 0;
270 271
    Klass* p;
    for (p = super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) {
D
duke 已提交
272 273 274
      ++extras;
    }

275 276
    ResourceMark rm(THREAD);  // need to reclaim GrowableArrays allocated below

D
duke 已提交
277
    // Compute the "real" non-extra secondaries.
278 279 280 281 282
    GrowableArray<Klass*>* secondaries = compute_secondary_supers(extras);
    if (secondaries == NULL) {
      // secondary_supers set by compute_secondary_supers
      return;
    }
D
duke 已提交
283

284 285 286
    GrowableArray<Klass*>* primaries = new GrowableArray<Klass*>(extras);

    for (p = this_kh->super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) {
D
duke 已提交
287 288 289 290 291 292 293 294 295
      int i;                    // Scan for overflow primaries being duplicates of 2nd'arys

      // This happens frequently for very deeply nested arrays: the
      // primary superclass chain overflows into the secondary.  The
      // secondary list contains the element_klass's secondaries with
      // an extra array dimension added.  If the element_klass's
      // secondary list already contains some primary overflows, they
      // (with the extra level of array-ness) will collide with the
      // normal primary superclass overflows.
296 297
      for( i = 0; i < secondaries->length(); i++ ) {
        if( secondaries->at(i) == p )
D
duke 已提交
298
          break;
299
      }
D
duke 已提交
300 301
      if( i < secondaries->length() )
        continue;               // It's a dup, don't put it in
302
      primaries->push(p);
D
duke 已提交
303
    }
304 305 306 307 308 309 310 311 312 313 314
    // Combine the two arrays into a metadata object to pack the array.
    // The primaries are added in the reverse order, then the secondaries.
    int new_length = primaries->length() + secondaries->length();
    Array<Klass*>* s2 = MetadataFactory::new_array<Klass*>(
                                       class_loader_data(), new_length, CHECK);
    int fill_p = primaries->length();
    for (int j = 0; j < fill_p; j++) {
      s2->at_put(j, primaries->pop());  // add primaries in reverse order.
    }
    for( int j = 0; j < secondaries->length(); j++ ) {
      s2->at_put(j+fill_p, secondaries->at(j));  // add secondaries on the end.
D
duke 已提交
315 316 317 318
    }

  #ifdef ASSERT
      // We must not copy any NULL placeholders left over from bootstrap.
319 320
    for (int j = 0; j < s2->length(); j++) {
      assert(s2->at(j) != NULL, "correct bootstrapping order");
D
duke 已提交
321 322 323
    }
  #endif

324
    this_kh->set_secondary_supers(s2);
D
duke 已提交
325 326 327
  }
}

328
GrowableArray<Klass*>* Klass::compute_secondary_supers(int num_extra_slots) {
D
duke 已提交
329
  assert(num_extra_slots == 0, "override for complex klasses");
330 331
  set_secondary_supers(Universe::the_empty_klass_array());
  return NULL;
D
duke 已提交
332 333 334 335 336 337 338
}


Klass* Klass::subklass() const {
  return _subklass == NULL ? NULL : Klass::cast(_subklass);
}

339 340 341
InstanceKlass* Klass::superklass() const {
  assert(super() == NULL || super()->oop_is_instance(), "must be instance klass");
  return _super == NULL ? NULL : InstanceKlass::cast(_super);
D
duke 已提交
342 343 344 345 346 347
}

Klass* Klass::next_sibling() const {
  return _next_sibling == NULL ? NULL : Klass::cast(_next_sibling);
}

348 349 350
void Klass::set_subklass(Klass* s) {
  assert(s != this, "sanity check");
  _subklass = s;
D
duke 已提交
351 352
}

353 354 355
void Klass::set_next_sibling(Klass* s) {
  assert(s != this, "sanity check");
  _next_sibling = s;
D
duke 已提交
356 357 358
}

void Klass::append_to_sibling_list() {
359
  debug_only(if (!SharedSkipVerify) verify();)
D
duke 已提交
360
  // add ourselves to superklass' subklass list
361
  InstanceKlass* super = superklass();
D
duke 已提交
362 363 364 365 366
  if (super == NULL) return;        // special case: class Object
  assert(SharedSkipVerify ||
         (!super->is_interface()    // interfaces cannot be supers
          && (super->superklass() == NULL || !is_interface())),
         "an interface can only be a subklass of Object");
367
  Klass* prev_first_subklass = super->subklass_oop();
D
duke 已提交
368 369 370 371 372
  if (prev_first_subklass != NULL) {
    // set our sibling to be the superklass' previous first subklass
    set_next_sibling(prev_first_subklass);
  }
  // make ourselves the superklass' first subklass
373 374
  super->set_subklass(this);
  debug_only(if (!SharedSkipVerify) verify();)
D
duke 已提交
375 376 377 378
}

void Klass::remove_from_sibling_list() {
  // remove receiver from sibling list
379 380
  InstanceKlass* super = superklass();
  assert(super != NULL || this == SystemDictionary::Object_klass(), "should have super");
D
duke 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393
  if (super == NULL) return;        // special case: class Object
  if (super->subklass() == this) {
    // first subklass
    super->set_subklass(_next_sibling);
  } else {
    Klass* sib = super->subklass();
    while (sib->next_sibling() != this) {
      sib = sib->next_sibling();
    };
    sib->set_next_sibling(_next_sibling);
  }
}

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
bool Klass::is_loader_alive(BoolObjectClosure* is_alive) {
  assert(is_metadata(), "p is not meta-data");
  assert(ClassLoaderDataGraph::contains((address)this), "is in the metaspace");
  // The class is alive iff the class loader is alive.
  oop loader = class_loader();
  return (loader == NULL) || is_alive->do_object_b(loader);
}

void Klass::clean_weak_klass_links(BoolObjectClosure* is_alive) {
  if (!ClassUnloading) {
    return;
  }

  Klass* root = SystemDictionary::Object_klass();
  Stack<Klass*, mtGC> stack;

  stack.push(root);
  while (!stack.is_empty()) {
    Klass* current = stack.pop();

    assert(current->is_loader_alive(is_alive), "just checking, this should be live");

    // Find and set the first alive subklass
    Klass* sub = current->subklass_oop();
    while (sub != NULL && !sub->is_loader_alive(is_alive)) {
D
duke 已提交
419 420 421
#ifndef PRODUCT
        if (TraceClassUnloading && WizardMode) {
          ResourceMark rm;
422
        tty->print_cr("[Unlinking class (subclass) %s]", sub->external_name());
D
duke 已提交
423 424
        }
#endif
425
      sub = sub->next_sibling_oop();
D
duke 已提交
426
    }
427 428 429 430 431 432 433 434
    current->set_subklass(sub);
    if (sub != NULL) {
      stack.push(sub);
    }

    // Find and set the first alive sibling
    Klass* sibling = current->next_sibling_oop();
    while (sibling != NULL && !sibling->is_loader_alive(is_alive)) {
D
duke 已提交
435 436
          if (TraceClassUnloading && WizardMode) {
            ResourceMark rm;
437
        tty->print_cr("[Unlinking class (sibling) %s]", sibling->external_name());
D
duke 已提交
438
          }
439
      sibling = sibling->next_sibling_oop();
D
duke 已提交
440
      }
441 442 443 444 445 446 447 448 449 450
    current->set_next_sibling(sibling);
    if (sibling != NULL) {
      stack.push(sibling);
}

    // Clean the implementors list and method data.
    if (current->oop_is_instance()) {
      InstanceKlass* ik = InstanceKlass::cast(current);
      ik->clean_implementors_list(is_alive);
      ik->clean_method_data(is_alive);
D
duke 已提交
451
    }
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
  }
}

void Klass::klass_update_barrier_set(oop v) {
  record_modified_oops();
}

void Klass::klass_update_barrier_set_pre(void* p, oop v) {
  // This barrier used by G1, where it's used remember the old oop values,
  // so that we don't forget any objects that were live at the snapshot at
  // the beginning. This function is only used when we write oops into
  // Klasses. Since the Klasses are used as roots in G1, we don't have to
  // do anything here.
}

void Klass::klass_oop_store(oop* p, oop v) {
  assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
  assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");

  // do the store
  if (always_do_update_barrier) {
    klass_oop_store((volatile oop*)p, v);
D
duke 已提交
474
  } else {
475 476 477
    klass_update_barrier_set_pre((void*)p, v);
    *p = v;
    klass_update_barrier_set(v);
D
duke 已提交
478 479 480
  }
}

481 482 483 484 485 486 487 488 489 490 491 492
void Klass::klass_oop_store(volatile oop* p, oop v) {
  assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
  assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");

  klass_update_barrier_set_pre((void*)p, v);
  OrderAccess::release_store_ptr(p, v);
  klass_update_barrier_set(v);
}

void Klass::oops_do(OopClosure* cl) {
  cl->do_oop(&_java_mirror);
}
D
duke 已提交
493 494 495 496

void Klass::remove_unshareable_info() {
  set_subklass(NULL);
  set_next_sibling(NULL);
497 498 499 500 501 502
  // Clear the java mirror
  set_java_mirror(NULL);
  set_next_link(NULL);

  // Null out class_loader_data because we don't share that yet.
  set_class_loader_data(NULL);
D
duke 已提交
503 504
}

505 506 507 508
void Klass::restore_unshareable_info(TRAPS) {
  ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
  // Restore class_loader_data to the null class loader data
  set_class_loader_data(loader_data);
D
duke 已提交
509

510 511 512
  // Add to null class loader list first before creating the mirror
  // (same order as class file parsing)
  loader_data->add_class(this);
513

514 515 516
  // Recreate the class mirror
  java_lang_Class::create_mirror(this, CHECK);
}
517

518
Klass* Klass::array_klass_or_null(int rank) {
D
duke 已提交
519 520 521 522 523 524 525
  EXCEPTION_MARK;
  // No exception can be thrown by array_klass_impl when called with or_null == true.
  // (In anycase, the execption mark will fail if it do so)
  return array_klass_impl(true, rank, THREAD);
}


526
Klass* Klass::array_klass_or_null() {
D
duke 已提交
527 528 529 530 531 532 533
  EXCEPTION_MARK;
  // No exception can be thrown by array_klass_impl when called with or_null == true.
  // (In anycase, the execption mark will fail if it do so)
  return array_klass_impl(true, THREAD);
}


534
Klass* Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
535
  fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
D
duke 已提交
536 537 538 539
  return NULL;
}


540
Klass* Klass::array_klass_impl(bool or_null, TRAPS) {
541
  fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
D
duke 已提交
542 543 544 545
  return NULL;
}


546 547
void Klass::with_array_klasses_do(void f(Klass* k)) {
  f(this);
D
duke 已提交
548 549 550
}


551 552
oop Klass::class_loader() const { return class_loader_data()->class_loader(); }

D
duke 已提交
553
const char* Klass::external_name() const {
554
  if (oop_is_instance()) {
555
    InstanceKlass* ik = (InstanceKlass*) this;
556
    if (ik->is_anonymous()) {
557
      assert(EnableInvokeDynamic, "");
558 559 560 561 562 563 564 565 566 567 568 569 570 571
      intptr_t hash = ik->java_mirror()->identity_hash();
      char     hash_buf[40];
      sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
      size_t   hash_len = strlen(hash_buf);

      size_t result_len = name()->utf8_length();
      char*  result     = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1);
      name()->as_klass_external_name(result, (int) result_len + 1);
      assert(strlen(result) == result_len, "");
      strcpy(result + result_len, hash_buf);
      assert(strlen(result) == result_len + hash_len, "");
      return result;
    }
  }
572
  if (name() == NULL)  return "<unknown>";
D
duke 已提交
573 574 575 576
  return name()->as_klass_external_name();
}


577 578
const char* Klass::signature_name() const {
  if (name() == NULL)  return "<unknown>";
D
duke 已提交
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
  return name()->as_C_string();
}

// Unless overridden, modifier_flags is 0.
jint Klass::compute_modifier_flags(TRAPS) const {
  return 0;
}

int Klass::atomic_incr_biased_lock_revocation_count() {
  return (int) Atomic::add(1, &_biased_lock_revocation_count);
}

// Unless overridden, jvmti_class_status has no flags set.
jint Klass::jvmti_class_status() const {
  return 0;
}

596

D
duke 已提交
597 598
// Printing

599 600 601 602 603 604 605 606
void Klass::print_on(outputStream* st) const {
  ResourceMark rm;
  // print title
  st->print("%s", internal_name());
  print_address_on(st);
  st->cr();
}

D
duke 已提交
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
void Klass::oop_print_on(oop obj, outputStream* st) {
  ResourceMark rm;
  // print title
  st->print_cr("%s ", internal_name());
  obj->print_address_on(st);

  if (WizardMode) {
     // print header
     obj->mark()->print_on(st);
  }

  // print class
  st->print(" - klass: ");
  obj->klass()->print_value_on(st);
  st->cr();
}

void Klass::oop_print_value_on(oop obj, outputStream* st) {
  // print title
  ResourceMark rm;              // Cannot print in debug mode without this
  st->print("%s", internal_name());
  obj->print_address_on(st);
}

631

D
duke 已提交
632 633
// Verification

634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
void Klass::verify_on(outputStream* st) {
  guarantee(!Universe::heap()->is_in_reserved(this), "Shouldn't be");
  guarantee(this->is_metadata(), "should be in metaspace");

  assert(ClassLoaderDataGraph::contains((address)this), "Should be");

  guarantee(this->is_klass(),"should be klass");

  if (super() != NULL) {
    guarantee(super()->is_metadata(), "should be in metaspace");
    guarantee(super()->is_klass(), "should be klass");
  }
  if (secondary_super_cache() != NULL) {
    Klass* ko = secondary_super_cache();
    guarantee(ko->is_metadata(), "should be in metaspace");
    guarantee(ko->is_klass(), "should be klass");
  }
  for ( uint i = 0; i < primary_super_limit(); i++ ) {
    Klass* ko = _primary_supers[i];
    if (ko != NULL) {
      guarantee(ko->is_metadata(), "should be in metaspace");
      guarantee(ko->is_klass(), "should be klass");
    }
  }

  if (java_mirror() != NULL) {
    guarantee(java_mirror()->is_oop(), "should be instance");
  }
}

D
duke 已提交
664 665
void Klass::oop_verify_on(oop obj, outputStream* st) {
  guarantee(obj->is_oop(),  "should be oop");
666
  guarantee(obj->klass()->is_metadata(), "should not be in Java heap");
D
duke 已提交
667 668 669 670 671 672 673
  guarantee(obj->klass()->is_klass(), "klass field is not a klass");
}

#ifndef PRODUCT

void Klass::verify_vtable_index(int i) {
  if (oop_is_instance()) {
674
    assert(i>=0 && i<((InstanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
D
duke 已提交
675
  } else {
676
    assert(oop_is_array(), "Must be");
677
    assert(i>=0 && i<((ArrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
D
duke 已提交
678 679 680 681
  }
}

#endif