src/share/vm/classfile/classLoaderData.cpp

changeset 6974
556a06aec3fa
parent 6742
e4a6e7f1b90b
child 6992
2c6ef90f030a
     1.1 --- a/src/share/vm/classfile/classLoaderData.cpp	Fri Feb 21 10:01:20 2014 +0100
     1.2 +++ b/src/share/vm/classfile/classLoaderData.cpp	Fri Feb 21 10:19:09 2014 +0100
     1.3 @@ -73,7 +73,11 @@
     1.4  
     1.5  ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
     1.6    _class_loader(h_class_loader()),
     1.7 -  _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially
     1.8 +  _is_anonymous(is_anonymous),
     1.9 +  // An anonymous class loader data doesn't have anything to keep
    1.10 +  // it from being unloaded during parsing of the anonymous class.
    1.11 +  // The null-class-loader should always be kept alive.
    1.12 +  _keep_alive(is_anonymous || h_class_loader.is_null()),
    1.13    _metaspace(NULL), _unloading(false), _klasses(NULL),
    1.14    _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
    1.15    _next(NULL), _dependencies(dependencies),
    1.16 @@ -317,11 +321,15 @@
    1.17    }
    1.18  }
    1.19  
    1.20 +oop ClassLoaderData::keep_alive_object() const {
    1.21 +  assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
    1.22 +  return is_anonymous() ? _klasses->java_mirror() : class_loader();
    1.23 +}
    1.24 +
    1.25  bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
    1.26 -  bool alive =
    1.27 -    is_anonymous() ?
    1.28 -       is_alive_closure->do_object_b(_klasses->java_mirror()) :
    1.29 -       class_loader() == NULL || is_alive_closure->do_object_b(class_loader());
    1.30 +  bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
    1.31 +      || is_alive_closure->do_object_b(keep_alive_object());
    1.32 +
    1.33    assert(!alive || claimed(), "must be claimed");
    1.34    return alive;
    1.35  }
    1.36 @@ -601,8 +609,6 @@
    1.37  
    1.38  void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
    1.39    if (ClassUnloading) {
    1.40 -    ClassLoaderData::the_null_class_loader_data()->oops_do(f, klass_closure, must_claim);
    1.41 -    // keep any special CLDs alive.
    1.42      ClassLoaderDataGraph::keep_alive_oops_do(f, klass_closure, must_claim);
    1.43    } else {
    1.44      ClassLoaderDataGraph::oops_do(f, klass_closure, must_claim);
    1.45 @@ -689,7 +695,7 @@
    1.46    bool has_redefined_a_class = JvmtiExport::has_redefined_a_class();
    1.47    MetadataOnStackMark md_on_stack;
    1.48    while (data != NULL) {
    1.49 -    if (data->keep_alive() || data->is_alive(is_alive_closure)) {
    1.50 +    if (data->is_alive(is_alive_closure)) {
    1.51        if (has_redefined_a_class) {
    1.52          data->classes_do(InstanceKlass::purge_previous_versions);
    1.53        }

mercurial