comparison src/share/vm/classfile/classLoaderData.cpp @ 14909:4ca6dc0799b6

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