comparison src/share/vm/classfile/classLoaderData.cpp @ 14518:d8041d695d19

Merged with jdk9/dev/hotspot changeset 3812c088b945
author twisti
date Tue, 11 Mar 2014 18:45:59 -0700
parents f460c6926af7
children 4ca6dc0799b6
comparison
equal deleted inserted replaced
14141:f97c5ec83832 14518:d8041d695d19
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.
71 71
72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; 72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
73 73
74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) : 74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
75 _class_loader(h_class_loader()), 75 _class_loader(h_class_loader()),
76 _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially 76 _is_anonymous(is_anonymous),
77 // An anonymous class loader data doesn't have anything to keep
78 // it from being unloaded during parsing of the anonymous class.
79 // The null-class-loader should always be kept alive.
80 _keep_alive(is_anonymous || h_class_loader.is_null()),
77 _metaspace(NULL), _unloading(false), _klasses(NULL), 81 _metaspace(NULL), _unloading(false), _klasses(NULL),
78 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), 82 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
79 _next(NULL), _dependencies(dependencies), 83 _next(NULL), _dependencies(dependencies),
80 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { 84 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
81 // empty 85 // empty
315 } 319 }
316 tty->print_cr("]"); 320 tty->print_cr("]");
317 } 321 }
318 } 322 }
319 323
324 oop ClassLoaderData::keep_alive_object() const {
325 assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
326 return is_anonymous() ? _klasses->java_mirror() : class_loader();
327 }
328
320 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const { 329 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
321 bool alive = 330 bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
322 is_anonymous() ? 331 || is_alive_closure->do_object_b(keep_alive_object());
323 is_alive_closure->do_object_b(_klasses->java_mirror()) : 332
324 class_loader() == NULL || is_alive_closure->do_object_b(class_loader());
325 assert(!alive || claimed(), "must be claimed"); 333 assert(!alive || claimed(), "must be claimed");
326 return alive; 334 return alive;
327 } 335 }
328 336
329 337
518 k->verify(); 526 k->verify();
519 assert(k != k->next_link(), "no loops!"); 527 assert(k != k->next_link(), "no loops!");
520 } 528 }
521 } 529 }
522 530
531 bool ClassLoaderData::contains_klass(Klass* klass) {
532 for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
533 if (k == klass) return true;
534 }
535 return false;
536 }
537
523 538
524 // GC root of class loader data created. 539 // GC root of class loader data created.
525 ClassLoaderData* ClassLoaderDataGraph::_head = NULL; 540 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
526 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL; 541 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
527 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL; 542 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
589 } 604 }
590 } 605 }
591 606
592 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) { 607 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
593 if (ClassUnloading) { 608 if (ClassUnloading) {
594 ClassLoaderData::the_null_class_loader_data()->oops_do(f, klass_closure, must_claim);
595 // keep any special CLDs alive.
596 ClassLoaderDataGraph::keep_alive_oops_do(f, klass_closure, must_claim); 609 ClassLoaderDataGraph::keep_alive_oops_do(f, klass_closure, must_claim);
597 } else { 610 } else {
598 ClassLoaderDataGraph::oops_do(f, klass_closure, must_claim); 611 ClassLoaderDataGraph::oops_do(f, klass_closure, must_claim);
599 } 612 }
600 } 613 }
646 } 659 }
647 660
648 return array; 661 return array;
649 } 662 }
650 663
651 #ifndef PRODUCT 664 // For profiling and hsfind() only. Otherwise, this is unsafe (and slow). This
652 // for debugging and hsfind(x) 665 // is done lock free to avoid lock inversion problems. It is safe because
653 bool ClassLoaderDataGraph::contains(address x) { 666 // new ClassLoaderData are added to the end of the CLDG, and only removed at
654 // I think we need the _metaspace_lock taken here because the class loader 667 // safepoint. The _unloading list can be deallocated concurrently with CMS so
655 // data graph could be changing while we are walking it (new entries added, 668 // this doesn't look in metaspace for classes that have been unloaded.
656 // new entries being unloaded, etc). 669 bool ClassLoaderDataGraph::contains(const void* x) {
657 if (DumpSharedSpaces) { 670 if (DumpSharedSpaces) {
658 // There are only two metaspaces to worry about. 671 // There are only two metaspaces to worry about.
659 ClassLoaderData* ncld = ClassLoaderData::the_null_class_loader_data(); 672 ClassLoaderData* ncld = ClassLoaderData::the_null_class_loader_data();
660 return (ncld->ro_metaspace()->contains(x) || ncld->rw_metaspace()->contains(x)); 673 return (ncld->ro_metaspace()->contains(x) || ncld->rw_metaspace()->contains(x));
661 } 674 }
668 if (cld->metaspace_or_null() != NULL && cld->metaspace_or_null()->contains(x)) { 681 if (cld->metaspace_or_null() != NULL && cld->metaspace_or_null()->contains(x)) {
669 return true; 682 return true;
670 } 683 }
671 } 684 }
672 685
673 // Could also be on an unloading list which is okay, ie. still allocated 686 // Do not check unloading list because deallocation can be concurrent.
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; 687 return false;
681 } 688 }
682 689
690 #ifndef PRODUCT
683 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) { 691 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
684 for (ClassLoaderData* data = _head; data != NULL; data = data->next()) { 692 for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
685 if (loader_data == data) { 693 if (loader_data == data) {
686 return true; 694 return true;
687 } 695 }
701 // mark metadata seen on the stack and code cache so we can delete 709 // mark metadata seen on the stack and code cache so we can delete
702 // unneeded entries. 710 // unneeded entries.
703 bool has_redefined_a_class = JvmtiExport::has_redefined_a_class(); 711 bool has_redefined_a_class = JvmtiExport::has_redefined_a_class();
704 MetadataOnStackMark md_on_stack; 712 MetadataOnStackMark md_on_stack;
705 while (data != NULL) { 713 while (data != NULL) {
706 if (data->keep_alive() || data->is_alive(is_alive_closure)) { 714 if (data->is_alive(is_alive_closure)) {
707 if (has_redefined_a_class) { 715 if (has_redefined_a_class) {
708 data->classes_do(InstanceKlass::purge_previous_versions); 716 data->classes_do(InstanceKlass::purge_previous_versions);
709 } 717 }
710 data->free_deallocate_list(); 718 data->free_deallocate_list();
711 prev = data; 719 prev = data;