src/hotspot/share/gc/z/zNMethodTable.cpp
author eosterlund
Tue, 11 Dec 2018 11:08:39 +0100
changeset 52939 9a8585f60c32
parent 52410 9d3abb1b7b1f
child 53282 cb7fff9105a8
permissions -rw-r--r--
8214897: ZGC: Concurrent Class Unloading Reviewed-by: pliden Contributed-by: erik.osterlund@oracle.com, per.liden@oracle.com, stefan.karlsson@oracle.com
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
/*
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
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"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    25
#include "code/relocInfo.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    26
#include "code/nmethod.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    27
#include "code/icBuffer.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    28
#include "gc/shared/barrierSet.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    29
#include "gc/shared/barrierSetNMethod.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    30
#include "gc/z/zArray.inline.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    31
#include "gc/z/zGlobals.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    32
#include "gc/z/zHash.inline.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    33
#include "gc/z/zLock.inline.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    34
#include "gc/z/zNMethodTable.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    35
#include "gc/z/zOopClosures.inline.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    36
#include "gc/z/zTask.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    37
#include "gc/z/zWorkers.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    38
#include "logging/log.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    39
#include "memory/allocation.inline.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    40
#include "memory/resourceArea.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    41
#include "runtime/atomic.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    42
#include "runtime/orderAccess.hpp"
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    43
#include "runtime/os.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    44
#include "utilities/debug.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    45
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    46
class ZNMethodDataImmediateOops {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    47
private:
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    48
  const size_t _nimmediate_oops;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    49
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    50
  static size_t header_size();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    51
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    52
  ZNMethodDataImmediateOops(const GrowableArray<oop*>& immediate_oops);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    53
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    54
public:
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    55
  static ZNMethodDataImmediateOops* create(const GrowableArray<oop*>& immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    56
  static void destroy(ZNMethodDataImmediateOops* data_immediate_oops);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    57
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    58
  size_t immediate_oops_count() const;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    59
  oop** immediate_oops_begin() const;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    60
  oop** immediate_oops_end() const;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    61
};
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    62
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    63
size_t ZNMethodDataImmediateOops::header_size() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    64
  const size_t size = sizeof(ZNMethodDataImmediateOops);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    65
  assert(is_aligned(size, sizeof(oop*)), "Header misaligned");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    66
  return size;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    67
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    68
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    69
ZNMethodDataImmediateOops* ZNMethodDataImmediateOops::create(const GrowableArray<oop*>& immediate_oops) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    70
  // Allocate memory for the ZNMethodDataImmediateOops object
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    71
  // plus the immediate oop* array that follows right after.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    72
  const size_t size = ZNMethodDataImmediateOops::header_size() + (sizeof(oop*) * immediate_oops.length());
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    73
  void* const data_immediate_oops = NEW_C_HEAP_ARRAY(uint8_t, size, mtGC);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    74
  return ::new (data_immediate_oops) ZNMethodDataImmediateOops(immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    75
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    76
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    77
void ZNMethodDataImmediateOops::destroy(ZNMethodDataImmediateOops* data_immediate_oops) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    78
  ZNMethodTable::safe_delete(data_immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    79
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    80
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    81
ZNMethodDataImmediateOops::ZNMethodDataImmediateOops(const GrowableArray<oop*>& immediate_oops) :
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    82
    _nimmediate_oops(immediate_oops.length()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    83
  // Save all immediate oops
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    84
  for (size_t i = 0; i < _nimmediate_oops; i++) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    85
    immediate_oops_begin()[i] = immediate_oops.at(i);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    86
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    87
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    88
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    89
size_t ZNMethodDataImmediateOops::immediate_oops_count() const {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    90
  return _nimmediate_oops;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    91
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    92
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    93
oop** ZNMethodDataImmediateOops::immediate_oops_begin() const {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    94
  // The immediate oop* array starts immediately after this object
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    95
  return (oop**)((uintptr_t)this + header_size());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    96
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    97
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    98
oop** ZNMethodDataImmediateOops::immediate_oops_end() const {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    99
  return immediate_oops_begin() + immediate_oops_count();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   100
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   101
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   102
class ZNMethodData {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   103
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   104
  ZReentrantLock                      _lock;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   105
  ZNMethodDataImmediateOops* volatile _immediate_oops;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   106
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   107
  ZNMethodData(nmethod* nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   108
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   109
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   110
  static ZNMethodData* create(nmethod* nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   111
  static void destroy(ZNMethodData* data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   112
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   113
  ZReentrantLock* lock();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   114
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   115
  ZNMethodDataImmediateOops* immediate_oops() const;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   116
  ZNMethodDataImmediateOops* swap_immediate_oops(const GrowableArray<oop*>& immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   117
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   118
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   119
ZNMethodData* ZNMethodData::create(nmethod* nm) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   120
  void* const method = NEW_C_HEAP_ARRAY(uint8_t, sizeof(ZNMethodData), mtGC);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   121
  return ::new (method) ZNMethodData(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   122
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   123
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   124
void ZNMethodData::destroy(ZNMethodData* data) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   125
  ZNMethodDataImmediateOops::destroy(data->immediate_oops());
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   126
  ZNMethodTable::safe_delete(data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   127
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   128
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   129
ZNMethodData::ZNMethodData(nmethod* nm) :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   130
    _lock(),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   131
    _immediate_oops(NULL) {}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   132
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   133
ZReentrantLock* ZNMethodData::lock() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   134
  return &_lock;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   135
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   136
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   137
ZNMethodDataImmediateOops* ZNMethodData::immediate_oops() const {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   138
  return OrderAccess::load_acquire(&_immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   139
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   140
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   141
ZNMethodDataImmediateOops* ZNMethodData::swap_immediate_oops(const GrowableArray<oop*>& immediate_oops) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   142
  ZNMethodDataImmediateOops* const data_immediate_oops =
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   143
    immediate_oops.is_empty() ? NULL : ZNMethodDataImmediateOops::create(immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   144
  return Atomic::xchg(data_immediate_oops, &_immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   145
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   146
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   147
static ZNMethodData* gc_data(const nmethod* nm) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   148
  return nm->gc_data<ZNMethodData>();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   149
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   150
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   151
static void set_gc_data(nmethod* nm, ZNMethodData* data) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   152
  return nm->set_gc_data<ZNMethodData>(data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   153
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   154
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   155
ZNMethodTableEntry* ZNMethodTable::_table = NULL;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   156
size_t ZNMethodTable::_size = 0;
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   157
ZLock ZNMethodTable::_iter_lock;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   158
ZNMethodTableEntry* ZNMethodTable::_iter_table = NULL;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   159
size_t ZNMethodTable::_iter_table_size = 0;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   160
ZArray<void*> ZNMethodTable::_iter_deferred_deletes;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   161
size_t ZNMethodTable::_nregistered = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   162
size_t ZNMethodTable::_nunregistered = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   163
volatile size_t ZNMethodTable::_claimed = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   164
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   165
void ZNMethodTable::safe_delete(void* data) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   166
  if (data == NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   167
    return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   168
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   169
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   170
  ZLocker<ZLock> locker(&_iter_lock);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   171
  if (_iter_table != NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   172
    // Iteration in progress, defer delete
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   173
    _iter_deferred_deletes.add(data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   174
  } else {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   175
    // Iteration not in progress, delete now
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   176
    FREE_C_HEAP_ARRAY(uint8_t, data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   177
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   178
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   179
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   180
ZNMethodTableEntry ZNMethodTable::create_entry(nmethod* nm) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   181
  GrowableArray<oop*> immediate_oops;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   182
  bool non_immediate_oops = false;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   183
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   184
  // Find all oops relocations
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   185
  RelocIterator iter(nm);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   186
  while (iter.next()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   187
    if (iter.type() != relocInfo::oop_type) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   188
      // Not an oop
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   189
      continue;
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
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   192
    oop_Relocation* r = iter.oop_reloc();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   193
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   194
    if (!r->oop_is_immediate()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   195
      // Non-immediate oop found
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   196
      non_immediate_oops = true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   197
      continue;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   198
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   199
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   200
    if (r->oop_value() != NULL) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   201
      // Non-NULL immediate oop found. NULL oops can safely be
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   202
      // ignored since the method will be re-registered if they
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   203
      // are later patched to be non-NULL.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   204
      immediate_oops.push(r->oop_addr());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   205
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   206
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   207
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   208
  // Attach GC data to nmethod
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   209
  ZNMethodData* data = gc_data(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   210
  if (data == NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   211
    data = ZNMethodData::create(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   212
    set_gc_data(nm, data);
50525
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
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   215
  // Attach immediate oops in GC data
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   216
  ZNMethodDataImmediateOops* const old_data_immediate_oops = data->swap_immediate_oops(immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   217
  ZNMethodDataImmediateOops::destroy(old_data_immediate_oops);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   218
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   219
  // Create entry
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   220
  return ZNMethodTableEntry(nm, non_immediate_oops, !immediate_oops.is_empty());
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   221
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   222
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   223
ZReentrantLock* ZNMethodTable::lock_for_nmethod(nmethod* nm) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   224
  ZNMethodData* const data = gc_data(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   225
  if (data == NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   226
    return NULL;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   227
  }
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   228
  return data->lock();
50525
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
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   231
size_t ZNMethodTable::first_index(const nmethod* nm, size_t size) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   232
  assert(is_power_of_2(size), "Invalid size");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   233
  const size_t mask = size - 1;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   234
  const size_t hash = ZHash::address_to_uint32((uintptr_t)nm);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   235
  return hash & mask;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   236
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   237
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   238
size_t ZNMethodTable::next_index(size_t prev_index, size_t size) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   239
  assert(is_power_of_2(size), "Invalid size");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   240
  const size_t mask = size - 1;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   241
  return (prev_index + 1) & mask;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   242
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   243
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   244
bool ZNMethodTable::register_entry(ZNMethodTableEntry* table, size_t size, ZNMethodTableEntry entry) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   245
  const nmethod* const nm = entry.method();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   246
  size_t index = first_index(nm, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   247
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   248
  for (;;) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   249
    const ZNMethodTableEntry table_entry = table[index];
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   250
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   251
    if (!table_entry.registered() && !table_entry.unregistered()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   252
      // Insert new entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   253
      table[index] = entry;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   254
      return true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   255
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   256
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   257
    if (table_entry.registered() && table_entry.method() == nm) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   258
      // Replace existing entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   259
      table[index] = entry;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   260
      return false;
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
    index = next_index(index, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   264
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   265
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   266
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   267
bool ZNMethodTable::unregister_entry(ZNMethodTableEntry* table, size_t size, nmethod* nm) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   268
  if (size == 0) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   269
    // Table is empty
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   270
    return false;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   271
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   272
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   273
  size_t index = first_index(nm, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   274
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   275
  for (;;) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   276
    const ZNMethodTableEntry table_entry = table[index];
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   277
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   278
    if (!table_entry.registered() && !table_entry.unregistered()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   279
      // Entry not found
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   280
      return false;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   281
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   282
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   283
    if (table_entry.registered() && table_entry.method() == nm) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   284
      // Remove entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   285
      table[index] = ZNMethodTableEntry(true /* unregistered */);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   286
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   287
      // Destroy GC data
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   288
      ZNMethodData::destroy(gc_data(nm));
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   289
      set_gc_data(nm, NULL);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   290
      return true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   291
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   292
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   293
    index = next_index(index, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   294
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   295
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   296
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   297
void ZNMethodTable::rebuild(size_t new_size) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   298
  ZLocker<ZLock> locker(&_iter_lock);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   299
  assert(is_power_of_2(new_size), "Invalid size");
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   300
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   301
  log_debug(gc, nmethod)("Rebuilding NMethod Table: "
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   302
                         SIZE_FORMAT "->" SIZE_FORMAT " entries, "
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   303
                         SIZE_FORMAT "(%.0lf%%->%.0lf%%) registered, "
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   304
                         SIZE_FORMAT "(%.0lf%%->%.0lf%%) unregistered",
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   305
                         _size, new_size,
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   306
                         _nregistered, percent_of(_nregistered, _size), percent_of(_nregistered, new_size),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   307
                         _nunregistered, percent_of(_nunregistered, _size), 0.0);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   308
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   309
  // Allocate new table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   310
  ZNMethodTableEntry* const new_table = new ZNMethodTableEntry[new_size];
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
  // Transfer all registered entries
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   313
  for (size_t i = 0; i < _size; i++) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   314
    const ZNMethodTableEntry entry = _table[i];
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   315
    if (entry.registered()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   316
      register_entry(new_table, new_size, entry);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   317
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   318
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   319
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   320
  if (_iter_table != _table) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   321
    // Delete old table
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   322
    delete [] _table;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   323
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   324
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   325
  // Install new table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   326
  _table = new_table;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   327
  _size = new_size;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   328
  _nunregistered = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   329
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   330
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   331
void ZNMethodTable::rebuild_if_needed() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   332
  // The hash table uses linear probing. To avoid wasting memory while
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   333
  // at the same time maintaining good hash collision behavior we want
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   334
  // to keep the table occupancy between 30% and 70%. The table always
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   335
  // grows/shrinks by doubling/halving its size. Pruning of unregistered
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   336
  // entries is done by rebuilding the table with or without resizing it.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   337
  const size_t min_size = 1024;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   338
  const size_t shrink_threshold = _size * 0.30;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   339
  const size_t prune_threshold = _size * 0.65;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   340
  const size_t grow_threshold = _size * 0.70;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   341
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   342
  if (_size == 0) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   343
    // Initialize table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   344
    rebuild(min_size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   345
  } else if (_nregistered < shrink_threshold && _size > min_size) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   346
    // Shrink table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   347
    rebuild(_size / 2);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   348
  } else if (_nregistered + _nunregistered > grow_threshold) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   349
    // Prune or grow table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   350
    if (_nregistered < prune_threshold) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   351
      // Prune table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   352
      rebuild(_size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   353
    } else {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   354
      // Grow table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   355
      rebuild(_size * 2);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   356
    }
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
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   359
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   360
void ZNMethodTable::log_register(const nmethod* nm, ZNMethodTableEntry entry) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   361
  LogTarget(Trace, gc, nmethod) log;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   362
  if (!log.is_enabled()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   363
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   364
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   365
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   366
  log.print("Register NMethod: %s.%s (" PTR_FORMAT "), "
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   367
            "Compiler: %s, Oops: %d, ImmediateOops: " SIZE_FORMAT ", NonImmediateOops: %s",
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   368
            nm->method()->method_holder()->external_name(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   369
            nm->method()->name()->as_C_string(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   370
            p2i(nm),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   371
            nm->compiler_name(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   372
            nm->oops_count() - 1,
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   373
            entry.immediate_oops() ? gc_data(nm)->immediate_oops()->immediate_oops_count() : 0,
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   374
            entry.non_immediate_oops() ? "Yes" : "No");
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   375
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   376
  LogTarget(Trace, gc, nmethod, oops) log_oops;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   377
  if (!log_oops.is_enabled()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   378
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   379
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   380
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   381
  // Print nmethod oops table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   382
  oop* const begin = nm->oops_begin();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   383
  oop* const end = nm->oops_end();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   384
  for (oop* p = begin; p < end; p++) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   385
    log_oops.print("           Oop[" SIZE_FORMAT "] " PTR_FORMAT " (%s)",
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   386
                   (p - begin), p2i(*p), (*p)->klass()->external_name());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   387
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   388
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   389
  if (entry.immediate_oops()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   390
    // Print nmethod immediate oops
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   391
    const ZNMethodDataImmediateOops* const nmi = gc_data(nm)->immediate_oops();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   392
    if (nmi != NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   393
      oop** const begin = nmi->immediate_oops_begin();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   394
      oop** const end = nmi->immediate_oops_end();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   395
      for (oop** p = begin; p < end; p++) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   396
        log_oops.print("  ImmediateOop[" SIZE_FORMAT "] " PTR_FORMAT " @ " PTR_FORMAT " (%s)",
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   397
                       (p - begin), p2i(**p), p2i(*p), (**p)->klass()->external_name());
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   398
      }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   399
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   400
  }
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
void ZNMethodTable::log_unregister(const nmethod* nm) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   404
  LogTarget(Debug, gc, nmethod) log;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   405
  if (!log.is_enabled()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   406
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   407
  }
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
  log.print("Unregister NMethod: %s.%s (" PTR_FORMAT ")",
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   410
            nm->method()->method_holder()->external_name(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   411
            nm->method()->name()->as_C_string(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   412
            p2i(nm));
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
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   415
size_t ZNMethodTable::registered_nmethods() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   416
  return _nregistered;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   417
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   418
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   419
size_t ZNMethodTable::unregistered_nmethods() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   420
  return _nunregistered;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   421
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   422
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   423
void ZNMethodTable::register_nmethod(nmethod* nm) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   424
  assert(CodeCache_lock->owned_by_self(), "Lock must be held");
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   425
  ResourceMark rm;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   426
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   427
  // Grow/Shrink/Prune table if needed
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   428
  rebuild_if_needed();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   429
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   430
  // Create entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   431
  const ZNMethodTableEntry entry = create_entry(nm);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   432
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   433
  log_register(nm, entry);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   434
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   435
  // Insert new entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   436
  if (register_entry(_table, _size, entry)) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   437
    // New entry registered. When register_entry() instead returns
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   438
    // false the nmethod was already in the table so we do not want
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   439
    // to increase number of registered entries in that case.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   440
    _nregistered++;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   441
  }
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   442
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   443
  // Disarm nmethod entry barrier
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   444
  disarm_nmethod(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   445
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   446
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   447
void ZNMethodTable::sweeper_wait_for_iteration() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   448
  // The sweeper must wait for any ongoing iteration to complete
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   449
  // before it can unregister an nmethod.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   450
  if (!Thread::current()->is_Code_cache_sweeper_thread()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   451
    return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   452
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   453
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   454
  assert(CodeCache_lock->owned_by_self(), "Lock must be held");
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   455
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   456
  while (_iter_table != NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   457
    MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   458
    os::naked_short_sleep(1);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   459
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   460
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   461
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   462
void ZNMethodTable::unregister_nmethod(nmethod* nm) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   463
  ResourceMark rm;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   464
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   465
  sweeper_wait_for_iteration();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   466
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   467
  log_unregister(nm);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   468
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   469
  // Remove entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   470
  if (unregister_entry(_table, _size, nm)) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   471
    // Entry was unregistered. When unregister_entry() instead returns
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   472
    // false the nmethod was not in the table (because it didn't have
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   473
    // any oops) so we do not want to decrease the number of registered
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   474
    // entries in that case.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   475
    _nregistered--;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   476
    _nunregistered++;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   477
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   478
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   479
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   480
void ZNMethodTable::disarm_nmethod(nmethod* nm) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   481
  BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   482
  if (bs != NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   483
    bs->disarm(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   484
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   485
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   486
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   487
void ZNMethodTable::nmethod_entries_do_begin() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   488
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   489
  ZLocker<ZLock> locker(&_iter_lock);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   490
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   491
  // Prepare iteration
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   492
  _iter_table = _table;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   493
  _iter_table_size = _size;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   494
  _claimed = 0;
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   495
  assert(_iter_deferred_deletes.is_empty(), "Should be emtpy");
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   496
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   497
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   498
void ZNMethodTable::nmethod_entries_do_end() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   499
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   500
  ZLocker<ZLock> locker(&_iter_lock);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   501
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   502
  // Finish iteration
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   503
  if (_iter_table != _table) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   504
    delete [] _iter_table;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   505
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   506
  _iter_table = NULL;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   507
  assert(_claimed >= _iter_table_size, "Failed to claim all table entries");
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   508
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   509
  // Process deferred deletes
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   510
  ZArrayIterator<void*> iter(&_iter_deferred_deletes);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   511
  for (void* data; iter.next(&data);) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   512
    FREE_C_HEAP_ARRAY(uint8_t, data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   513
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   514
  _iter_deferred_deletes.clear();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   515
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   516
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   517
void ZNMethodTable::entry_oops_do(ZNMethodTableEntry entry, OopClosure* cl) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   518
  nmethod* const nm = entry.method();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   519
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   520
  // Process oops table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   521
  oop* const begin = nm->oops_begin();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   522
  oop* const end = nm->oops_end();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   523
  for (oop* p = begin; p < end; p++) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   524
    if (*p != Universe::non_oop_word()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   525
      cl->do_oop(p);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   526
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   527
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   528
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   529
  // Process immediate oops
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   530
  if (entry.immediate_oops()) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   531
    const ZNMethodDataImmediateOops* const nmi = gc_data(nm)->immediate_oops();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   532
    if (nmi != NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   533
      oop** const begin = nmi->immediate_oops_begin();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   534
      oop** const end = nmi->immediate_oops_end();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   535
      for (oop** p = begin; p < end; p++) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   536
        if (**p != Universe::non_oop_word()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   537
          cl->do_oop(*p);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   538
        }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   539
      }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   540
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   541
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   542
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   543
  // Process non-immediate oops
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   544
  if (entry.non_immediate_oops()) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   545
    nmethod* const nm = entry.method();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   546
    nm->fix_oop_relocations();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   547
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   548
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   549
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   550
class ZNMethodTableEntryToOopsDo : public ZNMethodTableEntryClosure {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   551
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   552
  OopClosure* _cl;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   553
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   554
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   555
  ZNMethodTableEntryToOopsDo(OopClosure* cl) :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   556
      _cl(cl) {}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   557
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   558
  void do_nmethod_entry(ZNMethodTableEntry entry) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   559
    ZNMethodTable::entry_oops_do(entry, _cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   560
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   561
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   562
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   563
void ZNMethodTable::oops_do(OopClosure* cl) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   564
  ZNMethodTableEntryToOopsDo entry_cl(cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   565
  nmethod_entries_do(&entry_cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   566
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   567
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   568
void ZNMethodTable::nmethod_entries_do(ZNMethodTableEntryClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   569
  for (;;) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   570
    // Claim table partition. Each partition is currently sized to span
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   571
    // two cache lines. This number is just a guess, but seems to work well.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   572
    const size_t partition_size = (ZCacheLineSize * 2) / sizeof(ZNMethodTableEntry);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   573
    const size_t partition_start = MIN2(Atomic::add(partition_size, &_claimed) - partition_size, _iter_table_size);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   574
    const size_t partition_end = MIN2(partition_start + partition_size, _iter_table_size);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   575
    if (partition_start == partition_end) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   576
      // End of table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   577
      break;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   578
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   579
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   580
    // Process table partition
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   581
    for (size_t i = partition_start; i < partition_end; i++) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   582
      const ZNMethodTableEntry entry = _iter_table[i];
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   583
      if (entry.registered()) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   584
        cl->do_nmethod_entry(entry);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   585
      }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   586
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   587
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   588
}
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   589
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   590
class ZNMethodTableUnlinkClosure : public ZNMethodTableEntryClosure {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   591
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   592
  bool          _unloading_occurred;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   593
  volatile bool _failed;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   594
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   595
  void set_failed() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   596
    Atomic::store(true, &_failed);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   597
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   598
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   599
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   600
  ZNMethodTableUnlinkClosure(bool unloading_occurred) :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   601
      _unloading_occurred(unloading_occurred),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   602
      _failed(false) {}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   603
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   604
  virtual void do_nmethod_entry(ZNMethodTableEntry entry) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   605
    if (failed()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   606
      return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   607
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   608
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   609
    nmethod* const nm = entry.method();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   610
    if (!nm->is_alive()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   611
      return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   612
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   613
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   614
    if (nm->is_unloading()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   615
      // Unlinking of the dependencies must happen before the
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   616
      // handshake separating unlink and purge.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   617
      nm->flush_dependencies(false /* delete_immediately */);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   618
      return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   619
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   620
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   621
    ZLocker<ZReentrantLock> locker(ZNMethodTable::lock_for_nmethod(nm));
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   622
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   623
    // Heal oops and disarm
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   624
    ZNMethodOopClosure cl;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   625
    ZNMethodTable::entry_oops_do(entry, &cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   626
    ZNMethodTable::disarm_nmethod(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   627
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   628
    // Clear compiled ICs and exception caches
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   629
    if (!nm->unload_nmethod_caches(_unloading_occurred)) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   630
      set_failed();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   631
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   632
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   633
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   634
  bool failed() const {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   635
    return Atomic::load(&_failed);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   636
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   637
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   638
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   639
class ZNMethodTableUnlinkTask : public ZTask {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   640
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   641
  ZNMethodTableUnlinkClosure _cl;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   642
  ICRefillVerifier*          _verifier;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   643
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   644
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   645
  ZNMethodTableUnlinkTask(bool unloading_occurred, ICRefillVerifier* verifier) :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   646
      ZTask("ZNMethodTableUnlinkTask"),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   647
      _cl(unloading_occurred),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   648
      _verifier(verifier) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   649
    ZNMethodTable::nmethod_entries_do_begin();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   650
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   651
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   652
  ~ZNMethodTableUnlinkTask() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   653
    ZNMethodTable::nmethod_entries_do_end();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   654
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   655
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   656
  virtual void work() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   657
    ICRefillVerifierMark mark(_verifier);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   658
    ZNMethodTable::nmethod_entries_do(&_cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   659
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   660
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   661
  bool success() const {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   662
    return !_cl.failed();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   663
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   664
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   665
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   666
void ZNMethodTable::unlink(ZWorkers* workers, bool unloading_occurred) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   667
  for (;;) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   668
    ICRefillVerifier verifier;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   669
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   670
    {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   671
      ZNMethodTableUnlinkTask task(unloading_occurred, &verifier);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   672
      workers->run_concurrent(&task);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   673
      if (task.success()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   674
        return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   675
      }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   676
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   677
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   678
    // Cleaning failed because we ran out of transitional IC stubs,
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   679
    // so we have to refill and try again. Refilling requires taking
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   680
    // a safepoint, so we temporarily leave the suspendible thread set.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   681
    SuspendibleThreadSetLeaver sts;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   682
    InlineCacheBuffer::refill_ic_stubs();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   683
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   684
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   685
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   686
class ZNMethodTablePurgeClosure : public ZNMethodTableEntryClosure {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   687
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   688
  virtual void do_nmethod_entry(ZNMethodTableEntry entry) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   689
    nmethod* const nm = entry.method();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   690
    if (nm->is_alive() && nm->is_unloading()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   691
      nm->make_unloaded();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   692
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   693
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   694
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   695
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   696
class ZNMethodTablePurgeTask : public ZTask {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   697
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   698
  ZNMethodTablePurgeClosure _cl;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   699
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   700
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   701
  ZNMethodTablePurgeTask() :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   702
      ZTask("ZNMethodTablePurgeTask"),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   703
      _cl() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   704
    ZNMethodTable::nmethod_entries_do_begin();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   705
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   706
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   707
  ~ZNMethodTablePurgeTask() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   708
    ZNMethodTable::nmethod_entries_do_end();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   709
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   710
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   711
  virtual void work() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   712
    ZNMethodTable::nmethod_entries_do(&_cl);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   713
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   714
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   715
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   716
void ZNMethodTable::purge(ZWorkers* workers) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   717
  ZNMethodTablePurgeTask task;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   718
  workers->run_concurrent(&task);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   719
}