src/hotspot/share/gc/z/zRootsIterator.cpp
author kbarrett
Tue, 02 Apr 2019 13:08:38 -0400
changeset 54385 9559ba212c18
parent 53894 bf1133e7dfba
child 54511 fbfcebad8e66
permissions -rw-r--r--
8221102: Allow GC threads to participate in threads claiming protocol Summary: Expand claim counter from 1bit to uintx, with rare overflow handling. Reviewed-by: tschatzl, rkennke
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     1
/*
54385
9559ba212c18 8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents: 53894
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     4
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     8
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    13
 * accompanied this code).
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    14
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    18
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    21
 * questions.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    22
 */
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    23
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    24
#include "precompiled.hpp"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 51803
diff changeset
    25
#include "classfile/classLoaderDataGraph.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    26
#include "classfile/stringTable.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    27
#include "classfile/systemDictionary.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    28
#include "code/codeCache.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    29
#include "compiler/oopMap.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
    30
#include "gc/shared/barrierSet.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
    31
#include "gc/shared/barrierSetNMethod.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    32
#include "gc/shared/oopStorageParState.inline.hpp"
52140
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
    33
#include "gc/shared/suspendibleThreadSet.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
    34
#include "gc/z/zBarrierSetNMethod.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    35
#include "gc/z/zGlobals.hpp"
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents: 53890
diff changeset
    36
#include "gc/z/zNMethod.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    37
#include "gc/z/zOopClosures.inline.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    38
#include "gc/z/zRootsIterator.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    39
#include "gc/z/zStat.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    40
#include "gc/z/zThreadLocalData.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    41
#include "memory/resourceArea.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    42
#include "memory/universe.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    43
#include "prims/jvmtiExport.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    44
#include "runtime/atomic.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    45
#include "runtime/jniHandles.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    46
#include "runtime/thread.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    47
#include "runtime/safepoint.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    48
#include "runtime/synchronizer.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    49
#include "services/management.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    50
#include "utilities/debug.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    51
#if INCLUDE_JFR
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    52
#include "jfr/jfr.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    53
#endif
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    54
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    55
static const ZStatSubPhase ZSubPhasePauseRootsSetup("Pause Roots Setup");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    56
static const ZStatSubPhase ZSubPhasePauseRoots("Pause Roots");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    57
static const ZStatSubPhase ZSubPhasePauseRootsTeardown("Pause Roots Teardown");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    58
static const ZStatSubPhase ZSubPhasePauseRootsUniverse("Pause Roots Universe");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    59
static const ZStatSubPhase ZSubPhasePauseRootsObjectSynchronizer("Pause Roots ObjectSynchronizer");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    60
static const ZStatSubPhase ZSubPhasePauseRootsManagement("Pause Roots Management");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    61
static const ZStatSubPhase ZSubPhasePauseRootsJVMTIExport("Pause Roots JVMTIExport");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    62
static const ZStatSubPhase ZSubPhasePauseRootsJVMTIWeakExport("Pause Roots JVMTIWeakExport");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    63
static const ZStatSubPhase ZSubPhasePauseRootsSystemDictionary("Pause Roots SystemDictionary");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    64
static const ZStatSubPhase ZSubPhasePauseRootsThreads("Pause Roots Threads");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    65
static const ZStatSubPhase ZSubPhasePauseRootsCodeCache("Pause Roots CodeCache");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    66
52140
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
    67
static const ZStatSubPhase ZSubPhaseConcurrentRootsSetup("Concurrent Roots Setup");
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
    68
static const ZStatSubPhase ZSubPhaseConcurrentRoots("Concurrent Roots");
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
    69
static const ZStatSubPhase ZSubPhaseConcurrentRootsTeardown("Concurrent Roots Teardown");
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
    70
static const ZStatSubPhase ZSubPhaseConcurrentRootsJNIHandles("Concurrent Roots JNIHandles");
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
    71
static const ZStatSubPhase ZSubPhaseConcurrentRootsClassLoaderDataGraph("Concurrent Roots ClassLoaderDataGraph");
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
    72
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    73
static const ZStatSubPhase ZSubPhasePauseWeakRootsSetup("Pause Weak Roots Setup");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    74
static const ZStatSubPhase ZSubPhasePauseWeakRoots("Pause Weak Roots");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    75
static const ZStatSubPhase ZSubPhasePauseWeakRootsTeardown("Pause Weak Roots Teardown");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    76
static const ZStatSubPhase ZSubPhasePauseWeakRootsJVMTIWeakExport("Pause Weak Roots JVMTIWeakExport");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    77
static const ZStatSubPhase ZSubPhasePauseWeakRootsJFRWeak("Pause Weak Roots JFRWeak");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    78
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    79
static const ZStatSubPhase ZSubPhaseConcurrentWeakRoots("Concurrent Weak Roots");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    80
static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsVMWeakHandles("Concurrent Weak Roots VMWeakHandles");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    81
static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsJNIWeakHandles("Concurrent Weak Roots JNIWeakHandles");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    82
static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsStringTable("Concurrent Weak Roots StringTable");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    83
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
    84
template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    85
ZSerialOopsDo<T, F>::ZSerialOopsDo(T* iter) :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    86
    _iter(iter),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    87
    _claimed(false) {}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    88
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
    89
template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
    90
void ZSerialOopsDo<T, F>::oops_do(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    91
  if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    92
    (_iter->*F)(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    93
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    94
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    95
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
    96
template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    97
ZParallelOopsDo<T, F>::ZParallelOopsDo(T* iter) :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    98
    _iter(iter),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    99
    _completed(false) {}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   100
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   101
template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   102
void ZParallelOopsDo<T, F>::oops_do(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   103
  if (!_completed) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   104
    (_iter->*F)(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   105
    if (!_completed) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   106
      _completed = true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   107
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   108
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   109
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   110
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   111
template <typename T, void (T::*F)(BoolObjectClosure*, ZRootsIteratorClosure*)>
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   112
ZSerialWeakOopsDo<T, F>::ZSerialWeakOopsDo(T* iter) :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   113
    _iter(iter),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   114
    _claimed(false) {}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   115
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   116
template <typename T, void (T::*F)(BoolObjectClosure*, ZRootsIteratorClosure*)>
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   117
void ZSerialWeakOopsDo<T, F>::weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   118
  if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   119
    (_iter->*F)(is_alive, cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   120
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   121
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   122
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   123
template <typename T, void (T::*F)(BoolObjectClosure*, ZRootsIteratorClosure*)>
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   124
ZParallelWeakOopsDo<T, F>::ZParallelWeakOopsDo(T* iter) :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   125
    _iter(iter),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   126
    _completed(false) {}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   127
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   128
template <typename T, void (T::*F)(BoolObjectClosure*, ZRootsIteratorClosure*)>
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   129
void ZParallelWeakOopsDo<T, F>::weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   130
  if (!_completed) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   131
    (_iter->*F)(is_alive, cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   132
    if (!_completed) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   133
      _completed = true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   134
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   135
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   136
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   137
53843
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   138
class ZRootsIteratorCodeBlobClosure : public CodeBlobToOopClosure {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   139
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   140
  BarrierSetNMethod* _bs;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   141
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   142
public:
53843
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   143
  ZRootsIteratorCodeBlobClosure(OopClosure* cl) :
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   144
    CodeBlobToOopClosure(cl, true /* fix_relocations */),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   145
    _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   146
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   147
  virtual void do_code_blob(CodeBlob* cb) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   148
    nmethod* const nm = cb->as_nmethod_or_null();
53843
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   149
    if (nm != NULL && !nm->test_set_oops_do_mark()) {
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   150
      CodeBlobToOopClosure::do_code_blob(cb);
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   151
      _bs->disarm(nm);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   152
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   153
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   154
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   155
53843
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   156
class ZRootsIteratorThreadClosure : public ThreadClosure {
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   157
private:
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   158
  ZRootsIteratorClosure* _cl;
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   159
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   160
public:
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   161
  ZRootsIteratorThreadClosure(ZRootsIteratorClosure* cl) :
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   162
      _cl(cl) {}
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   163
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   164
  virtual void do_thread(Thread* thread) {
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   165
    ZRootsIteratorCodeBlobClosure code_cl(_cl);
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   166
    thread->oops_do(_cl, ClassUnloading ? &code_cl : NULL);
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   167
    _cl->do_thread(thread);
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   168
  }
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   169
};
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   170
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   171
ZRootsIterator::ZRootsIterator() :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   172
    _universe(this),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   173
    _object_synchronizer(this),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   174
    _management(this),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   175
    _jvmti_export(this),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   176
    _jvmti_weak_export(this),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   177
    _system_dictionary(this),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   178
    _threads(this),
51590
3aaf039a3636 8210065: ZGC: Remove mode for treating weaks as strong
eosterlund
parents: 51587
diff changeset
   179
    _code_cache(this) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   180
  assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   181
  ZStatTimer timer(ZSubPhasePauseRootsSetup);
54385
9559ba212c18 8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents: 53894
diff changeset
   182
  Threads::change_thread_claim_token();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   183
  COMPILER2_PRESENT(DerivedPointerTable::clear());
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   184
  if (ClassUnloading) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   185
    nmethod::oops_do_marking_prologue();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   186
  } else {
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents: 53890
diff changeset
   187
    ZNMethod::oops_do_begin();
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   188
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   189
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   190
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   191
ZRootsIterator::~ZRootsIterator() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   192
  ZStatTimer timer(ZSubPhasePauseRootsTeardown);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   193
  ResourceMark rm;
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   194
  if (ClassUnloading) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   195
    nmethod::oops_do_marking_epilogue();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   196
  } else {
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents: 53890
diff changeset
   197
    ZNMethod::oops_do_end();
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   198
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   199
  JvmtiExport::gc_epilogue();
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   200
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   201
  COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   202
  Threads::assert_all_threads_claimed();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   203
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   204
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   205
void ZRootsIterator::do_universe(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   206
  ZStatTimer timer(ZSubPhasePauseRootsUniverse);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   207
  Universe::oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   208
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   209
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   210
void ZRootsIterator::do_object_synchronizer(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   211
  ZStatTimer timer(ZSubPhasePauseRootsObjectSynchronizer);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   212
  ObjectSynchronizer::oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   213
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   214
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   215
void ZRootsIterator::do_management(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   216
  ZStatTimer timer(ZSubPhasePauseRootsManagement);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   217
  Management::oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   218
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   219
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   220
void ZRootsIterator::do_jvmti_export(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   221
  ZStatTimer timer(ZSubPhasePauseRootsJVMTIExport);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   222
  JvmtiExport::oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   223
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   224
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   225
void ZRootsIterator::do_jvmti_weak_export(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   226
  ZStatTimer timer(ZSubPhasePauseRootsJVMTIWeakExport);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   227
  AlwaysTrueClosure always_alive;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   228
  JvmtiExport::weak_oops_do(&always_alive, cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   229
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   230
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   231
void ZRootsIterator::do_system_dictionary(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   232
  ZStatTimer timer(ZSubPhasePauseRootsSystemDictionary);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   233
  SystemDictionary::oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   234
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   235
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   236
void ZRootsIterator::do_threads(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   237
  ZStatTimer timer(ZSubPhasePauseRootsThreads);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   238
  ResourceMark rm;
53843
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   239
  ZRootsIteratorThreadClosure thread_cl(cl);
b38d76fc4835 8219332: ZGC: Improve ZRootsIteratorClosure abstraction
pliden
parents: 52939
diff changeset
   240
  Threads::possibly_parallel_threads_do(true, &thread_cl);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   241
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   242
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   243
void ZRootsIterator::do_code_cache(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   244
  ZStatTimer timer(ZSubPhasePauseRootsCodeCache);
53894
bf1133e7dfba 8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents: 53890
diff changeset
   245
  ZNMethod::oops_do(cl);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   246
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   247
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   248
void ZRootsIterator::oops_do(ZRootsIteratorClosure* cl, bool visit_jvmti_weak_export) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   249
  ZStatTimer timer(ZSubPhasePauseRoots);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   250
  _universe.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   251
  _object_synchronizer.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   252
  _management.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   253
  _jvmti_export.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   254
  _system_dictionary.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   255
  _threads.oops_do(cl);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   256
  if (!ClassUnloading) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   257
    _code_cache.oops_do(cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   258
  }
51590
3aaf039a3636 8210065: ZGC: Remove mode for treating weaks as strong
eosterlund
parents: 51587
diff changeset
   259
  if (visit_jvmti_weak_export) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   260
    _jvmti_weak_export.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   261
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   262
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   263
52140
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   264
ZConcurrentRootsIterator::ZConcurrentRootsIterator(bool marking) :
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   265
    _marking(marking),
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   266
    _sts_joiner(marking /* active */),
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   267
    _jni_handles_iter(JNIHandles::global_handles()),
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   268
    _jni_handles(this),
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   269
    _class_loader_data_graph(this) {
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   270
  ZStatTimer timer(ZSubPhaseConcurrentRootsSetup);
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   271
  if (_marking) {
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   272
    ClassLoaderDataGraph_lock->lock();
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   273
    ClassLoaderDataGraph::clear_claimed_marks();
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   274
  }
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   275
}
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   276
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   277
ZConcurrentRootsIterator::~ZConcurrentRootsIterator() {
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   278
  ZStatTimer timer(ZSubPhaseConcurrentRootsTeardown);
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   279
  if (_marking) {
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   280
    ClassLoaderDataGraph_lock->unlock();
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   281
  }
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   282
}
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   283
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   284
void ZConcurrentRootsIterator::do_jni_handles(ZRootsIteratorClosure* cl) {
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   285
  ZStatTimer timer(ZSubPhaseConcurrentRootsJNIHandles);
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   286
  _jni_handles_iter.oops_do(cl);
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   287
}
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   288
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   289
void ZConcurrentRootsIterator::do_class_loader_data_graph(ZRootsIteratorClosure* cl) {
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   290
  ZStatTimer timer(ZSubPhaseConcurrentRootsClassLoaderDataGraph);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   291
  if (_marking) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   292
    CLDToOopClosure cld_cl(cl, ClassLoaderData::_claim_strong);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   293
    ClassLoaderDataGraph::always_strong_cld_do(&cld_cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   294
  } else {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   295
    CLDToOopClosure cld_cl(cl, ClassLoaderData::_claim_none);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   296
    ClassLoaderDataGraph::cld_do(&cld_cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52141
diff changeset
   297
  }
52140
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   298
}
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   299
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   300
void ZConcurrentRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   301
  ZStatTimer timer(ZSubPhaseConcurrentRoots);
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   302
  _jni_handles.oops_do(cl);
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   303
  _class_loader_data_graph.oops_do(cl);
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   304
}
3a168f782e80 8210064: ZGC: Introduce ZConcurrentRootsIterator for scanning a subset of strong IN_NATIVE roots concurrently
eosterlund
parents: 51959
diff changeset
   305
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   306
ZWeakRootsIterator::ZWeakRootsIterator() :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   307
    _jvmti_weak_export(this),
51587
b459c731901b 8210061: ZGC: Remove STW weak processor mode
eosterlund
parents: 51405
diff changeset
   308
    _jfr_weak(this) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   309
  assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   310
  ZStatTimer timer(ZSubPhasePauseWeakRootsSetup);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   311
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   312
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   313
ZWeakRootsIterator::~ZWeakRootsIterator() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   314
  ZStatTimer timer(ZSubPhasePauseWeakRootsTeardown);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   315
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   316
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   317
void ZWeakRootsIterator::do_jvmti_weak_export(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   318
  ZStatTimer timer(ZSubPhasePauseWeakRootsJVMTIWeakExport);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   319
  JvmtiExport::weak_oops_do(is_alive, cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   320
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   321
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   322
void ZWeakRootsIterator::do_jfr_weak(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   323
#if INCLUDE_JFR
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   324
  ZStatTimer timer(ZSubPhasePauseWeakRootsJFRWeak);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   325
  Jfr::weak_oops_do(is_alive, cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   326
#endif
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   327
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   328
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   329
void ZWeakRootsIterator::weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   330
  ZStatTimer timer(ZSubPhasePauseWeakRoots);
51590
3aaf039a3636 8210065: ZGC: Remove mode for treating weaks as strong
eosterlund
parents: 51587
diff changeset
   331
  _jvmti_weak_export.weak_oops_do(is_alive, cl);
3aaf039a3636 8210065: ZGC: Remove mode for treating weaks as strong
eosterlund
parents: 51587
diff changeset
   332
  _jfr_weak.weak_oops_do(is_alive, cl);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   333
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   334
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   335
void ZWeakRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   336
  AlwaysTrueClosure always_alive;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   337
  weak_oops_do(&always_alive, cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   338
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   339
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   340
ZConcurrentWeakRootsIterator::ZConcurrentWeakRootsIterator() :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   341
    _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   342
    _jni_weak_handles_iter(JNIHandles::weak_global_handles()),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   343
    _string_table_iter(StringTable::weak_storage()),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   344
    _vm_weak_handles(this),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   345
    _jni_weak_handles(this),
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   346
    _string_table(this) {
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   347
  StringTable::reset_dead_counter();
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   348
}
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   349
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   350
ZConcurrentWeakRootsIterator::~ZConcurrentWeakRootsIterator() {
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   351
  StringTable::finish_dead_counter();
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   352
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   353
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   354
void ZConcurrentWeakRootsIterator::do_vm_weak_handles(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   355
  ZStatTimer timer(ZSubPhaseConcurrentWeakRootsVMWeakHandles);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   356
  _vm_weak_handles_iter.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   357
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   358
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   359
void ZConcurrentWeakRootsIterator::do_jni_weak_handles(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   360
  ZStatTimer timer(ZSubPhaseConcurrentWeakRootsJNIWeakHandles);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   361
  _jni_weak_handles_iter.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   362
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   363
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   364
class ZStringTableDeadCounterClosure : public ZRootsIteratorClosure  {
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   365
private:
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   366
  ZRootsIteratorClosure* const _cl;
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   367
  size_t                       _ndead;
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   368
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   369
public:
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   370
  ZStringTableDeadCounterClosure(ZRootsIteratorClosure* cl) :
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   371
      _cl(cl),
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   372
      _ndead(0) {}
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   373
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   374
  ~ZStringTableDeadCounterClosure() {
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   375
    StringTable::inc_dead_counter(_ndead);
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   376
  }
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   377
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   378
  virtual void do_oop(oop* p) {
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   379
    _cl->do_oop(p);
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   380
    if (*p == NULL) {
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   381
      _ndead++;
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   382
    }
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   383
  }
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   384
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   385
  virtual void do_oop(narrowOop* p) {
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   386
    ShouldNotReachHere();
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   387
  }
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   388
};
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   389
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   390
void ZConcurrentWeakRootsIterator::do_string_table(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   391
  ZStatTimer timer(ZSubPhaseConcurrentWeakRootsStringTable);
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   392
  ZStringTableDeadCounterClosure counter_cl(cl);
50556
e5a40146791b 8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents: 50525
diff changeset
   393
  _string_table_iter.oops_do(&counter_cl);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   394
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   395
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   396
void ZConcurrentWeakRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   397
  ZStatTimer timer(ZSubPhaseConcurrentWeakRoots);
51590
3aaf039a3636 8210065: ZGC: Remove mode for treating weaks as strong
eosterlund
parents: 51587
diff changeset
   398
  _vm_weak_handles.oops_do(cl);
3aaf039a3636 8210065: ZGC: Remove mode for treating weaks as strong
eosterlund
parents: 51587
diff changeset
   399
  _jni_weak_handles.oops_do(cl);
3aaf039a3636 8210065: ZGC: Remove mode for treating weaks as strong
eosterlund
parents: 51587
diff changeset
   400
  _string_table.oops_do(cl);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   401
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   402
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   403
ZThreadRootsIterator::ZThreadRootsIterator() :
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   404
    _threads(this) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   405
  assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   406
  ZStatTimer timer(ZSubPhasePauseRootsSetup);
54385
9559ba212c18 8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents: 53894
diff changeset
   407
  Threads::change_thread_claim_token();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   408
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   409
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   410
ZThreadRootsIterator::~ZThreadRootsIterator() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   411
  ZStatTimer timer(ZSubPhasePauseRootsTeardown);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   412
  Threads::assert_all_threads_claimed();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   413
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   414
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   415
void ZThreadRootsIterator::do_threads(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   416
  ZStatTimer timer(ZSubPhasePauseRootsThreads);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   417
  ResourceMark rm;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   418
  Threads::possibly_parallel_oops_do(true, cl, NULL);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   419
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   420
51803
a16777c0a6c5 8210881: ZGC: Introduce ZRootsIteratorClosure
pliden
parents: 51744
diff changeset
   421
void ZThreadRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   422
  ZStatTimer timer(ZSubPhasePauseRoots);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   423
  _threads.oops_do(cl);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   424
}