src/hotspot/share/gc/shenandoah/shenandoahUnload.cpp
author zgu
Wed, 27 Nov 2019 11:52:57 -0500
changeset 59296 9186be5c78ba
permissions -rw-r--r--
8228720: Shenandoah: Implementation of concurrent class unloading Reviewed-by: rkennke
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59296
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     1
/*
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     2
 * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     3
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     6
 * published by the Free Software Foundation.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     7
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    12
 * accompanied this code).
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    13
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    17
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    20
 * questions.
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    21
 *
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    22
 */
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    23
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    24
#include "precompiled.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    25
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    26
#include "classfile/classLoaderDataGraph.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    27
#include "classfile/systemDictionary.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    28
#include "code/codeBehaviours.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    29
#include "code/codeCache.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    30
#include "code/dependencyContext.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    31
#include "gc/shared/gcBehaviours.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    32
#include "gc/shared/suspendibleThreadSet.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    33
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    34
#include "gc/shenandoah/shenandoahCodeRoots.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    35
#include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    36
#include "gc/shenandoah/shenandoahNMethod.inline.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    37
#include "gc/shenandoah/shenandoahLock.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    38
#include "gc/shenandoah/shenandoahRootProcessor.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    39
#include "gc/shenandoah/shenandoahUnload.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    40
#include "gc/shenandoah/shenandoahVerifier.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    41
#include "memory/iterator.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    42
#include "memory/resourceArea.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    43
#include "oops/access.inline.hpp"
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    44
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    45
class ShenandoahIsUnloadingOopClosure : public OopClosure {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    46
private:
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    47
  ShenandoahMarkingContext*    _marking_context;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    48
  bool                         _is_unloading;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    49
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    50
public:
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    51
  ShenandoahIsUnloadingOopClosure() :
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    52
    _marking_context(ShenandoahHeap::heap()->marking_context()),
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    53
    _is_unloading(false) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    54
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    55
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    56
  virtual void do_oop(oop* p) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    57
    if (_is_unloading) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    58
      return;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    59
    }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    60
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    61
    const oop o = RawAccess<>::oop_load(p);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    62
    if (!CompressedOops::is_null(o) &&
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    63
        _marking_context->is_complete() &&
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    64
        !_marking_context->is_marked(o)) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    65
      _is_unloading = true;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    66
    }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    67
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    68
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    69
  virtual void do_oop(narrowOop* p) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    70
    ShouldNotReachHere();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    71
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    72
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    73
  bool is_unloading() const {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    74
    return _is_unloading;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    75
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    76
};
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    77
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    78
class ShenandoahIsUnloadingBehaviour : public IsUnloadingBehaviour {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    79
public:
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    80
  virtual bool is_unloading(CompiledMethod* method) const {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    81
    nmethod* const nm = method->as_nmethod();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    82
    guarantee(ShenandoahHeap::heap()->is_evacuation_in_progress(), "Only this phase");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    83
    ShenandoahNMethod* data = ShenandoahNMethod::gc_data(nm);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    84
    ShenandoahReentrantLocker locker(data->lock());
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    85
    ShenandoahIsUnloadingOopClosure cl;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    86
    data->oops_do(&cl);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    87
    return  cl.is_unloading();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    88
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    89
};
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    90
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    91
class ShenandoahCompiledICProtectionBehaviour : public CompiledICProtectionBehaviour {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    92
public:
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    93
  virtual bool lock(CompiledMethod* method) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    94
    nmethod* const nm = method->as_nmethod();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    95
    ShenandoahReentrantLock* const lock = ShenandoahNMethod::lock_for_nmethod(nm);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    96
    assert(lock != NULL, "Not yet registered?");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    97
    lock->lock();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    98
    return true;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
    99
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   100
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   101
  virtual void unlock(CompiledMethod* method) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   102
    nmethod* const nm = method->as_nmethod();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   103
    ShenandoahReentrantLock* const lock = ShenandoahNMethod::lock_for_nmethod(nm);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   104
    assert(lock != NULL, "Not yet registered?");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   105
    lock->unlock();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   106
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   107
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   108
  virtual bool is_safe(CompiledMethod* method) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   109
    if (SafepointSynchronize::is_at_safepoint()) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   110
      return true;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   111
    }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   112
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   113
    nmethod* const nm = method->as_nmethod();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   114
    ShenandoahReentrantLock* const lock = ShenandoahNMethod::lock_for_nmethod(nm);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   115
    assert(lock != NULL, "Not yet registered?");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   116
    return lock->owned_by_self();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   117
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   118
};
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   119
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   120
ShenandoahUnload::ShenandoahUnload() {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   121
  if (ShenandoahConcurrentRoots::can_do_concurrent_class_unloading()) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   122
    static ShenandoahIsUnloadingBehaviour is_unloading_behaviour;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   123
    IsUnloadingBehaviour::set_current(&is_unloading_behaviour);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   124
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   125
    static ShenandoahCompiledICProtectionBehaviour ic_protection_behaviour;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   126
    CompiledICProtectionBehaviour::set_current(&ic_protection_behaviour);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   127
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   128
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   129
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   130
void ShenandoahUnload::prepare() {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   131
  assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   132
  assert(ShenandoahConcurrentRoots::can_do_concurrent_class_unloading(), "Sanity");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   133
  CodeCache::increment_unloading_cycle();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   134
  DependencyContext::cleaning_start();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   135
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   136
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   137
void ShenandoahUnload::unlink() {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   138
  SuspendibleThreadSetJoiner sts;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   139
  bool unloading_occurred;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   140
  ShenandoahHeap* const heap = ShenandoahHeap::heap();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   141
  {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   142
    MutexLocker cldg_ml(ClassLoaderDataGraph_lock);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   143
    unloading_occurred = SystemDictionary::do_unloading(heap->gc_timer());
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   144
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   145
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   146
  Klass::clean_weak_klass_links(unloading_occurred);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   147
  ShenandoahCodeRoots::unlink(ShenandoahHeap::heap()->workers(), unloading_occurred);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   148
  DependencyContext::cleaning_end();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   149
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   150
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   151
void ShenandoahUnload::purge() {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   152
  {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   153
    SuspendibleThreadSetJoiner sts;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   154
    ShenandoahCodeRoots::purge(ShenandoahHeap::heap()->workers());
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   155
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   156
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   157
  ClassLoaderDataGraph::purge();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   158
  CodeCache::purge_exception_caches();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   159
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   160
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   161
class ShenandoahUnloadRendezvousClosure : public ThreadClosure {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   162
public:
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   163
  void do_thread(Thread* thread) {}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   164
};
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   165
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   166
void ShenandoahUnload::unload() {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   167
  assert(ShenandoahConcurrentRoots::can_do_concurrent_class_unloading(), "Why we here?");
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   168
  if (!ShenandoahHeap::heap()->is_evacuation_in_progress()) {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   169
    return;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   170
  }
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   171
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   172
  // Unlink stale metadata and nmethods
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   173
  unlink();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   174
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   175
  // Make sure stale metadata and nmethods are no longer observable
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   176
  ShenandoahUnloadRendezvousClosure cl;
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   177
  Handshake::execute(&cl);
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   178
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   179
  // Purge stale metadata and nmethods that were unlinked
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   180
  purge();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   181
}
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   182
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   183
void ShenandoahUnload::finish() {
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   184
  MetaspaceGC::compute_new_size();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   185
  MetaspaceUtils::verify_metrics();
9186be5c78ba 8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff changeset
   186
}