src/hotspot/share/classfile/classLoaderDataGraph.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 58291 a013100f7a35
child 58494 54c1ba464b78
child 58679 9c3209ff7550
child 59247 56bf71d64d51
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     1
/*
54355
f226ab0b7f21 8221183: Avoid code cache walk in MetadataOnStackMark
coleenp
parents: 53322
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     4
 *
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     8
 *
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    13
 * accompanied this code).
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    14
 *
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    18
 *
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    21
 * questions.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    22
 *
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    23
 */
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    24
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    26
#include "classfile/classLoaderDataGraph.inline.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    27
#include "classfile/dictionary.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    28
#include "classfile/javaClasses.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    29
#include "classfile/metadataOnStackMark.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    30
#include "classfile/moduleEntry.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    31
#include "classfile/packageEntry.hpp"
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52587
diff changeset
    32
#include "code/dependencyContext.hpp"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    33
#include "logging/log.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    34
#include "logging/logStream.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    35
#include "memory/allocation.inline.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    36
#include "memory/metaspace.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    37
#include "memory/resourceArea.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    38
#include "runtime/atomic.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    39
#include "runtime/handles.inline.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    40
#include "runtime/mutex.hpp"
55268
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    41
#include "runtime/orderAccess.hpp"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    42
#include "runtime/safepoint.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    43
#include "runtime/safepointVerifiers.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    44
#include "utilities/growableArray.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    45
#include "utilities/macros.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    46
#include "utilities/ostream.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    47
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    48
volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    49
volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    50
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    51
void ClassLoaderDataGraph::clear_claimed_marks() {
55268
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    52
  // The claimed marks of the CLDs in the ClassLoaderDataGraph are cleared
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    53
  // outside a safepoint and without locking the ClassLoaderDataGraph_lock.
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    54
  // This is required to avoid a deadlock between concurrent GC threads and safepointing.
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    55
  //
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    56
  // We need to make sure that the CLD contents are fully visible to the
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    57
  // reader thread. This is accomplished by acquire/release of the _head,
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    58
  // and is sufficient.
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    59
  //
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    60
  // Any ClassLoaderData added after or during walking the list are prepended to
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    61
  // _head. Their claim mark need not be handled here.
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
    62
  for (ClassLoaderData* cld = OrderAccess::load_acquire(&_head); cld != NULL; cld = cld->next()) {
52141
de6dc206a92b 8210330: Make CLD claiming allow multiple claim bits
eosterlund
parents: 52140
diff changeset
    63
    cld->clear_claim();
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    64
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    65
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    66
55603
3868dde58ebb 8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents: 55268
diff changeset
    67
void ClassLoaderDataGraph::clear_claimed_marks(int claim) {
3868dde58ebb 8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents: 55268
diff changeset
    68
 for (ClassLoaderData* cld = OrderAccess::load_acquire(&_head); cld != NULL; cld = cld->next()) {
3868dde58ebb 8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents: 55268
diff changeset
    69
    cld->clear_claim(claim);
3868dde58ebb 8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents: 55268
diff changeset
    70
  }
3868dde58ebb 8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents: 55268
diff changeset
    71
}
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    72
// Class iterator used by the compiler.  It gets some number of classes at
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    73
// a safepoint to decay invocation counters on the methods.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    74
class ClassLoaderDataGraphKlassIteratorStatic {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    75
  ClassLoaderData* _current_loader_data;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    76
  Klass*           _current_class_entry;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    77
 public:
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    78
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    79
  ClassLoaderDataGraphKlassIteratorStatic() : _current_loader_data(NULL), _current_class_entry(NULL) {}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    80
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    81
  InstanceKlass* try_get_next_class() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    82
    assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    83
    size_t max_classes = ClassLoaderDataGraph::num_instance_classes();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    84
    assert(max_classes > 0, "should not be called with no instance classes");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    85
    for (size_t i = 0; i < max_classes; ) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    86
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    87
      if (_current_class_entry != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    88
        Klass* k = _current_class_entry;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    89
        _current_class_entry = _current_class_entry->next_link();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    90
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    91
        if (k->is_instance_klass()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    92
          InstanceKlass* ik = InstanceKlass::cast(k);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    93
          i++;  // count all instance classes found
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    94
          // Not yet loaded classes are counted in max_classes
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    95
          // but only return loaded classes.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    96
          if (ik->is_loaded()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    97
            return ik;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    98
          }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
    99
        }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   100
      } else {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   101
        // Go to next CLD
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   102
        if (_current_loader_data != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   103
          _current_loader_data = _current_loader_data->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   104
        }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   105
        // Start at the beginning
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   106
        if (_current_loader_data == NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   107
          _current_loader_data = ClassLoaderDataGraph::_head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   108
        }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   109
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   110
        _current_class_entry = _current_loader_data->klasses();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   111
      }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   112
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   113
    // Should never be reached unless all instance classes have failed or are not fully loaded.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   114
    // Caller handles NULL.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   115
    return NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   116
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   117
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   118
  // If the current class for the static iterator is a class being unloaded or
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   119
  // deallocated, adjust the current class.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   120
  void adjust_saved_class(ClassLoaderData* cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   121
    if (_current_loader_data == cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   122
      _current_loader_data = cld->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   123
      if (_current_loader_data != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   124
        _current_class_entry = _current_loader_data->klasses();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   125
      }  // else try_get_next_class will start at the head
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   126
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   127
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   128
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   129
  void adjust_saved_class(Klass* klass) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   130
    if (_current_class_entry == klass) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   131
      _current_class_entry = klass->next_link();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   132
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   133
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   134
};
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   135
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   136
static ClassLoaderDataGraphKlassIteratorStatic static_klass_iterator;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   137
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   138
InstanceKlass* ClassLoaderDataGraph::try_get_next_class() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   139
  assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   140
  return static_klass_iterator.try_get_next_class();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   141
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   142
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   143
void ClassLoaderDataGraph::adjust_saved_class(ClassLoaderData* cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   144
  return static_klass_iterator.adjust_saved_class(cld);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   145
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   146
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   147
void ClassLoaderDataGraph::adjust_saved_class(Klass* klass) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   148
  return static_klass_iterator.adjust_saved_class(klass);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   149
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   150
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   151
void ClassLoaderDataGraph::clean_deallocate_lists(bool walk_previous_versions) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   152
  assert(SafepointSynchronize::is_at_safepoint(), "must only be called at safepoint");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   153
  uint loaders_processed = 0;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   154
  for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   155
    // is_alive check will be necessary for concurrent class unloading.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   156
    if (cld->is_alive()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   157
      // clean metaspace
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   158
      if (walk_previous_versions) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   159
        cld->classes_do(InstanceKlass::purge_previous_versions);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   160
      }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   161
      cld->free_deallocate_list();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   162
      loaders_processed++;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   163
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   164
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   165
  log_debug(class, loader, data)("clean_deallocate_lists: loaders processed %u %s",
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   166
                                 loaders_processed, walk_previous_versions ? "walk_previous_versions" : "");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   167
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   168
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   169
void ClassLoaderDataGraph::walk_metadata_and_clean_metaspaces() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   170
  assert(SafepointSynchronize::is_at_safepoint(), "must only be called at safepoint");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   171
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   172
  _should_clean_deallocate_lists = false; // assume everything gets cleaned
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   173
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   174
  // Mark metadata seen on the stack so we can delete unreferenced entries.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   175
  // Walk all metadata, including the expensive code cache walk, only for class redefinition.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   176
  // The MetadataOnStackMark walk during redefinition saves previous versions if it finds old methods
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   177
  // on the stack or in the code cache, so we only have to repeat the full walk if
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   178
  // they were found at that time.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   179
  // TODO: have redefinition clean old methods out of the code cache.  They still exist in some places.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   180
  bool walk_all_metadata = InstanceKlass::has_previous_versions_and_reset();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   181
54355
f226ab0b7f21 8221183: Avoid code cache walk in MetadataOnStackMark
coleenp
parents: 53322
diff changeset
   182
  MetadataOnStackMark md_on_stack(walk_all_metadata, /*redefinition_walk*/false);
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   183
  clean_deallocate_lists(walk_all_metadata);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   184
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   185
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   186
// GC root of class loader data created.
55268
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
   187
ClassLoaderData* volatile ClassLoaderDataGraph::_head = NULL;
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   188
ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   189
ClassLoaderData* ClassLoaderDataGraph::_saved_unloading = NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   190
ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   191
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   192
bool ClassLoaderDataGraph::_should_purge = false;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   193
bool ClassLoaderDataGraph::_should_clean_deallocate_lists = false;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   194
bool ClassLoaderDataGraph::_safepoint_cleanup_needed = false;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   195
bool ClassLoaderDataGraph::_metaspace_oom = false;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   196
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   197
// Add a new class loader data node to the list.  Assign the newly created
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   198
// ClassLoaderData into the java/lang/ClassLoader object as a hidden field
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   199
ClassLoaderData* ClassLoaderDataGraph::add_to_graph(Handle loader, bool is_unsafe_anonymous) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   200
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   201
  assert_lock_strong(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   202
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   203
  ClassLoaderData* cld;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   204
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   205
  // First check if another thread beat us to creating the CLD and installing
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   206
  // it into the loader while we were waiting for the lock.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   207
  if (!is_unsafe_anonymous && loader.not_null()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   208
    cld = java_lang_ClassLoader::loader_data_acquire(loader());
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   209
    if (cld != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   210
      return cld;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   211
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   212
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   213
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   214
  // We mustn't GC until we've installed the ClassLoaderData in the Graph since the CLD
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   215
  // contains oops in _handles that must be walked.  GC doesn't walk CLD from the
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   216
  // loader oop in all collections, particularly young collections.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   217
  NoSafepointVerifier no_safepoints;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   218
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   219
  cld = new ClassLoaderData(loader, is_unsafe_anonymous);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   220
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   221
  // First install the new CLD to the Graph.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   222
  cld->set_next(_head);
55268
c5fe45d1281d 8224151: Test vmTestbase/nsk/sysdict/vm/stress/chain/chain007/chain007.java might hang with release binaries
coleenp
parents: 54961
diff changeset
   223
  OrderAccess::release_store(&_head, cld);
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   224
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   225
  // Next associate with the class_loader.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   226
  if (!is_unsafe_anonymous) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   227
    // Use OrderAccess, since readers need to get the loader_data only after
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   228
    // it's added to the Graph
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   229
    java_lang_ClassLoader::release_set_loader_data(loader(), cld);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   230
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   231
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   232
  // Lastly log, if requested
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   233
  LogTarget(Trace, class, loader, data) lt;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   234
  if (lt.is_enabled()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   235
    ResourceMark rm;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   236
    LogStream ls(lt);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   237
    ls.print("create ");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   238
    cld->print_value_on(&ls);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   239
    ls.cr();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   240
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   241
  return cld;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   242
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   243
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   244
ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_unsafe_anonymous) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   245
  MutexLocker ml(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   246
  ClassLoaderData* loader_data = add_to_graph(loader, is_unsafe_anonymous);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   247
  return loader_data;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   248
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   249
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   250
void ClassLoaderDataGraph::cld_unloading_do(CLDClosure* cl) {
52140
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 52014
diff changeset
   251
  assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   252
  // Only walk the head until any clds not purged from prior unloading
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   253
  // (CMS doesn't purge right away).
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   254
  for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   255
    assert(cld->is_unloading(), "invariant");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   256
    cl->do_cld(cld);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   257
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   258
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   259
52586
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   260
// These are functions called by the GC, which require all of the CLDs, including the
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   261
// unloading ones.
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   262
void ClassLoaderDataGraph::cld_do(CLDClosure* cl) {
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   263
  assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   264
  for (ClassLoaderData* cld = _head;  cld != NULL; cld = cld->_next) {
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   265
    cl->do_cld(cld);
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   266
  }
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   267
}
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   268
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   269
void ClassLoaderDataGraph::roots_cld_do(CLDClosure* strong, CLDClosure* weak) {
52140
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 52014
diff changeset
   270
  assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   271
  for (ClassLoaderData* cld = _head;  cld != NULL; cld = cld->_next) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   272
    CLDClosure* closure = cld->keep_alive() ? strong : weak;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   273
    if (closure != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   274
      closure->do_cld(cld);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   275
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   276
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   277
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   278
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   279
void ClassLoaderDataGraph::always_strong_cld_do(CLDClosure* cl) {
52140
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 52014
diff changeset
   280
  assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   281
  if (ClassUnloading) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   282
    roots_cld_do(cl, NULL);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   283
  } else {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   284
    cld_do(cl);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   285
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   286
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   287
58291
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   288
// Closure for locking and iterating through classes. Only lock outside of safepoint.
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   289
LockedClassesDo::LockedClassesDo(classes_do_func_t f) : _function(f),
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   290
  _do_lock(!SafepointSynchronize::is_at_safepoint()) {
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   291
  if (_do_lock) {
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   292
    ClassLoaderDataGraph_lock->lock();
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   293
  }
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   294
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   295
58291
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   296
LockedClassesDo::LockedClassesDo() : _function(NULL),
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   297
  _do_lock(!SafepointSynchronize::is_at_safepoint()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   298
  // callers provide their own do_klass
58291
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   299
  if (_do_lock) {
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   300
    ClassLoaderDataGraph_lock->lock();
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   301
  }
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   302
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   303
58291
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   304
LockedClassesDo::~LockedClassesDo() {
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   305
  if (_do_lock) {
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   306
    ClassLoaderDataGraph_lock->unlock();
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   307
  }
a013100f7a35 8213150: Add verification for locking by VMThread
coleenp
parents: 57603
diff changeset
   308
}
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   309
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   310
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   311
// Iterating over the CLDG needs to be locked because
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   312
// unloading can remove entries concurrently soon.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   313
class ClassLoaderDataGraphIterator : public StackObj {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   314
  ClassLoaderData* _next;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   315
  HandleMark       _hm;  // clean up handles when this is done.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   316
  Handle           _holder;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   317
  Thread*          _thread;
52586
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   318
  NoSafepointVerifier _nsv; // No safepoints allowed in this scope
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   319
                            // unless verifying at a safepoint.
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   320
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   321
public:
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 55603
diff changeset
   322
  ClassLoaderDataGraphIterator() : _next(ClassLoaderDataGraph::_head) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   323
    _thread = Thread::current();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   324
    assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   325
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   326
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   327
  ClassLoaderData* get_next() {
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   328
    ClassLoaderData* cld = _next;
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   329
    // Skip already unloaded CLD for concurrent unloading.
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   330
    while (cld != NULL && !cld->is_alive()) {
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   331
      cld = cld->next();
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   332
    }
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   333
    if (cld != NULL) {
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   334
      // Keep cld that is being returned alive.
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   335
      _holder = Handle(_thread, cld->holder_phantom());
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   336
      _next = cld->next();
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   337
    } else {
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   338
      _next = NULL;
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   339
    }
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   340
    return cld;
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   341
  }
52586
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   342
};
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   343
52586
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   344
void ClassLoaderDataGraph::loaded_cld_do(CLDClosure* cl) {
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   345
  ClassLoaderDataGraphIterator iter;
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   346
  while (ClassLoaderData* cld = iter.get_next()) {
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   347
    cl->do_cld(cld);
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   348
  }
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52498
diff changeset
   349
}
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   350
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   351
// These functions assume that the caller has locked the ClassLoaderDataGraph_lock
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   352
// if they are not calling the function from a safepoint.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   353
void ClassLoaderDataGraph::classes_do(KlassClosure* klass_closure) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   354
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   355
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   356
    cld->classes_do(klass_closure);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   357
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   358
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   359
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   360
void ClassLoaderDataGraph::classes_do(void f(Klass* const)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   361
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   362
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   363
    cld->classes_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   364
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   365
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   366
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   367
void ClassLoaderDataGraph::methods_do(void f(Method*)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   368
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   369
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   370
    cld->methods_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   371
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   372
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   373
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   374
void ClassLoaderDataGraph::modules_do(void f(ModuleEntry*)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   375
  assert_locked_or_safepoint(Module_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   376
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   377
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   378
    cld->modules_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   379
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   380
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   381
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   382
void ClassLoaderDataGraph::modules_unloading_do(void f(ModuleEntry*)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   383
  assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   384
  // Only walk the head until any clds not purged from prior unloading
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   385
  // (CMS doesn't purge right away).
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   386
  for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   387
    assert(cld->is_unloading(), "invariant");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   388
    cld->modules_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   389
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   390
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   391
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   392
void ClassLoaderDataGraph::packages_do(void f(PackageEntry*)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   393
  assert_locked_or_safepoint(Module_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   394
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   395
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   396
    cld->packages_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   397
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   398
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   399
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   400
void ClassLoaderDataGraph::packages_unloading_do(void f(PackageEntry*)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   401
  assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   402
  // Only walk the head until any clds not purged from prior unloading
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   403
  // (CMS doesn't purge right away).
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   404
  for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   405
    assert(cld->is_unloading(), "invariant");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   406
    cld->packages_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   407
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   408
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   409
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   410
void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   411
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   412
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   413
    cld->loaded_classes_do(klass_closure);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   414
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   415
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   416
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   417
// This case can block but cannot do unloading (called from CDS)
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   418
void ClassLoaderDataGraph::unlocked_loaded_classes_do(KlassClosure* klass_closure) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   419
  for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   420
    cld->loaded_classes_do(klass_closure);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   421
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   422
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   423
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   424
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   425
void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   426
  assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   427
  // Only walk the head until any clds not purged from prior unloading
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   428
  // (CMS doesn't purge right away).
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   429
  for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   430
    assert(cld->is_unloading(), "invariant");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   431
    cld->classes_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   432
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   433
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   434
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   435
#define FOR_ALL_DICTIONARY(X)   ClassLoaderDataGraphIterator iter; \
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   436
                                while (ClassLoaderData* X = iter.get_next()) \
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   437
                                  if (X->dictionary() != NULL)
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   438
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   439
// Walk classes in the loaded class dictionaries in various forms.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   440
// Only walks the classes defined in this class loader.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   441
void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*)) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   442
  FOR_ALL_DICTIONARY(cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   443
    cld->dictionary()->classes_do(f);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   444
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   445
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   446
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   447
// Only walks the classes defined in this class loader.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   448
void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   449
  FOR_ALL_DICTIONARY(cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   450
    cld->dictionary()->classes_do(f, CHECK);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   451
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   452
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   453
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   454
void ClassLoaderDataGraph::verify_dictionary() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   455
  FOR_ALL_DICTIONARY(cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   456
    cld->dictionary()->verify();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   457
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   458
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   459
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   460
void ClassLoaderDataGraph::print_dictionary(outputStream* st) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   461
  FOR_ALL_DICTIONARY(cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   462
    st->print("Dictionary for ");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   463
    cld->print_value_on(st);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   464
    st->cr();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   465
    cld->dictionary()->print_on(st);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   466
    st->cr();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   467
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   468
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   469
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents: 54756
diff changeset
   470
void ClassLoaderDataGraph::print_table_statistics(outputStream* st) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   471
  FOR_ALL_DICTIONARY(cld) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   472
    ResourceMark rm;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   473
    stringStream tempst;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   474
    tempst.print("System Dictionary for %s class loader", cld->loader_name_and_id());
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   475
    cld->dictionary()->print_table_statistics(st, tempst.as_string());
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   476
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   477
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   478
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   479
GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   480
  assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   481
  assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   482
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   483
  GrowableArray<ClassLoaderData*>* array = new GrowableArray<ClassLoaderData*>();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   484
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   485
  // The CLDs in [_head, _saved_head] were all added during last call to remember_new_clds(true);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   486
  ClassLoaderData* curr = _head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   487
  while (curr != _saved_head) {
55603
3868dde58ebb 8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents: 55268
diff changeset
   488
    if (!curr->claimed(ClassLoaderData::_claim_strong)) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   489
      array->push(curr);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   490
      LogTarget(Debug, class, loader, data) lt;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   491
      if (lt.is_enabled()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   492
        LogStream ls(lt);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   493
        ls.print("found new CLD: ");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   494
        curr->print_value_on(&ls);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   495
        ls.cr();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   496
      }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   497
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   498
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   499
    curr = curr->_next;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   500
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   501
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   502
  return array;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   503
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   504
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   505
#ifndef PRODUCT
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   506
bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   507
  assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   508
  for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   509
    if (loader_data == data) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   510
      return true;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   511
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   512
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   513
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   514
  return false;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   515
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   516
#endif // PRODUCT
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   517
52014
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   518
bool ClassLoaderDataGraph::is_valid(ClassLoaderData* loader_data) {
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   519
  DEBUG_ONLY( if (!VMError::is_error_reported()) { assert_locked_or_safepoint(ClassLoaderDataGraph_lock); } )
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   520
  if (loader_data != NULL) {
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   521
    if (loader_data == ClassLoaderData::the_null_class_loader_data()) {
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   522
      return true;
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   523
    }
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   524
    for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   525
      if (loader_data == data) {
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   526
        return true;
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   527
      }
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   528
    }
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   529
  }
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   530
  return false;
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   531
}
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51959
diff changeset
   532
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   533
// Move class loader data from main list to the unloaded list for unloading
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   534
// and deallocation later.
52498
c3066f7465fa 8213307: G1 should clean up RMT with ClassUnloadingWithConcurrentMark
tschatzl
parents: 52344
diff changeset
   535
bool ClassLoaderDataGraph::do_unloading() {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   536
  assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   537
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   538
  // Indicate whether safepoint cleanup is needed.
52498
c3066f7465fa 8213307: G1 should clean up RMT with ClassUnloadingWithConcurrentMark
tschatzl
parents: 52344
diff changeset
   539
  _safepoint_cleanup_needed = true;
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   540
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   541
  ClassLoaderData* data = _head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   542
  ClassLoaderData* prev = NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   543
  bool seen_dead_loader = false;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   544
  uint loaders_processed = 0;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   545
  uint loaders_removed = 0;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   546
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   547
  // Save previous _unloading pointer for CMS which may add to unloading list before
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   548
  // purging and we don't want to rewalk the previously unloaded class loader data.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   549
  _saved_unloading = _unloading;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   550
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   551
  data = _head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   552
  while (data != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   553
    if (data->is_alive()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   554
      prev = data;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   555
      data = data->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   556
      loaders_processed++;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   557
      continue;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   558
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   559
    seen_dead_loader = true;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   560
    loaders_removed++;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   561
    ClassLoaderData* dead = data;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   562
    dead->unload();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   563
    data = data->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   564
    // Remove from loader list.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   565
    // This class loader data will no longer be found
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   566
    // in the ClassLoaderDataGraph.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   567
    if (prev != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   568
      prev->set_next(data);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   569
    } else {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   570
      assert(dead == _head, "sanity check");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   571
      _head = data;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   572
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   573
    dead->set_next(_unloading);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   574
    _unloading = dead;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   575
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   576
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   577
  log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   578
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   579
  return seen_dead_loader;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   580
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   581
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   582
// There's at least one dead class loader.  Purge refererences of healthy module
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   583
// reads lists and package export lists to modules belonging to dead loaders.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   584
void ClassLoaderDataGraph::clean_module_and_package_info() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   585
  assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   586
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   587
  ClassLoaderData* data = _head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   588
  while (data != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   589
    // Walk a ModuleEntry's reads, and a PackageEntry's exports
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   590
    // lists to determine if there are modules on those lists that are now
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   591
    // dead and should be removed.  A module's life cycle is equivalent
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   592
    // to its defining class loader's life cycle.  Since a module is
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   593
    // considered dead if its class loader is dead, these walks must
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   594
    // occur after each class loader's aliveness is determined.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   595
    if (data->packages() != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   596
      data->packages()->purge_all_package_exports();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   597
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   598
    if (data->modules_defined()) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   599
      data->modules()->purge_all_module_reads();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   600
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   601
    data = data->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   602
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   603
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   604
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   605
void ClassLoaderDataGraph::purge() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   606
  ClassLoaderData* list = _unloading;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   607
  _unloading = NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   608
  ClassLoaderData* next = list;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   609
  bool classes_unloaded = false;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   610
  while (next != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   611
    ClassLoaderData* purge_me = next;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   612
    next = purge_me->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   613
    delete purge_me;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   614
    classes_unloaded = true;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   615
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   616
  if (classes_unloaded) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   617
    Metaspace::purge();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   618
    set_metaspace_oom(false);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   619
  }
52781
436097b038a1 8213565: Crash in DependencyContext::remove_dependent_nmethod
eosterlund
parents: 52587
diff changeset
   620
  DependencyContext::purge_dependency_contexts();
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   621
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   622
54961
30c8a21ce002 8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents: 54807
diff changeset
   623
int ClassLoaderDataGraph::resize_dictionaries() {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   624
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   625
  int resized = 0;
54961
30c8a21ce002 8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents: 54807
diff changeset
   626
  assert (Dictionary::does_any_dictionary_needs_resizing(), "some dictionary should need resizing");
30c8a21ce002 8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents: 54807
diff changeset
   627
  FOR_ALL_DICTIONARY(cld) {
30c8a21ce002 8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents: 54807
diff changeset
   628
    if (cld->dictionary()->resize_if_needed()) {
30c8a21ce002 8224119: Safepoint cleanup logging logs times for things it doesn't do
coleenp
parents: 54807
diff changeset
   629
      resized++;
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   630
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   631
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   632
  return resized;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   633
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   634
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   635
ClassLoaderDataGraphKlassIteratorAtomic::ClassLoaderDataGraphKlassIteratorAtomic()
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   636
    : _next_klass(NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   637
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   638
  ClassLoaderData* cld = ClassLoaderDataGraph::_head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   639
  Klass* klass = NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   640
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   641
  // Find the first klass in the CLDG.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   642
  while (cld != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   643
    assert_locked_or_safepoint(cld->metaspace_lock());
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   644
    klass = cld->_klasses;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   645
    if (klass != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   646
      _next_klass = klass;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   647
      return;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   648
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   649
    cld = cld->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   650
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   651
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   652
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   653
Klass* ClassLoaderDataGraphKlassIteratorAtomic::next_klass_in_cldg(Klass* klass) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   654
  Klass* next = klass->next_link();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   655
  if (next != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   656
    return next;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   657
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   658
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   659
  // No more klasses in the current CLD. Time to find a new CLD.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   660
  ClassLoaderData* cld = klass->class_loader_data();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   661
  assert_locked_or_safepoint(cld->metaspace_lock());
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   662
  while (next == NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   663
    cld = cld->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   664
    if (cld == NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   665
      break;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   666
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   667
    next = cld->_klasses;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   668
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   669
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   670
  return next;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   671
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   672
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   673
Klass* ClassLoaderDataGraphKlassIteratorAtomic::next_klass() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   674
  Klass* head = _next_klass;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   675
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   676
  while (head != NULL) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   677
    Klass* next = next_klass_in_cldg(head);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   678
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   679
    Klass* old_head = Atomic::cmpxchg(next, &_next_klass, head);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   680
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   681
    if (old_head == head) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   682
      return head; // Won the CAS.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   683
    }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   684
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   685
    head = old_head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   686
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   687
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   688
  // Nothing more for the iterator to hand out.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   689
  assert(head == NULL, "head is " PTR_FORMAT ", expected not null:", p2i(head));
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   690
  return NULL;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   691
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   692
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   693
ClassLoaderDataGraphMetaspaceIterator::ClassLoaderDataGraphMetaspaceIterator() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   694
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   695
  _data = ClassLoaderDataGraph::_head;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   696
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   697
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   698
ClassLoaderDataGraphMetaspaceIterator::~ClassLoaderDataGraphMetaspaceIterator() {}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   699
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   700
ClassLoaderMetaspace* ClassLoaderDataGraphMetaspaceIterator::get_next() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   701
  assert(_data != NULL, "Should not be NULL in call to the iterator");
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   702
  ClassLoaderMetaspace* result = _data->metaspace_or_null();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   703
  _data = _data->next();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   704
  // This result might be NULL for class loaders without metaspace
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   705
  // yet.  It would be nice to return only non-null results but
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   706
  // there is no guarantee that there will be a non-null result
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   707
  // down the list so the caller is going to have to check.
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   708
  return result;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   709
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   710
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   711
#ifndef PRODUCT
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   712
// callable from debugger
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   713
extern "C" int print_loader_data_graph() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   714
  ResourceMark rm;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   715
  ClassLoaderDataGraph::print_on(tty);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   716
  return 0;
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   717
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   718
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   719
void ClassLoaderDataGraph::verify() {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   720
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   721
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   722
    cld->verify();
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   723
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   724
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   725
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   726
void ClassLoaderDataGraph::print_on(outputStream * const out) {
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   727
  ClassLoaderDataGraphIterator iter;
52344
55711b181dfc 8213107: Make ClassLoaderDataGraph iterator skip unloaded CLDs
coleenp
parents: 52141
diff changeset
   728
  while (ClassLoaderData* cld = iter.get_next()) {
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   729
    cld->print_on(out);
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   730
  }
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   731
}
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
diff changeset
   732
#endif // PRODUCT
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54764
diff changeset
   733
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54764
diff changeset
   734
void ClassLoaderDataGraph::print() { print_on(tty); }