int klassKlass::oop_oop_iterate(oop obj, OopClosure* blk) { // Get size before changing pointers int size = oop_size(obj); Klass* k = Klass::cast(klassOop(obj)); blk->do_oop(k->adr_super()); for (juint i = 0; i < Klass::primary_super_limit(); i++) blk->do_oop(k->adr_primary_supers()+i); blk->do_oop(k->adr_secondary_super_cache()); blk->do_oop(k->adr_secondary_supers()); blk->do_oop(k->adr_java_mirror()); blk->do_oop(k->adr_name()); // The following are in the perm gen and are treated // specially in a later phase of a perm gen collection; ... assert(oop(k)->is_perm(), "should be in perm"); assert(oop(k->subklass())->is_perm_or_null(), "should be in perm"); assert(oop(k->next_sibling())->is_perm_or_null(), "should be in perm"); // ... don't scan them normally, but remember this klassKlass // for later (see, for instance, oop_follow_contents above // for what MarkSweep does with it. if (blk->should_remember_klasses()) { blk->remember_klass(k); } obj->oop_iterate_header(blk); return size; }
// 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 }
void CHA::process_interface(instanceKlassHandle r, GrowableArray<KlassHandle>* receivers, GrowableArray<methodHandle>* methods, symbolHandle name, symbolHandle signature) { // recursively add non-abstract implementors of interface r to receivers list assert(r->is_interface(), "should call process_class instead"); // We only store the implementors for an interface, if there is exactly one implementor klassOop k = r->implementor(); assert(k == NULL || r->nof_implementors() == 1, "inconsistent implementor list"); if (k != NULL && !methods->is_full()) { instanceKlass* kl = instanceKlass::cast(k); assert(kl->oop_is_instance(), "primitive klasses don't implement interfaces"); assert(!kl->is_interface(), "must be a real klass"); process_class(kl, receivers, methods, name, signature); } // now process all subinterfaces for (Klass* s = r->subklass(); s != NULL && !methods->is_full(); s = s->next_sibling()) { assert(s->is_interface(), "must be an interface"); instanceKlassHandle sub(s->as_klassOop()); process_interface(sub, receivers, methods, name, signature); if (methods->is_full()) break; // give up -- too many overriding methods } }
void CHA::process_class(KlassHandle r, GrowableArray<KlassHandle>* receivers, GrowableArray<methodHandle>* methods, symbolHandle name, symbolHandle signature) { // recursively add non-abstract subclasses of r to receivers list assert(!r->is_interface(), "should call process_interface instead"); for (Klass* s = r->subklass(); s != NULL && !methods->is_full(); s = s->next_sibling()) { // preorder traversal, so check subclasses first if (s->is_interface()) { // can only happen if r == Object assert(r->superklass() == NULL, "must be klass Object"); } else { process_class(s, receivers, methods, name, signature); } } // now check r itself (after subclasses because of preorder) if (!methods->is_full()) { // don't add abstract classes to receivers list // (but still consider their methods -- they may be non-abstract) if (!receivers->is_full() && !r->is_abstract()) receivers->push(r); methodOop m = NULL; if (r->oop_is_instance()) m = instanceKlass::cast(r())->find_method(name(), signature()); if (m != NULL && !m->is_abstract()) { if (!methods->contains(m)) methods->push(m); } } }
void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) { klassKlass::oop_verify_on(obj, st); if (!obj->partially_loaded()) { Thread *thread = Thread::current(); instanceKlass* ik = instanceKlass::cast(klassOop(obj)); // Avoid redundant verifies if (ik->_verify_count == Universe::verify_count()) return; ik->_verify_count = Universe::verify_count(); // Verify that klass is present in SystemDictionary if (ik->is_loaded()) { symbolHandle h_name (thread, ik->name()); Handle h_loader (thread, ik->class_loader()); SystemDictionary::verify_obj_klass_present(obj, h_name, h_loader); } // Verify static fields VerifyFieldClosure blk; ik->iterate_static_fields(&blk); // Verify vtables if (ik->is_linked()) { ResourceMark rm(thread); // $$$ This used to be done only for m/s collections. Doing it // always seemed a valid generalization. (DLD -- 6/00) ik->vtable()->verify(st); } // Verify oop map cache if (ik->oop_map_cache() != NULL) { ik->oop_map_cache()->verify(); } // Verify first subklass if (ik->subklass_oop() != NULL) { guarantee(ik->subklass_oop()->is_perm(), "should be in permspace"); guarantee(ik->subklass_oop()->is_klass(), "should be klass"); } // Verify siblings klassOop super = ik->super(); Klass* sib = ik->next_sibling(); int sib_count = 0; while (sib != NULL) { if (sib == ik) { fatal1("subclass cycle of length %d", sib_count); } if (sib_count >= 100000) { fatal1("suspiciously long subclass list %d", sib_count); } guarantee(sib->as_klassOop()->is_klass(), "should be klass"); guarantee(sib->as_klassOop()->is_perm(), "should be in permspace"); guarantee(sib->super() == super, "siblings should have same superklass"); sib = sib->next_sibling(); } // Verify implementor field if (ik->implementor() != NULL) { guarantee(ik->is_interface(), "only interfaces should have implementor set"); guarantee(ik->nof_implementors() == 1, "should only have one implementor"); klassOop im = ik->implementor(); guarantee(im->is_perm(), "should be in permspace"); guarantee(im->is_klass(), "should be klass"); guarantee(!Klass::cast(klassOop(im))->is_interface(), "implementors cannot be interfaces"); } // Verify local interfaces objArrayOop local_interfaces = ik->local_interfaces(); guarantee(local_interfaces->is_perm(), "should be in permspace"); guarantee(local_interfaces->is_objArray(), "should be obj array"); int j; for (j = 0; j < local_interfaces->length(); j++) { oop e = local_interfaces->obj_at(j); guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid local interface"); } // Verify transitive interfaces objArrayOop transitive_interfaces = ik->transitive_interfaces(); guarantee(transitive_interfaces->is_perm(), "should be in permspace"); guarantee(transitive_interfaces->is_objArray(), "should be obj array"); for (j = 0; j < transitive_interfaces->length(); j++) { oop e = transitive_interfaces->obj_at(j); guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid transitive interface"); } // Verify methods objArrayOop methods = ik->methods(); guarantee(methods->is_perm(), "should be in permspace"); guarantee(methods->is_objArray(), "should be obj array"); for (j = 0; j < methods->length(); j++) { guarantee(methods->obj_at(j)->is_method(), "non-method in methods array"); } for (j = 0; j < methods->length() - 1; j++) { methodOop m1 = methodOop(methods->obj_at(j)); methodOop m2 = methodOop(methods->obj_at(j + 1)); guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly"); } // Verify method ordering typeArrayOop method_ordering = ik->method_ordering(); guarantee(method_ordering->is_perm(), "should be in permspace"); guarantee(method_ordering->is_typeArray(), "should be type array"); int length = method_ordering->length(); if (jvmdi::enabled()) { guarantee(length == methods->length(), "invalid method ordering length"); jlong sum = 0; for (j = 0; j < length; j++) { int original_index = method_ordering->int_at(j); guarantee(original_index >= 0 && original_index < length, "invalid method ordering index"); sum += original_index; } // Verify sum of indices 0,1,...,length-1 guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum"); } else { guarantee(length == 0, "invalid method ordering length"); } // Verify JNI static field/method identifiers if (ik->jni_ids() != NULL) { ik->jni_ids()->verify(ik->as_klassOop()); } // Verify other fields if (ik->array_klasses() != NULL) { guarantee(ik->array_klasses()->is_perm(), "should be in permspace"); guarantee(ik->array_klasses()->is_klass(), "should be klass"); } guarantee(ik->fields()->is_perm(), "should be in permspace"); guarantee(ik->fields()->is_typeArray(), "should be type array"); guarantee(ik->constants()->is_perm(), "should be in permspace"); guarantee(ik->constants()->is_constantPool(), "should be constant pool"); guarantee(ik->inner_classes()->is_perm(), "should be in permspace"); guarantee(ik->inner_classes()->is_typeArray(), "should be type array"); if (ik->source_file_name() != NULL) { guarantee(ik->source_file_name()->is_perm(), "should be in permspace"); guarantee(ik->source_file_name()->is_symbol(), "should be symbol"); } if (ik->source_debug_extension() != NULL) { guarantee(ik->source_debug_extension()->is_perm(), "should be in permspace"); guarantee(ik->source_debug_extension()->is_symbol(), "should be symbol"); } if (ik->protection_domain() != NULL) { guarantee(ik->protection_domain()->is_oop(), "should be oop"); } if (ik->signers() != NULL) { guarantee(ik->signers()->is_objArray(), "should be obj array"); } } }
void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) { assert(obj->is_klass(), "must be klass"); instanceKlass* ik = instanceKlass::cast(klassOop(obj)); klassKlass::oop_print_on(obj, st); st->print(" - instance size: %d", ik->size_helper()); st->cr(); st->print(" - klass size: %d", ik->object_size()); st->cr(); st->print(" - access: "); ik->access_flags().print_on(st); st->cr(); st->print(" - state: "); st->print_cr(state_names[ik->_init_state]); st->print(" - name: "); ik->name()->print_value_on(st); st->cr(); st->print(" - super: "); ik->super()->print_value_on(st); st->cr(); st->print(" - sub: "); Klass* sub = ik->subklass(); int n; for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) { if (n < MaxSubklassPrintSize) { sub->as_klassOop()->print_value_on(st); st->print(" "); } } if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize); st->cr(); if (ik->is_interface()) { st->print_cr(" - nof implementors: %d", ik->nof_implementors()); if (ik->nof_implementors() == 1) { st->print_cr(" - implementor: "); ik->implementor()->print_value_on(st);st->cr(); } } st->print(" - arrays: "); ik->array_klasses()->print_value_on(st); st->cr(); st->print(" - methods: "); ik->methods()->print_value_on(st); st->cr(); if (Verbose) { objArrayOop methods = ik->methods(); for(int i = 0; i < methods->length(); i++) { tty->print("%d : ", i); methods->obj_at(i)->print_value(); tty->cr(); } } st->print(" - method ordering: "); ik->method_ordering()->print_value_on(st); st->cr(); st->print(" - local interfaces: "); ik->local_interfaces()->print_value_on(st); st->cr(); st->print(" - trans. interfaces: "); ik->transitive_interfaces()->print_value_on(st); st->cr(); st->print(" - constants: "); ik->constants()->print_value_on(st); st->cr(); st->print(" - class loader: "); ik->class_loader()->print_value_on(st); st->cr(); st->print(" - protection domain: "); ik->protection_domain()->print_value_on(st); st->cr(); st->print(" - signers: "); ik->signers()->print_value_on(st); st->cr(); if (ik->source_file_name() != NULL) { st->print(" - source file: "); ik->source_file_name()->print_value_on(st); st->cr(); } if (ik->source_debug_extension() != NULL) { st->print(" - source debug extension: "); ik->source_debug_extension()->print_value_on(st); st->cr(); } if (ik->has_previous_version()) { st->print_cr(" - previous version: "); ik->previous_version()->print_value_on(st); st->cr(); } st->print(" - inner classes: "); ik->inner_classes()->print_value_on(st); st->cr(); st->print(" - java mirror: "); ik->java_mirror()->print_value_on(st); st->cr(); st->print(" - vtable length %d (start addr: " INTPTR_FORMAT ")", ik->vtable_length(), ik->start_of_vtable()); st->cr(); st->print(" - itable length %d (start addr: " INTPTR_FORMAT ")", ik->itable_length(), ik->start_of_itable()); st->cr(); st->print_cr(" - static fields:"); printing_stream = st; ik->do_local_static_fields(print_static_field, obj); st->print_cr(" - non-static fields:"); ik->do_nonstatic_fields(print_nonstatic_field, NULL); printing_stream = NULL; st->print(" - static oop maps: "); if (ik->static_oop_field_size() > 0) { int first_offset = ik->offset_of_static_fields(); st->print("%d-%d", first_offset, first_offset + ik->static_oop_field_size() - 1); } st->cr(); st->print(" - non-static oop maps: "); OopMapBlock* map = ik->start_of_nonstatic_oop_maps(); OopMapBlock* end_map = map + ik->nonstatic_oop_map_size(); while (map < end_map) { st->print("%d-%d ", map->offset(), map->offset() + map->length() - 1); map++; } st->cr(); }
void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) { assert(obj->is_klass(), "must be klass"); instanceKlass* ik = instanceKlass::cast(klassOop(obj)); klassKlass::oop_print_on(obj, st); st->print(BULLET"instance size: %d", ik->size_helper()); st->cr(); st->print(BULLET"klass size: %d", ik->object_size()); st->cr(); st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr(); st->print(BULLET"state: "); st->print_cr(state_names[ik->_init_state]); st->print(BULLET"name: "); ik->name()->print_value_on(st); st->cr(); st->print(BULLET"super: "); ik->super()->print_value_on(st); st->cr(); st->print(BULLET"sub: "); Klass* sub = ik->subklass(); int n; for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) { if (n < MaxSubklassPrintSize) { sub->as_klassOop()->print_value_on(st); st->print(" "); } } if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize); st->cr(); if (ik->is_interface()) { st->print_cr(BULLET"nof implementors: %d", ik->nof_implementors()); if (ik->nof_implementors() == 1) { st->print_cr(BULLET"implementor: "); st->print(" "); ik->implementor()->print_value_on(st); st->cr(); } } st->print(BULLET"arrays: "); ik->array_klasses()->print_value_on(st); st->cr(); st->print(BULLET"methods: "); ik->methods()->print_value_on(st); st->cr(); if (Verbose) { objArrayOop methods = ik->methods(); for(int i = 0; i < methods->length(); i++) { tty->print("%d : ", i); methods->obj_at(i)->print_value(); tty->cr(); } } st->print(BULLET"method ordering: "); ik->method_ordering()->print_value_on(st); st->cr(); st->print(BULLET"local interfaces: "); ik->local_interfaces()->print_value_on(st); st->cr(); st->print(BULLET"trans. interfaces: "); ik->transitive_interfaces()->print_value_on(st); st->cr(); st->print(BULLET"constants: "); ik->constants()->print_value_on(st); st->cr(); st->print(BULLET"class loader: "); ik->class_loader()->print_value_on(st); st->cr(); st->print(BULLET"protection domain: "); ik->protection_domain()->print_value_on(st); st->cr(); if (ik->host_klass() != NULL) { st->print(BULLET"host class: "); ik->host_klass()->print_value_on(st); st->cr(); } st->print(BULLET"signers: "); ik->signers()->print_value_on(st); st->cr(); if (ik->source_file_name() != NULL) { st->print(BULLET"source file: "); ik->source_file_name()->print_value_on(st); st->cr(); } if (ik->source_debug_extension() != NULL) { st->print(BULLET"source debug extension: "); st->print_cr("%s", ik->source_debug_extension()); st->cr(); } { ResourceMark rm; // PreviousVersionInfo objects returned via PreviousVersionWalker // contain a GrowableArray of handles. We have to clean up the // GrowableArray _after_ the PreviousVersionWalker destructor // has destroyed the handles. { bool have_pv = false; PreviousVersionWalker pvw(ik); for (PreviousVersionInfo * pv_info = pvw.next_previous_version(); pv_info != NULL; pv_info = pvw.next_previous_version()) { if (!have_pv) st->print(BULLET"previous version: "); have_pv = true; pv_info->prev_constant_pool_handle()()->print_value_on(st); } if (have_pv) st->cr(); } // pvw is cleaned up } // rm is cleaned up if (ik->generic_signature() != NULL) { st->print(BULLET"generic signature: "); ik->generic_signature()->print_value_on(st); st->cr(); } st->print(BULLET"inner classes: "); ik->inner_classes()->print_value_on(st); st->cr(); st->print(BULLET"java mirror: "); ik->java_mirror()->print_value_on(st); st->cr(); st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", ik->vtable_length(), ik->start_of_vtable()); st->cr(); st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", ik->itable_length(), ik->start_of_itable()); st->cr(); st->print_cr(BULLET"---- static fields (%d words):", ik->static_field_size()); FieldPrinter print_static_field(st); ik->do_local_static_fields(&print_static_field); st->print_cr(BULLET"---- non-static fields (%d words):", ik->nonstatic_field_size()); FieldPrinter print_nonstatic_field(st); ik->do_nonstatic_fields(&print_nonstatic_field); st->print(BULLET"non-static oop maps: "); OopMapBlock* map = ik->start_of_nonstatic_oop_maps(); OopMapBlock* end_map = map + ik->nonstatic_oop_map_count(); while (map < end_map) { st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1)); map++; } st->cr(); }