comparison src/share/vm/classfile/classLoaderData.cpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents 4ca6dc0799b6 e4a6e7f1b90b
children 7848fc12602b
comparison
equal deleted inserted replaced
17606:45d7b2c7029d 18041:52b4284cb496
1 /* 1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
267 267
268 if (TraceClassLoaderData && Verbose && k->class_loader_data() != NULL) { 268 if (TraceClassLoaderData && Verbose && k->class_loader_data() != NULL) {
269 ResourceMark rm; 269 ResourceMark rm;
270 tty->print_cr("[TraceClassLoaderData] Adding k: " PTR_FORMAT " %s to CLD: " 270 tty->print_cr("[TraceClassLoaderData] Adding k: " PTR_FORMAT " %s to CLD: "
271 PTR_FORMAT " loader: " PTR_FORMAT " %s", 271 PTR_FORMAT " loader: " PTR_FORMAT " %s",
272 k, 272 p2i(k),
273 k->external_name(), 273 k->external_name(),
274 k->class_loader_data(), 274 p2i(k->class_loader_data()),
275 (void *)k->class_loader(), 275 p2i((void *)k->class_loader()),
276 loader_name()); 276 loader_name());
277 } 277 }
278 } 278 }
279 279
280 // This is called by InstanceKlass::deallocate_contents() to remove the 280 // This is called by InstanceKlass::deallocate_contents() to remove the
305 // Tell serviceability tools these classes are unloading 305 // Tell serviceability tools these classes are unloading
306 classes_do(InstanceKlass::notify_unload_class); 306 classes_do(InstanceKlass::notify_unload_class);
307 307
308 if (TraceClassLoaderData) { 308 if (TraceClassLoaderData) {
309 ResourceMark rm; 309 ResourceMark rm;
310 tty->print("[ClassLoaderData: unload loader data "PTR_FORMAT, this); 310 tty->print("[ClassLoaderData: unload loader data " INTPTR_FORMAT, p2i(this));
311 tty->print(" for instance "PTR_FORMAT" of %s", (void *)class_loader(), 311 tty->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)class_loader()),
312 loader_name()); 312 loader_name());
313 if (is_anonymous()) { 313 if (is_anonymous()) {
314 tty->print(" for anonymous class "PTR_FORMAT " ", _klasses); 314 tty->print(" for anonymous class " INTPTR_FORMAT " ", p2i(_klasses));
315 } 315 }
316 tty->print_cr("]"); 316 tty->print_cr("]");
317 } 317 }
318 } 318 }
319 319
467 #undef CLD_DUMP_KLASSES 467 #undef CLD_DUMP_KLASSES
468 468
469 void ClassLoaderData::dump(outputStream * const out) { 469 void ClassLoaderData::dump(outputStream * const out) {
470 ResourceMark rm; 470 ResourceMark rm;
471 out->print("ClassLoaderData CLD: "PTR_FORMAT", loader: "PTR_FORMAT", loader_klass: "PTR_FORMAT" %s {", 471 out->print("ClassLoaderData CLD: "PTR_FORMAT", loader: "PTR_FORMAT", loader_klass: "PTR_FORMAT" %s {",
472 this, (void *)class_loader(), 472 p2i(this), p2i((void *)class_loader()),
473 class_loader() != NULL ? class_loader()->klass() : NULL, loader_name()); 473 p2i(class_loader() != NULL ? class_loader()->klass() : NULL), loader_name());
474 if (claimed()) out->print(" claimed "); 474 if (claimed()) out->print(" claimed ");
475 if (is_unloading()) out->print(" unloading "); 475 if (is_unloading()) out->print(" unloading ");
476 out->print(" handles " INTPTR_FORMAT, handles()); 476 out->print(" handles " INTPTR_FORMAT, p2i(handles()));
477 out->cr(); 477 out->cr();
478 if (metaspace_or_null() != NULL) { 478 if (metaspace_or_null() != NULL) {
479 out->print_cr("metaspace: " PTR_FORMAT, metaspace_or_null()); 479 out->print_cr("metaspace: " INTPTR_FORMAT, p2i(metaspace_or_null()));
480 metaspace_or_null()->dump(out); 480 metaspace_or_null()->dump(out);
481 } else { 481 } else {
482 out->print_cr("metaspace: NULL"); 482 out->print_cr("metaspace: NULL");
483 } 483 }
484 484
518 k->verify(); 518 k->verify();
519 assert(k != k->next_link(), "no loops!"); 519 assert(k != k->next_link(), "no loops!");
520 } 520 }
521 } 521 }
522 522
523 bool ClassLoaderData::contains_klass(Klass* klass) {
524 for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
525 if (k == klass) return true;
526 }
527 return false;
528 }
529
523 530
524 // GC root of class loader data created. 531 // GC root of class loader data created.
525 ClassLoaderData* ClassLoaderDataGraph::_head = NULL; 532 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
526 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL; 533 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
534 ClassLoaderData* ClassLoaderDataGraph::_saved_unloading = NULL;
527 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL; 535 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
536
537 bool ClassLoaderDataGraph::_should_purge = false;
528 538
529 // Add a new class loader data node to the list. Assign the newly created 539 // Add a new class loader data node to the list. Assign the newly created
530 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field 540 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
531 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) { 541 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) {
532 // We need to allocate all the oops for the ClassLoaderData before allocating the 542 // We need to allocate all the oops for the ClassLoaderData before allocating the
561 ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next); 571 ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next);
562 if (exchanged == next) { 572 if (exchanged == next) {
563 if (TraceClassLoaderData) { 573 if (TraceClassLoaderData) {
564 ResourceMark rm; 574 ResourceMark rm;
565 tty->print("[ClassLoaderData: "); 575 tty->print("[ClassLoaderData: ");
566 tty->print("create class loader data "PTR_FORMAT, cld); 576 tty->print("create class loader data " INTPTR_FORMAT, p2i(cld));
567 tty->print(" for instance "PTR_FORMAT" of %s", (void *)cld->class_loader(), 577 tty->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)cld->class_loader()),
568 cld->loader_name()); 578 cld->loader_name());
569 tty->print_cr("]"); 579 tty->print_cr("]");
570 } 580 }
571 return cld; 581 return cld;
572 } 582 }
617 } 627 }
618 } 628 }
619 629
620 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) { 630 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
621 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); 631 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
622 for (ClassLoaderData* cld = _unloading; cld != NULL; cld = cld->next()) { 632 // Only walk the head until any clds not purged from prior unloading
633 // (CMS doesn't purge right away).
634 for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
623 cld->classes_do(f); 635 cld->classes_do(f);
624 } 636 }
625 } 637 }
626 638
627 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() { 639 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
647 659
648 return array; 660 return array;
649 } 661 }
650 662
651 #ifndef PRODUCT 663 #ifndef PRODUCT
652 // for debugging and hsfind(x)
653 bool ClassLoaderDataGraph::contains(address x) {
654 // I think we need the _metaspace_lock taken here because the class loader
655 // data graph could be changing while we are walking it (new entries added,
656 // new entries being unloaded, etc).
657 if (DumpSharedSpaces) {
658 // There are only two metaspaces to worry about.
659 ClassLoaderData* ncld = ClassLoaderData::the_null_class_loader_data();
660 return (ncld->ro_metaspace()->contains(x) || ncld->rw_metaspace()->contains(x));
661 }
662
663 if (UseSharedSpaces && MetaspaceShared::is_in_shared_space(x)) {
664 return true;
665 }
666
667 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
668 if (cld->metaspace_or_null() != NULL && cld->metaspace_or_null()->contains(x)) {
669 return true;
670 }
671 }
672
673 // Could also be on an unloading list which is okay, ie. still allocated
674 // for a little while.
675 for (ClassLoaderData* ucld = _unloading; ucld != NULL; ucld = ucld->next()) {
676 if (ucld->metaspace_or_null() != NULL && ucld->metaspace_or_null()->contains(x)) {
677 return true;
678 }
679 }
680 return false;
681 }
682
683 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) { 664 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
684 for (ClassLoaderData* data = _head; data != NULL; data = data->next()) { 665 for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
685 if (loader_data == data) { 666 if (loader_data == data) {
686 return true; 667 return true;
687 } 668 }
696 // and deallocation later. 677 // and deallocation later.
697 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure) { 678 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure) {
698 ClassLoaderData* data = _head; 679 ClassLoaderData* data = _head;
699 ClassLoaderData* prev = NULL; 680 ClassLoaderData* prev = NULL;
700 bool seen_dead_loader = false; 681 bool seen_dead_loader = false;
682
683 // Save previous _unloading pointer for CMS which may add to unloading list before
684 // purging and we don't want to rewalk the previously unloaded class loader data.
685 _saved_unloading = _unloading;
686
701 // mark metadata seen on the stack and code cache so we can delete 687 // mark metadata seen on the stack and code cache so we can delete
702 // unneeded entries. 688 // unneeded entries.
703 bool has_redefined_a_class = JvmtiExport::has_redefined_a_class(); 689 bool has_redefined_a_class = JvmtiExport::has_redefined_a_class();
704 MetadataOnStackMark md_on_stack; 690 MetadataOnStackMark md_on_stack;
705 while (data != NULL) { 691 while (data != NULL) {
735 721
736 return seen_dead_loader; 722 return seen_dead_loader;
737 } 723 }
738 724
739 void ClassLoaderDataGraph::purge() { 725 void ClassLoaderDataGraph::purge() {
726 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
740 ClassLoaderData* list = _unloading; 727 ClassLoaderData* list = _unloading;
741 _unloading = NULL; 728 _unloading = NULL;
742 ClassLoaderData* next = list; 729 ClassLoaderData* next = list;
743 while (next != NULL) { 730 while (next != NULL) {
744 ClassLoaderData* purge_me = next; 731 ClassLoaderData* purge_me = next;
823 810
824 void ClassLoaderData::print_value_on(outputStream* out) const { 811 void ClassLoaderData::print_value_on(outputStream* out) const {
825 if (class_loader() == NULL) { 812 if (class_loader() == NULL) {
826 out->print("NULL class_loader"); 813 out->print("NULL class_loader");
827 } else { 814 } else {
828 out->print("class loader "PTR_FORMAT, this); 815 out->print("class loader " INTPTR_FORMAT, p2i(this));
829 class_loader()->print_value_on(out); 816 class_loader()->print_value_on(out);
830 } 817 }
831 } 818 }
832 819
833 #if INCLUDE_TRACE 820 #if INCLUDE_TRACE