annotate src/share/vm/oops/klass.cpp @ 3743:bdb5f8c9978b

7199068: NPG: SharedSkipVerify is meaningless Summary: Remove the SharedSkipVerify flag Reviewed-by: kamg, sspitsyn, coleenp Contributed-by: harold.seigel@oracle.com
author coleenp
date Wed, 10 Oct 2012 17:04:33 -0400
parents d8ce2825b193
children 070d523b96a7
rev   line source
duke@0 1 /*
brutisso@3240 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
coleenp@3602 26 #include "classfile/javaClasses.hpp"
coleenp@3602 27 #include "classfile/dictionary.hpp"
stefank@1879 28 #include "classfile/systemDictionary.hpp"
stefank@1879 29 #include "classfile/vmSymbols.hpp"
coleenp@3602 30 #include "gc_implementation/shared/markSweep.inline.hpp"
stefank@1879 31 #include "gc_interface/collectedHeap.inline.hpp"
coleenp@3602 32 #include "memory/metadataFactory.hpp"
stefank@1879 33 #include "memory/oopFactory.hpp"
stefank@1879 34 #include "memory/resourceArea.hpp"
stefank@1879 35 #include "oops/instanceKlass.hpp"
stefank@1879 36 #include "oops/klass.inline.hpp"
stefank@1879 37 #include "oops/oop.inline2.hpp"
stefank@1879 38 #include "runtime/atomic.hpp"
coleenp@3602 39 #include "utilities/stack.hpp"
coleenp@3602 40 #ifndef SERIALGC
coleenp@3602 41 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
coleenp@3602 42 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
coleenp@3602 43 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
coleenp@3602 44 #endif
duke@0 45
coleenp@2062 46 void Klass::set_name(Symbol* n) {
coleenp@2062 47 _name = n;
coleenp@2062 48 if (_name != NULL) _name->increment_refcount();
coleenp@2062 49 }
duke@0 50
coleenp@3602 51 bool Klass::is_subclass_of(Klass* k) const {
duke@0 52 // Run up the super chain and check
coleenp@3602 53 if (this == k) return true;
duke@0 54
coleenp@3602 55 Klass* t = const_cast<Klass*>(this)->super();
duke@0 56
duke@0 57 while (t != NULL) {
duke@0 58 if (t == k) return true;
duke@0 59 t = Klass::cast(t)->super();
duke@0 60 }
duke@0 61 return false;
duke@0 62 }
duke@0 63
coleenp@3602 64 bool Klass::search_secondary_supers(Klass* k) const {
duke@0 65 // Put some extra logic here out-of-line, before the search proper.
duke@0 66 // This cuts down the size of the inline method.
duke@0 67
duke@0 68 // This is necessary, since I am never in my own secondary_super list.
coleenp@3602 69 if (this == k)
duke@0 70 return true;
duke@0 71 // Scan the array-of-objects for a match
duke@0 72 int cnt = secondary_supers()->length();
duke@0 73 for (int i = 0; i < cnt; i++) {
coleenp@3602 74 if (secondary_supers()->at(i) == k) {
duke@0 75 ((Klass*)this)->set_secondary_super_cache(k);
duke@0 76 return true;
duke@0 77 }
duke@0 78 }
duke@0 79 return false;
duke@0 80 }
duke@0 81
duke@0 82 // Return self, except for abstract classes with exactly 1
duke@0 83 // implementor. Then return the 1 concrete implementation.
duke@0 84 Klass *Klass::up_cast_abstract() {
duke@0 85 Klass *r = this;
duke@0 86 while( r->is_abstract() ) { // Receiver is abstract?
duke@0 87 Klass *s = r->subklass(); // Check for exactly 1 subklass
duke@0 88 if( !s || s->next_sibling() ) // Oops; wrong count; give up
duke@0 89 return this; // Return 'this' as a no-progress flag
duke@0 90 r = s; // Loop till find concrete class
duke@0 91 }
duke@0 92 return r; // Return the 1 concrete class
duke@0 93 }
duke@0 94
twisti@605 95 // Find LCA in class hierarchy
duke@0 96 Klass *Klass::LCA( Klass *k2 ) {
duke@0 97 Klass *k1 = this;
duke@0 98 while( 1 ) {
coleenp@3602 99 if( k1->is_subtype_of(k2) ) return k2;
coleenp@3602 100 if( k2->is_subtype_of(k1) ) return k1;
coleenp@3602 101 k1 = k1->super();
coleenp@3602 102 k2 = k2->super();
duke@0 103 }
duke@0 104 }
duke@0 105
duke@0 106
duke@0 107 void Klass::check_valid_for_instantiation(bool throwError, TRAPS) {
duke@0 108 ResourceMark rm(THREAD);
duke@0 109 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
duke@0 110 : vmSymbols::java_lang_InstantiationException(), external_name());
duke@0 111 }
duke@0 112
duke@0 113
duke@0 114 void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
duke@0 115 THROW(vmSymbols::java_lang_ArrayStoreException());
duke@0 116 }
duke@0 117
duke@0 118
duke@0 119 void Klass::initialize(TRAPS) {
duke@0 120 ShouldNotReachHere();
duke@0 121 }
duke@0 122
coleenp@3602 123 bool Klass::compute_is_subtype_of(Klass* k) {
duke@0 124 assert(k->is_klass(), "argument must be a class");
duke@0 125 return is_subclass_of(k);
duke@0 126 }
duke@0 127
duke@0 128
coleenp@3602 129 Method* Klass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
duke@0 130 #ifdef ASSERT
duke@0 131 tty->print_cr("Error: uncached_lookup_method called on a klass oop."
duke@0 132 " Likely error: reflection method does not correctly"
duke@0 133 " wrap return value in a mirror object.");
duke@0 134 #endif
duke@0 135 ShouldNotReachHere();
duke@0 136 return NULL;
duke@0 137 }
duke@0 138
coleenp@3602 139 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) {
coleenp@3602 140 return Metaspace::allocate(loader_data, word_size, /*read_only*/false,
coleenp@3602 141 Metaspace::ClassType, CHECK_NULL);
coleenp@3602 142 }
coleenp@3602 143
coleenp@3602 144 Klass::Klass() {
coleenp@3602 145 Klass* k = this;
duke@0 146
duke@0 147 { // Preinitialize supertype information.
duke@0 148 // A later call to initialize_supers() may update these settings:
coleenp@3602 149 set_super(NULL);
duke@0 150 for (juint i = 0; i < Klass::primary_super_limit(); i++) {
coleenp@3602 151 _primary_supers[i] = NULL;
duke@0 152 }
coleenp@3602 153 set_secondary_supers(NULL);
coleenp@3602 154 _primary_supers[0] = k;
coleenp@3602 155 set_super_check_offset(in_bytes(primary_supers_offset()));
duke@0 156 }
duke@0 157
coleenp@3602 158 set_java_mirror(NULL);
coleenp@3602 159 set_modifier_flags(0);
coleenp@3602 160 set_layout_helper(Klass::_lh_neutral_value);
coleenp@3602 161 set_name(NULL);
duke@0 162 AccessFlags af;
duke@0 163 af.set_flags(0);
coleenp@3602 164 set_access_flags(af);
coleenp@3602 165 set_subklass(NULL);
coleenp@3602 166 set_next_sibling(NULL);
coleenp@3602 167 set_next_link(NULL);
coleenp@3602 168 set_alloc_count(0);
coleenp@3602 169 TRACE_SET_KLASS_TRACE_ID(this, 0);
duke@0 170
coleenp@3602 171 set_prototype_header(markOopDesc::prototype());
coleenp@3602 172 set_biased_lock_revocation_count(0);
coleenp@3602 173 set_last_biased_lock_bulk_revocation_time(0);
duke@0 174
coleenp@3602 175 // The klass doesn't have any references at this point.
coleenp@3602 176 clear_modified_oops();
coleenp@3602 177 clear_accumulated_modified_oops();
duke@0 178 }
duke@0 179
duke@0 180 jint Klass::array_layout_helper(BasicType etype) {
duke@0 181 assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
duke@0 182 // Note that T_ARRAY is not allowed here.
duke@0 183 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
kvn@29 184 int esize = type2aelembytes(etype);
duke@0 185 bool isobj = (etype == T_OBJECT);
duke@0 186 int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
duke@0 187 int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
duke@0 188
duke@0 189 assert(lh < (int)_lh_neutral_value, "must look like an array layout");
coleenp@3602 190 assert(layout_helper_is_array(lh), "correct kind");
duke@0 191 assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
duke@0 192 assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
duke@0 193 assert(layout_helper_header_size(lh) == hsize, "correct decode");
duke@0 194 assert(layout_helper_element_type(lh) == etype, "correct decode");
duke@0 195 assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
duke@0 196
duke@0 197 return lh;
duke@0 198 }
duke@0 199
duke@0 200 bool Klass::can_be_primary_super_slow() const {
duke@0 201 if (super() == NULL)
duke@0 202 return true;
coleenp@3602 203 else if (super()->super_depth() >= primary_super_limit()-1)
duke@0 204 return false;
duke@0 205 else
duke@0 206 return true;
duke@0 207 }
duke@0 208
coleenp@3602 209 void Klass::initialize_supers(Klass* k, TRAPS) {
duke@0 210 if (FastSuperclassLimit == 0) {
duke@0 211 // None of the other machinery matters.
duke@0 212 set_super(k);
duke@0 213 return;
duke@0 214 }
duke@0 215 if (k == NULL) {
duke@0 216 set_super(NULL);
coleenp@3602 217 _primary_supers[0] = this;
duke@0 218 assert(super_depth() == 0, "Object must already be initialized properly");
never@1142 219 } else if (k != super() || k == SystemDictionary::Object_klass()) {
never@1142 220 assert(super() == NULL || super() == SystemDictionary::Object_klass(),
duke@0 221 "initialize this only once to a non-trivial value");
duke@0 222 set_super(k);
coleenp@3602 223 Klass* sup = k;
duke@0 224 int sup_depth = sup->super_depth();
duke@0 225 juint my_depth = MIN2(sup_depth + 1, (int)primary_super_limit());
duke@0 226 if (!can_be_primary_super_slow())
duke@0 227 my_depth = primary_super_limit();
duke@0 228 for (juint i = 0; i < my_depth; i++) {
coleenp@3602 229 _primary_supers[i] = sup->_primary_supers[i];
duke@0 230 }
coleenp@3602 231 Klass* *super_check_cell;
duke@0 232 if (my_depth < primary_super_limit()) {
coleenp@3602 233 _primary_supers[my_depth] = this;
duke@0 234 super_check_cell = &_primary_supers[my_depth];
duke@0 235 } else {
duke@0 236 // Overflow of the primary_supers array forces me to be secondary.
duke@0 237 super_check_cell = &_secondary_super_cache;
duke@0 238 }
coleenp@3602 239 set_super_check_offset((address)super_check_cell - (address) this);
duke@0 240
duke@0 241 #ifdef ASSERT
duke@0 242 {
duke@0 243 juint j = super_depth();
duke@0 244 assert(j == my_depth, "computed accessor gets right answer");
coleenp@3602 245 Klass* t = this;
duke@0 246 while (!Klass::cast(t)->can_be_primary_super()) {
duke@0 247 t = Klass::cast(t)->super();
duke@0 248 j = Klass::cast(t)->super_depth();
duke@0 249 }
duke@0 250 for (juint j1 = j+1; j1 < primary_super_limit(); j1++) {
duke@0 251 assert(primary_super_of_depth(j1) == NULL, "super list padding");
duke@0 252 }
duke@0 253 while (t != NULL) {
duke@0 254 assert(primary_super_of_depth(j) == t, "super list initialization");
duke@0 255 t = Klass::cast(t)->super();
duke@0 256 --j;
duke@0 257 }
duke@0 258 assert(j == (juint)-1, "correct depth count");
duke@0 259 }
duke@0 260 #endif
duke@0 261 }
duke@0 262
duke@0 263 if (secondary_supers() == NULL) {
duke@0 264 KlassHandle this_kh (THREAD, this);
duke@0 265
duke@0 266 // Now compute the list of secondary supertypes.
duke@0 267 // Secondaries can occasionally be on the super chain,
duke@0 268 // if the inline "_primary_supers" array overflows.
duke@0 269 int extras = 0;
coleenp@3602 270 Klass* p;
coleenp@3602 271 for (p = super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) {
duke@0 272 ++extras;
duke@0 273 }
duke@0 274
coleenp@3602 275 ResourceMark rm(THREAD); // need to reclaim GrowableArrays allocated below
coleenp@3602 276
duke@0 277 // Compute the "real" non-extra secondaries.
coleenp@3602 278 GrowableArray<Klass*>* secondaries = compute_secondary_supers(extras);
coleenp@3602 279 if (secondaries == NULL) {
coleenp@3602 280 // secondary_supers set by compute_secondary_supers
coleenp@3602 281 return;
coleenp@3602 282 }
duke@0 283
coleenp@3602 284 GrowableArray<Klass*>* primaries = new GrowableArray<Klass*>(extras);
coleenp@3602 285
coleenp@3602 286 for (p = this_kh->super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) {
duke@0 287 int i; // Scan for overflow primaries being duplicates of 2nd'arys
duke@0 288
duke@0 289 // This happens frequently for very deeply nested arrays: the
duke@0 290 // primary superclass chain overflows into the secondary. The
duke@0 291 // secondary list contains the element_klass's secondaries with
duke@0 292 // an extra array dimension added. If the element_klass's
duke@0 293 // secondary list already contains some primary overflows, they
duke@0 294 // (with the extra level of array-ness) will collide with the
duke@0 295 // normal primary superclass overflows.
coleenp@3602 296 for( i = 0; i < secondaries->length(); i++ ) {
coleenp@3602 297 if( secondaries->at(i) == p )
duke@0 298 break;
coleenp@3602 299 }
duke@0 300 if( i < secondaries->length() )
duke@0 301 continue; // It's a dup, don't put it in
coleenp@3602 302 primaries->push(p);
duke@0 303 }
coleenp@3602 304 // Combine the two arrays into a metadata object to pack the array.
coleenp@3602 305 // The primaries are added in the reverse order, then the secondaries.
coleenp@3602 306 int new_length = primaries->length() + secondaries->length();
coleenp@3602 307 Array<Klass*>* s2 = MetadataFactory::new_array<Klass*>(
coleenp@3602 308 class_loader_data(), new_length, CHECK);
coleenp@3602 309 int fill_p = primaries->length();
coleenp@3602 310 for (int j = 0; j < fill_p; j++) {
coleenp@3602 311 s2->at_put(j, primaries->pop()); // add primaries in reverse order.
coleenp@3602 312 }
coleenp@3602 313 for( int j = 0; j < secondaries->length(); j++ ) {
coleenp@3602 314 s2->at_put(j+fill_p, secondaries->at(j)); // add secondaries on the end.
duke@0 315 }
duke@0 316
duke@0 317 #ifdef ASSERT
duke@0 318 // We must not copy any NULL placeholders left over from bootstrap.
coleenp@3602 319 for (int j = 0; j < s2->length(); j++) {
coleenp@3602 320 assert(s2->at(j) != NULL, "correct bootstrapping order");
duke@0 321 }
duke@0 322 #endif
duke@0 323
coleenp@3602 324 this_kh->set_secondary_supers(s2);
duke@0 325 }
duke@0 326 }
duke@0 327
coleenp@3602 328 GrowableArray<Klass*>* Klass::compute_secondary_supers(int num_extra_slots) {
duke@0 329 assert(num_extra_slots == 0, "override for complex klasses");
coleenp@3602 330 set_secondary_supers(Universe::the_empty_klass_array());
coleenp@3602 331 return NULL;
duke@0 332 }
duke@0 333
duke@0 334
duke@0 335 Klass* Klass::subklass() const {
duke@0 336 return _subklass == NULL ? NULL : Klass::cast(_subklass);
duke@0 337 }
duke@0 338
coleenp@3602 339 InstanceKlass* Klass::superklass() const {
coleenp@3602 340 assert(super() == NULL || super()->oop_is_instance(), "must be instance klass");
coleenp@3602 341 return _super == NULL ? NULL : InstanceKlass::cast(_super);
duke@0 342 }
duke@0 343
duke@0 344 Klass* Klass::next_sibling() const {
duke@0 345 return _next_sibling == NULL ? NULL : Klass::cast(_next_sibling);
duke@0 346 }
duke@0 347
coleenp@3602 348 void Klass::set_subklass(Klass* s) {
coleenp@3602 349 assert(s != this, "sanity check");
coleenp@3602 350 _subklass = s;
duke@0 351 }
duke@0 352
coleenp@3602 353 void Klass::set_next_sibling(Klass* s) {
coleenp@3602 354 assert(s != this, "sanity check");
coleenp@3602 355 _next_sibling = s;
duke@0 356 }
duke@0 357
duke@0 358 void Klass::append_to_sibling_list() {
coleenp@3743 359 debug_only(verify();)
duke@0 360 // add ourselves to superklass' subklass list
coleenp@3602 361 InstanceKlass* super = superklass();
duke@0 362 if (super == NULL) return; // special case: class Object
coleenp@3743 363 assert((!super->is_interface() // interfaces cannot be supers
duke@0 364 && (super->superklass() == NULL || !is_interface())),
duke@0 365 "an interface can only be a subklass of Object");
coleenp@3602 366 Klass* prev_first_subklass = super->subklass_oop();
duke@0 367 if (prev_first_subklass != NULL) {
duke@0 368 // set our sibling to be the superklass' previous first subklass
duke@0 369 set_next_sibling(prev_first_subklass);
duke@0 370 }
duke@0 371 // make ourselves the superklass' first subklass
coleenp@3602 372 super->set_subklass(this);
coleenp@3743 373 debug_only(verify();)
duke@0 374 }
duke@0 375
duke@0 376 void Klass::remove_from_sibling_list() {
duke@0 377 // remove receiver from sibling list
coleenp@3602 378 InstanceKlass* super = superklass();
coleenp@3602 379 assert(super != NULL || this == SystemDictionary::Object_klass(), "should have super");
duke@0 380 if (super == NULL) return; // special case: class Object
duke@0 381 if (super->subklass() == this) {
duke@0 382 // first subklass
duke@0 383 super->set_subklass(_next_sibling);
duke@0 384 } else {
duke@0 385 Klass* sib = super->subklass();
duke@0 386 while (sib->next_sibling() != this) {
duke@0 387 sib = sib->next_sibling();
duke@0 388 };
duke@0 389 sib->set_next_sibling(_next_sibling);
duke@0 390 }
duke@0 391 }
duke@0 392
coleenp@3602 393 bool Klass::is_loader_alive(BoolObjectClosure* is_alive) {
coleenp@3602 394 assert(is_metadata(), "p is not meta-data");
coleenp@3602 395 assert(ClassLoaderDataGraph::contains((address)this), "is in the metaspace");
coleenp@3602 396 // The class is alive iff the class loader is alive.
coleenp@3602 397 oop loader = class_loader();
coleenp@3602 398 return (loader == NULL) || is_alive->do_object_b(loader);
coleenp@3602 399 }
coleenp@3602 400
coleenp@3602 401 void Klass::clean_weak_klass_links(BoolObjectClosure* is_alive) {
coleenp@3602 402 if (!ClassUnloading) {
coleenp@3602 403 return;
coleenp@3602 404 }
coleenp@3602 405
coleenp@3602 406 Klass* root = SystemDictionary::Object_klass();
coleenp@3602 407 Stack<Klass*, mtGC> stack;
coleenp@3602 408
coleenp@3602 409 stack.push(root);
coleenp@3602 410 while (!stack.is_empty()) {
coleenp@3602 411 Klass* current = stack.pop();
coleenp@3602 412
coleenp@3602 413 assert(current->is_loader_alive(is_alive), "just checking, this should be live");
coleenp@3602 414
coleenp@3602 415 // Find and set the first alive subklass
coleenp@3602 416 Klass* sub = current->subklass_oop();
coleenp@3602 417 while (sub != NULL && !sub->is_loader_alive(is_alive)) {
duke@0 418 #ifndef PRODUCT
duke@0 419 if (TraceClassUnloading && WizardMode) {
duke@0 420 ResourceMark rm;
coleenp@3602 421 tty->print_cr("[Unlinking class (subclass) %s]", sub->external_name());
duke@0 422 }
duke@0 423 #endif
coleenp@3602 424 sub = sub->next_sibling_oop();
duke@0 425 }
coleenp@3602 426 current->set_subklass(sub);
coleenp@3602 427 if (sub != NULL) {
coleenp@3602 428 stack.push(sub);
coleenp@3602 429 }
coleenp@3602 430
coleenp@3602 431 // Find and set the first alive sibling
coleenp@3602 432 Klass* sibling = current->next_sibling_oop();
coleenp@3602 433 while (sibling != NULL && !sibling->is_loader_alive(is_alive)) {
duke@0 434 if (TraceClassUnloading && WizardMode) {
duke@0 435 ResourceMark rm;
coleenp@3602 436 tty->print_cr("[Unlinking class (sibling) %s]", sibling->external_name());
duke@0 437 }
coleenp@3602 438 sibling = sibling->next_sibling_oop();
duke@0 439 }
coleenp@3602 440 current->set_next_sibling(sibling);
coleenp@3602 441 if (sibling != NULL) {
coleenp@3602 442 stack.push(sibling);
coleenp@3602 443 }
coleenp@3602 444
coleenp@3602 445 // Clean the implementors list and method data.
coleenp@3602 446 if (current->oop_is_instance()) {
coleenp@3602 447 InstanceKlass* ik = InstanceKlass::cast(current);
coleenp@3602 448 ik->clean_implementors_list(is_alive);
coleenp@3602 449 ik->clean_method_data(is_alive);
duke@0 450 }
duke@0 451 }
duke@0 452 }
duke@0 453
coleenp@3602 454 void Klass::klass_update_barrier_set(oop v) {
coleenp@3602 455 record_modified_oops();
coleenp@3602 456 }
coleenp@3602 457
coleenp@3602 458 void Klass::klass_update_barrier_set_pre(void* p, oop v) {
coleenp@3602 459 // This barrier used by G1, where it's used remember the old oop values,
coleenp@3602 460 // so that we don't forget any objects that were live at the snapshot at
coleenp@3602 461 // the beginning. This function is only used when we write oops into
coleenp@3602 462 // Klasses. Since the Klasses are used as roots in G1, we don't have to
coleenp@3602 463 // do anything here.
coleenp@3602 464 }
coleenp@3602 465
coleenp@3602 466 void Klass::klass_oop_store(oop* p, oop v) {
coleenp@3602 467 assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
coleenp@3602 468 assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");
coleenp@3602 469
coleenp@3602 470 // do the store
coleenp@3602 471 if (always_do_update_barrier) {
coleenp@3602 472 klass_oop_store((volatile oop*)p, v);
coleenp@3602 473 } else {
coleenp@3602 474 klass_update_barrier_set_pre((void*)p, v);
coleenp@3602 475 *p = v;
coleenp@3602 476 klass_update_barrier_set(v);
coleenp@3602 477 }
coleenp@3602 478 }
coleenp@3602 479
coleenp@3602 480 void Klass::klass_oop_store(volatile oop* p, oop v) {
coleenp@3602 481 assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
coleenp@3602 482 assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");
coleenp@3602 483
coleenp@3602 484 klass_update_barrier_set_pre((void*)p, v);
coleenp@3602 485 OrderAccess::release_store_ptr(p, v);
coleenp@3602 486 klass_update_barrier_set(v);
coleenp@3602 487 }
coleenp@3602 488
coleenp@3602 489 void Klass::oops_do(OopClosure* cl) {
coleenp@3602 490 cl->do_oop(&_java_mirror);
coleenp@3602 491 }
duke@0 492
duke@0 493 void Klass::remove_unshareable_info() {
duke@0 494 set_subklass(NULL);
duke@0 495 set_next_sibling(NULL);
coleenp@3602 496 // Clear the java mirror
coleenp@3602 497 set_java_mirror(NULL);
coleenp@3602 498 set_next_link(NULL);
coleenp@3602 499
coleenp@3602 500 // Null out class_loader_data because we don't share that yet.
coleenp@3602 501 set_class_loader_data(NULL);
duke@0 502 }
duke@0 503
coleenp@3602 504 void Klass::restore_unshareable_info(TRAPS) {
coleenp@3602 505 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
coleenp@3602 506 // Restore class_loader_data to the null class loader data
coleenp@3602 507 set_class_loader_data(loader_data);
duke@0 508
coleenp@3602 509 // Add to null class loader list first before creating the mirror
coleenp@3602 510 // (same order as class file parsing)
coleenp@3602 511 loader_data->add_class(this);
coleenp@3602 512
coleenp@3602 513 // Recreate the class mirror
coleenp@3602 514 java_lang_Class::create_mirror(this, CHECK);
coleenp@2062 515 }
coleenp@2062 516
coleenp@3602 517 Klass* Klass::array_klass_or_null(int rank) {
duke@0 518 EXCEPTION_MARK;
duke@0 519 // No exception can be thrown by array_klass_impl when called with or_null == true.
duke@0 520 // (In anycase, the execption mark will fail if it do so)
duke@0 521 return array_klass_impl(true, rank, THREAD);
duke@0 522 }
duke@0 523
duke@0 524
coleenp@3602 525 Klass* Klass::array_klass_or_null() {
duke@0 526 EXCEPTION_MARK;
duke@0 527 // No exception can be thrown by array_klass_impl when called with or_null == true.
duke@0 528 // (In anycase, the execption mark will fail if it do so)
duke@0 529 return array_klass_impl(true, THREAD);
duke@0 530 }
duke@0 531
duke@0 532
coleenp@3602 533 Klass* Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
coleenp@3707 534 fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
duke@0 535 return NULL;
duke@0 536 }
duke@0 537
duke@0 538
coleenp@3602 539 Klass* Klass::array_klass_impl(bool or_null, TRAPS) {
coleenp@3707 540 fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
duke@0 541 return NULL;
duke@0 542 }
duke@0 543
duke@0 544
coleenp@3602 545 void Klass::with_array_klasses_do(void f(Klass* k)) {
coleenp@3602 546 f(this);
duke@0 547 }
duke@0 548
duke@0 549
coleenp@3602 550 oop Klass::class_loader() const { return class_loader_data()->class_loader(); }
coleenp@3602 551
duke@0 552 const char* Klass::external_name() const {
jrose@431 553 if (oop_is_instance()) {
coleenp@3602 554 InstanceKlass* ik = (InstanceKlass*) this;
jrose@431 555 if (ik->is_anonymous()) {
twisti@2263 556 assert(EnableInvokeDynamic, "");
jrose@431 557 intptr_t hash = ik->java_mirror()->identity_hash();
jrose@431 558 char hash_buf[40];
jrose@431 559 sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
jrose@431 560 size_t hash_len = strlen(hash_buf);
jrose@431 561
jrose@431 562 size_t result_len = name()->utf8_length();
jrose@431 563 char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1);
jrose@431 564 name()->as_klass_external_name(result, (int) result_len + 1);
jrose@431 565 assert(strlen(result) == result_len, "");
jrose@431 566 strcpy(result + result_len, hash_buf);
jrose@431 567 assert(strlen(result) == result_len + hash_len, "");
jrose@431 568 return result;
jrose@431 569 }
jrose@431 570 }
jrose@1039 571 if (name() == NULL) return "<unknown>";
duke@0 572 return name()->as_klass_external_name();
duke@0 573 }
duke@0 574
duke@0 575
jrose@1039 576 const char* Klass::signature_name() const {
jrose@1039 577 if (name() == NULL) return "<unknown>";
duke@0 578 return name()->as_C_string();
duke@0 579 }
duke@0 580
duke@0 581 // Unless overridden, modifier_flags is 0.
duke@0 582 jint Klass::compute_modifier_flags(TRAPS) const {
duke@0 583 return 0;
duke@0 584 }
duke@0 585
duke@0 586 int Klass::atomic_incr_biased_lock_revocation_count() {
duke@0 587 return (int) Atomic::add(1, &_biased_lock_revocation_count);
duke@0 588 }
duke@0 589
duke@0 590 // Unless overridden, jvmti_class_status has no flags set.
duke@0 591 jint Klass::jvmti_class_status() const {
duke@0 592 return 0;
duke@0 593 }
duke@0 594
coleenp@3602 595
duke@0 596 // Printing
duke@0 597
coleenp@3602 598 void Klass::print_on(outputStream* st) const {
coleenp@3602 599 ResourceMark rm;
coleenp@3602 600 // print title
coleenp@3602 601 st->print("%s", internal_name());
coleenp@3602 602 print_address_on(st);
coleenp@3602 603 st->cr();
coleenp@3602 604 }
coleenp@3602 605
duke@0 606 void Klass::oop_print_on(oop obj, outputStream* st) {
duke@0 607 ResourceMark rm;
duke@0 608 // print title
duke@0 609 st->print_cr("%s ", internal_name());
duke@0 610 obj->print_address_on(st);
duke@0 611
duke@0 612 if (WizardMode) {
duke@0 613 // print header
duke@0 614 obj->mark()->print_on(st);
duke@0 615 }
duke@0 616
duke@0 617 // print class
duke@0 618 st->print(" - klass: ");
duke@0 619 obj->klass()->print_value_on(st);
duke@0 620 st->cr();
duke@0 621 }
duke@0 622
duke@0 623 void Klass::oop_print_value_on(oop obj, outputStream* st) {
duke@0 624 // print title
duke@0 625 ResourceMark rm; // Cannot print in debug mode without this
duke@0 626 st->print("%s", internal_name());
duke@0 627 obj->print_address_on(st);
duke@0 628 }
duke@0 629
coleenp@3602 630
duke@0 631 // Verification
duke@0 632
coleenp@3602 633 void Klass::verify_on(outputStream* st) {
coleenp@3602 634 guarantee(!Universe::heap()->is_in_reserved(this), "Shouldn't be");
coleenp@3602 635 guarantee(this->is_metadata(), "should be in metaspace");
coleenp@3602 636
coleenp@3602 637 assert(ClassLoaderDataGraph::contains((address)this), "Should be");
coleenp@3602 638
coleenp@3602 639 guarantee(this->is_klass(),"should be klass");
coleenp@3602 640
coleenp@3602 641 if (super() != NULL) {
coleenp@3602 642 guarantee(super()->is_metadata(), "should be in metaspace");
coleenp@3602 643 guarantee(super()->is_klass(), "should be klass");
coleenp@3602 644 }
coleenp@3602 645 if (secondary_super_cache() != NULL) {
coleenp@3602 646 Klass* ko = secondary_super_cache();
coleenp@3602 647 guarantee(ko->is_metadata(), "should be in metaspace");
coleenp@3602 648 guarantee(ko->is_klass(), "should be klass");
coleenp@3602 649 }
coleenp@3602 650 for ( uint i = 0; i < primary_super_limit(); i++ ) {
coleenp@3602 651 Klass* ko = _primary_supers[i];
coleenp@3602 652 if (ko != NULL) {
coleenp@3602 653 guarantee(ko->is_metadata(), "should be in metaspace");
coleenp@3602 654 guarantee(ko->is_klass(), "should be klass");
coleenp@3602 655 }
coleenp@3602 656 }
coleenp@3602 657
coleenp@3602 658 if (java_mirror() != NULL) {
coleenp@3602 659 guarantee(java_mirror()->is_oop(), "should be instance");
coleenp@3602 660 }
coleenp@3602 661 }
coleenp@3602 662
duke@0 663 void Klass::oop_verify_on(oop obj, outputStream* st) {
duke@0 664 guarantee(obj->is_oop(), "should be oop");
coleenp@3602 665 guarantee(obj->klass()->is_metadata(), "should not be in Java heap");
duke@0 666 guarantee(obj->klass()->is_klass(), "klass field is not a klass");
duke@0 667 }
duke@0 668
duke@0 669 #ifndef PRODUCT
duke@0 670
duke@0 671 void Klass::verify_vtable_index(int i) {
duke@0 672 if (oop_is_instance()) {
coleenp@3602 673 assert(i>=0 && i<((InstanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
duke@0 674 } else {
coleenp@3602 675 assert(oop_is_array(), "Must be");
coleenp@3707 676 assert(i>=0 && i<((ArrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
duke@0 677 }
duke@0 678 }
duke@0 679
duke@0 680 #endif