annotate src/share/vm/oops/klass.cpp @ 5645:fce21ac5968d

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