src/hotspot/share/gc/z/zNMethodTable.cpp
author stefank
Wed, 20 Feb 2019 11:39:36 +0100
changeset 53891 29273bb37241
parent 53890 70a6a7b15d36
child 53892 33790c8e4647
permissions -rw-r--r--
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class Reviewed-by: pliden
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
/*
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     4
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     8
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    13
 * accompanied this code).
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    14
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    18
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    21
 * questions.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    22
 */
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    23
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    24
#include "precompiled.hpp"
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"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    30
#include "gc/z/zGlobals.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    31
#include "gc/z/zHash.inline.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    32
#include "gc/z/zLock.inline.hpp"
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
    33
#include "gc/z/zNMethodAllocator.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"
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
    39
#include "memory/allocation.hpp"
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    40
#include "memory/iterator.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    41
#include "memory/resourceArea.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    42
#include "runtime/atomic.hpp"
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    43
#include "runtime/orderAccess.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
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    46
class ZNMethodDataOops {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    47
private:
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    48
  const size_t _nimmediates;
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    49
  bool         _has_non_immediates;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    50
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    51
  static size_t header_size();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    52
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    53
  ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    54
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    55
public:
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    56
  static ZNMethodDataOops* create(const GrowableArray<oop*>& immediates, bool has_non_immediates);
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    57
  static void destroy(ZNMethodDataOops* oops);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    58
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    59
  size_t immediates_count() const;
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    60
  oop** immediates_begin() const;
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    61
  oop** immediates_end() const;
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    62
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    63
  bool has_non_immediates() const;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    64
};
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    65
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    66
size_t ZNMethodDataOops::header_size() {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    67
  const size_t size = sizeof(ZNMethodDataOops);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    68
  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
    69
  return size;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    70
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    71
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    72
ZNMethodDataOops* ZNMethodDataOops::create(const GrowableArray<oop*>& immediates, bool has_non_immediates) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    73
  // Allocate memory for the ZNMethodDataOops object
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    74
  // plus the immediate oop* array that follows right after.
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    75
  const size_t size = ZNMethodDataOops::header_size() + (sizeof(oop*) * immediates.length());
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
    76
  void* const mem = ZNMethodAllocator::allocate(size);
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
    77
  return ::new (mem) ZNMethodDataOops(immediates, has_non_immediates);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    78
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    79
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    80
void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) {
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
    81
  ZNMethodAllocator::free(oops);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    82
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
    83
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    84
ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) :
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    85
    _nimmediates(immediates.length()),
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    86
    _has_non_immediates(has_non_immediates) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    87
  // Save all immediate oops
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    88
  for (size_t i = 0; i < _nimmediates; i++) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    89
    immediates_begin()[i] = immediates.at(i);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    90
  }
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
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    93
size_t ZNMethodDataOops::immediates_count() const {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    94
  return _nimmediates;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    95
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    96
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
    97
oop** ZNMethodDataOops::immediates_begin() const {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    98
  // 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
    99
  return (oop**)((uintptr_t)this + header_size());
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
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   102
oop** ZNMethodDataOops::immediates_end() const {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   103
  return immediates_begin() + immediates_count();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   104
}
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   105
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   106
bool ZNMethodDataOops::has_non_immediates() const {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   107
  return _has_non_immediates;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   108
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   109
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   110
class ZNMethodData {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   111
private:
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   112
  ZReentrantLock             _lock;
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   113
  ZNMethodDataOops* volatile _oops;
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   114
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   115
  ZNMethodData(nmethod* nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   116
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   117
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   118
  static ZNMethodData* create(nmethod* nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   119
  static void destroy(ZNMethodData* data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   120
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   121
  ZReentrantLock* lock();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   122
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   123
  ZNMethodDataOops* oops() const;
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   124
  ZNMethodDataOops* swap_oops(ZNMethodDataOops* oops);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   125
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   126
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   127
ZNMethodData* ZNMethodData::create(nmethod* nm) {
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   128
  void* const mem = ZNMethodAllocator::allocate(sizeof(ZNMethodData));
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   129
  return ::new (mem) ZNMethodData(nm);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   130
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   131
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   132
void ZNMethodData::destroy(ZNMethodData* data) {
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   133
  ZNMethodAllocator::free(data->oops());
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   134
  ZNMethodAllocator::free(data);
52939
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
ZNMethodData::ZNMethodData(nmethod* nm) :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   138
    _lock(),
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   139
    _oops(NULL) {}
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   140
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   141
ZReentrantLock* ZNMethodData::lock() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   142
  return &_lock;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   143
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   144
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   145
ZNMethodDataOops* ZNMethodData::oops() const {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   146
  return OrderAccess::load_acquire(&_oops);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   147
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   148
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   149
ZNMethodDataOops* ZNMethodData::swap_oops(ZNMethodDataOops* new_oops) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   150
  return Atomic::xchg(new_oops, &_oops);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   151
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   152
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   153
static ZNMethodData* gc_data(const nmethod* nm) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   154
  return nm->gc_data<ZNMethodData>();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   155
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   156
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   157
static void set_gc_data(nmethod* nm, ZNMethodData* data) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   158
  return nm->set_gc_data<ZNMethodData>(data);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   159
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   160
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   161
ZNMethodTableEntry* ZNMethodTable::_table = NULL;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   162
size_t ZNMethodTable::_size = 0;
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   163
ZNMethodTableEntry* ZNMethodTable::_iter_table = NULL;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   164
size_t ZNMethodTable::_iter_table_size = 0;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   165
size_t ZNMethodTable::_nregistered = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   166
size_t ZNMethodTable::_nunregistered = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   167
volatile size_t ZNMethodTable::_claimed = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   168
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   169
void ZNMethodTable::attach_gc_data(nmethod* nm) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   170
  GrowableArray<oop*> immediate_oops;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   171
  bool non_immediate_oops = false;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   172
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   173
  // Find all oops relocations
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   174
  RelocIterator iter(nm);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   175
  while (iter.next()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   176
    if (iter.type() != relocInfo::oop_type) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   177
      // Not an oop
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   178
      continue;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   179
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   180
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   181
    oop_Relocation* r = iter.oop_reloc();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   182
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   183
    if (!r->oop_is_immediate()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   184
      // Non-immediate oop found
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   185
      non_immediate_oops = true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   186
      continue;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   187
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   188
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   189
    if (r->oop_value() != NULL) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   190
      // 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
   191
      // 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
   192
      // are later patched to be non-NULL.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   193
      immediate_oops.push(r->oop_addr());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   194
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   195
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   196
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   197
  // Attach GC data to nmethod
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   198
  ZNMethodData* data = gc_data(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   199
  if (data == NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   200
    data = ZNMethodData::create(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   201
    set_gc_data(nm, data);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   202
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   203
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   204
  // Attach oops in GC data
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   205
  ZNMethodDataOops* const new_oops = ZNMethodDataOops::create(immediate_oops, non_immediate_oops);
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   206
  ZNMethodDataOops* const old_oops = data->swap_oops(new_oops);
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   207
  ZNMethodDataOops::destroy(old_oops);
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   208
}
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   209
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   210
void ZNMethodTable::detach_gc_data(nmethod* nm) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   211
  // Destroy GC data
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   212
  ZNMethodData::destroy(gc_data(nm));
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   213
  set_gc_data(nm, NULL);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   214
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   215
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   216
ZReentrantLock* ZNMethodTable::lock_for_nmethod(nmethod* nm) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   217
  ZNMethodData* const data = gc_data(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   218
  if (data == NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   219
    return NULL;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   220
  }
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   221
  return data->lock();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   222
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   223
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   224
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
   225
  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
   226
  const size_t mask = size - 1;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   227
  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
   228
  return hash & mask;
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::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
   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
  return (prev_index + 1) & mask;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   235
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   236
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   237
bool ZNMethodTable::register_entry(ZNMethodTableEntry* table, size_t size, nmethod* nm) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   238
  const ZNMethodTableEntry entry(nm);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   239
  size_t index = first_index(nm, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   240
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   241
  for (;;) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   242
    const ZNMethodTableEntry table_entry = table[index];
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
    if (!table_entry.registered() && !table_entry.unregistered()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   245
      // Insert new entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   246
      table[index] = entry;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   247
      return true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   248
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   249
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   250
    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
   251
      // Replace existing entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   252
      table[index] = entry;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   253
      return false;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   254
    }
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
    index = next_index(index, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   257
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   258
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   259
53500
f618cfbaf35b 8217309: ZGC: Fix ZNMethodTable corruption
pliden
parents: 53282
diff changeset
   260
void 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
   261
  size_t index = first_index(nm, size);
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
  for (;;) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   264
    const ZNMethodTableEntry table_entry = table[index];
53500
f618cfbaf35b 8217309: ZGC: Fix ZNMethodTable corruption
pliden
parents: 53282
diff changeset
   265
    assert(table_entry.registered() || table_entry.unregistered(), "Entry not found");
50525
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
    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
   268
      // Remove entry
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   269
      table[index] = ZNMethodTableEntry(true /* unregistered */);
53500
f618cfbaf35b 8217309: ZGC: Fix ZNMethodTable corruption
pliden
parents: 53282
diff changeset
   270
      return;
50525
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
    index = next_index(index, 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
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   276
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   277
void ZNMethodTable::rebuild(size_t new_size) {
53888
a858ad440eb9 8219463: ZGC: Remove redundant ZNMethodTable::_iter_lock
stefank
parents: 53887
diff changeset
   278
  assert(CodeCache_lock->owned_by_self(), "Lock must be held");
a858ad440eb9 8219463: ZGC: Remove redundant ZNMethodTable::_iter_lock
stefank
parents: 53887
diff changeset
   279
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   280
  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
   281
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   282
  log_debug(gc, nmethod)("Rebuilding NMethod Table: "
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   283
                         SIZE_FORMAT "->" SIZE_FORMAT " entries, "
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   284
                         SIZE_FORMAT "(%.0lf%%->%.0lf%%) registered, "
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   285
                         SIZE_FORMAT "(%.0lf%%->%.0lf%%) unregistered",
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   286
                         _size, new_size,
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   287
                         _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
   288
                         _nunregistered, percent_of(_nunregistered, _size), 0.0);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   289
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   290
  // Allocate new table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   291
  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
   292
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   293
  // Transfer all registered entries
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   294
  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
   295
    const ZNMethodTableEntry entry = _table[i];
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   296
    if (entry.registered()) {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   297
      register_entry(new_table, new_size, entry.method());
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   298
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   299
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   300
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   301
  if (_iter_table != _table) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   302
    // Delete old table
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   303
    delete [] _table;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   304
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   305
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   306
  // Install new table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   307
  _table = new_table;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   308
  _size = new_size;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   309
  _nunregistered = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   310
}
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
void ZNMethodTable::rebuild_if_needed() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   313
  // 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
   314
  // 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
   315
  // 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
   316
  // 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
   317
  // 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
   318
  const size_t min_size = 1024;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   319
  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
   320
  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
   321
  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
   322
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   323
  if (_size == 0) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   324
    // Initialize table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   325
    rebuild(min_size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   326
  } 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
   327
    // Shrink table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   328
    rebuild(_size / 2);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   329
  } else if (_nregistered + _nunregistered > grow_threshold) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   330
    // Prune or grow table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   331
    if (_nregistered < prune_threshold) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   332
      // Prune table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   333
      rebuild(_size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   334
    } else {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   335
      // Grow table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   336
      rebuild(_size * 2);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   337
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   338
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   339
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   340
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   341
void ZNMethodTable::log_register(const nmethod* nm) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   342
  LogTarget(Trace, gc, nmethod) log;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   343
  if (!log.is_enabled()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   344
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   345
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   346
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   347
  const ZNMethodDataOops* const oops = gc_data(nm)->oops();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   348
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   349
  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
   350
            "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
   351
            nm->method()->method_holder()->external_name(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   352
            nm->method()->name()->as_C_string(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   353
            p2i(nm),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   354
            nm->compiler_name(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   355
            nm->oops_count() - 1,
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   356
            oops->immediates_count(),
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   357
            oops->has_non_immediates() ? "Yes" : "No");
50525
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
  LogTarget(Trace, gc, nmethod, oops) log_oops;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   360
  if (!log_oops.is_enabled()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   361
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   362
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   363
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   364
  // Print nmethod oops table
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   365
  {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   366
    oop* const begin = nm->oops_begin();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   367
    oop* const end = nm->oops_end();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   368
    for (oop* p = begin; p < end; p++) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   369
      log_oops.print("           Oop[" SIZE_FORMAT "] " PTR_FORMAT " (%s)",
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   370
                     (p - begin), p2i(*p), (*p)->klass()->external_name());
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   371
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   372
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   373
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   374
  // Print nmethod immediate oops
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   375
  {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   376
    oop** const begin = oops->immediates_begin();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   377
    oop** const end = oops->immediates_end();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   378
    for (oop** p = begin; p < end; p++) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   379
      log_oops.print("  ImmediateOop[" SIZE_FORMAT "] " PTR_FORMAT " @ " PTR_FORMAT " (%s)",
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   380
                     (p - begin), p2i(**p), p2i(*p), (**p)->klass()->external_name());
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   381
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   382
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   383
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   384
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   385
void ZNMethodTable::log_unregister(const nmethod* nm) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   386
  LogTarget(Debug, gc, nmethod) log;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   387
  if (!log.is_enabled()) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   388
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   389
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   390
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   391
  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
   392
            nm->method()->method_holder()->external_name(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   393
            nm->method()->name()->as_C_string(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   394
            p2i(nm));
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   395
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   396
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   397
size_t ZNMethodTable::registered_nmethods() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   398
  return _nregistered;
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
size_t ZNMethodTable::unregistered_nmethods() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   402
  return _nunregistered;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   403
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   404
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   405
void ZNMethodTable::register_nmethod(nmethod* nm) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   406
  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
   407
  ResourceMark rm;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   408
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   409
  // Grow/Shrink/Prune table if needed
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   410
  rebuild_if_needed();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   411
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   412
  // Create and attach gc data
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   413
  attach_gc_data(nm);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   414
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   415
  log_register(nm);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   416
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   417
  // Insert new entry
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   418
  if (register_entry(_table, _size, nm)) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   419
    // 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
   420
    // 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
   421
    // 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
   422
    _nregistered++;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   423
  }
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   424
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   425
  // Disarm nmethod entry barrier
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   426
  disarm_nmethod(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   427
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   428
53887
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   429
void ZNMethodTable::wait_until_iteration_done() {
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   430
  assert(CodeCache_lock->owned_by_self(), "Lock must be held");
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   431
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   432
  while (_iter_table != NULL) {
53887
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   433
    CodeCache_lock->wait(Monitor::_no_safepoint_check_flag);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   434
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   435
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   436
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   437
void ZNMethodTable::unregister_nmethod(nmethod* nm) {
53500
f618cfbaf35b 8217309: ZGC: Fix ZNMethodTable corruption
pliden
parents: 53282
diff changeset
   438
  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
   439
53887
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   440
  if (Thread::current()->is_Code_cache_sweeper_thread()) {
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   441
    // The sweeper must wait for any ongoing iteration to complete
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   442
    // before it can unregister an nmethod.
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   443
    ZNMethodTable::wait_until_iteration_done();
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   444
  }
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   445
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   446
  ResourceMark rm;
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   447
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   448
  log_unregister(nm);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   449
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   450
  // Remove entry
53500
f618cfbaf35b 8217309: ZGC: Fix ZNMethodTable corruption
pliden
parents: 53282
diff changeset
   451
  unregister_entry(_table, _size, nm);
f618cfbaf35b 8217309: ZGC: Fix ZNMethodTable corruption
pliden
parents: 53282
diff changeset
   452
  _nunregistered++;
f618cfbaf35b 8217309: ZGC: Fix ZNMethodTable corruption
pliden
parents: 53282
diff changeset
   453
  _nregistered--;
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   454
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   455
  detach_gc_data(nm);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   456
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   457
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   458
void ZNMethodTable::disarm_nmethod(nmethod* nm) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   459
  BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   460
  if (bs != NULL) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   461
    bs->disarm(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   462
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   463
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   464
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   465
void ZNMethodTable::nmethods_do_begin() {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   466
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   467
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   468
  // Make sure we don't free data while iterating
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   469
  ZNMethodAllocator::activate_deferred_frees();
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   470
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   471
  // Prepare iteration
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   472
  _iter_table = _table;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   473
  _iter_table_size = _size;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   474
  _claimed = 0;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   475
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   476
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   477
void ZNMethodTable::nmethods_do_end() {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   478
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   479
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   480
  // Finish iteration
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   481
  if (_iter_table != _table) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   482
    delete [] _iter_table;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   483
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   484
  _iter_table = NULL;
53887
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   485
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   486
  assert(_claimed >= _iter_table_size, "Failed to claim all table entries");
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   487
53891
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   488
  // Process deferred frees
29273bb37241 8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents: 53890
diff changeset
   489
  ZNMethodAllocator::deactivate_and_process_deferred_frees();
53887
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   490
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   491
  // Notify iteration done
2e1896987ed8 8219462: ZGC: Use wait/notify in ZNMethodTable
stefank
parents: 53500
diff changeset
   492
  CodeCache_lock->notify_all();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   493
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   494
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   495
void ZNMethodTable::oops_do(nmethod* nm, OopClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   496
  // Process oops table
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   497
  {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   498
    oop* const begin = nm->oops_begin();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   499
    oop* const end = nm->oops_end();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   500
    for (oop* p = begin; p < end; p++) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   501
      if (*p != Universe::non_oop_word()) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   502
        cl->do_oop(p);
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   503
      }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   504
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   505
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   506
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   507
  ZNMethodDataOops* const oops = gc_data(nm)->oops();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   508
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   509
  // Process immediate oops
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   510
  {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   511
    oop** const begin = oops->immediates_begin();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   512
    oop** const end = oops->immediates_end();
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   513
    for (oop** p = begin; p < end; p++) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   514
      if (**p != Universe::non_oop_word()) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   515
        cl->do_oop(*p);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   516
      }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   517
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   518
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   519
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   520
  // Process non-immediate oops
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   521
  if (oops->has_non_immediates()) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   522
    nm->fix_oop_relocations();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   523
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   524
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   525
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   526
class ZNMethodToOopsDoClosure : public NMethodClosure {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   527
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   528
  OopClosure* _cl;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   529
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   530
public:
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   531
  ZNMethodToOopsDoClosure(OopClosure* cl) :
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   532
      _cl(cl) {}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   533
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   534
  virtual void do_nmethod(nmethod* nm) {
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   535
    ZNMethodTable::oops_do(nm, _cl);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   536
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   537
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   538
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   539
void ZNMethodTable::oops_do(OopClosure* cl) {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   540
  ZNMethodToOopsDoClosure nm_cl(cl);
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   541
  nmethods_do(&nm_cl);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   542
}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   543
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   544
void ZNMethodTable::nmethods_do(NMethodClosure* cl) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   545
  for (;;) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   546
    // 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
   547
    // 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
   548
    const size_t partition_size = (ZCacheLineSize * 2) / sizeof(ZNMethodTableEntry);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   549
    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
   550
    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
   551
    if (partition_start == partition_end) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   552
      // End of table
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   553
      break;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   554
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   555
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   556
    // Process table partition
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   557
    for (size_t i = partition_start; i < partition_end; i++) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   558
      const ZNMethodTableEntry entry = _iter_table[i];
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   559
      if (entry.registered()) {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   560
        cl->do_nmethod(entry.method());
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   561
      }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   562
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   563
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   564
}
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   565
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   566
class ZNMethodTableUnlinkClosure : public NMethodClosure {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   567
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   568
  bool          _unloading_occurred;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   569
  volatile bool _failed;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   570
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   571
  void set_failed() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   572
    Atomic::store(true, &_failed);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   573
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   574
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   575
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   576
  ZNMethodTableUnlinkClosure(bool unloading_occurred) :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   577
      _unloading_occurred(unloading_occurred),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   578
      _failed(false) {}
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   579
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   580
  virtual void do_nmethod(nmethod* nm) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   581
    if (failed()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   582
      return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   583
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   584
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   585
    if (!nm->is_alive()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   586
      return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   587
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   588
53282
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
   589
    ZLocker<ZReentrantLock> locker(ZNMethodTable::lock_for_nmethod(nm));
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
   590
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   591
    if (nm->is_unloading()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   592
      // Unlinking of the dependencies must happen before the
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   593
      // handshake separating unlink and purge.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   594
      nm->flush_dependencies(false /* delete_immediately */);
53282
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
   595
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
   596
      // We don't need to take the lock when unlinking nmethods from
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
   597
      // the Method, because it is only concurrently unlinked by
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
   598
      // the entry barrier, which acquires the per nmethod lock.
cb7fff9105a8 8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents: 52939
diff changeset
   599
      nm->unlink_from_method(false /* acquire_lock */);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   600
      return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   601
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   602
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   603
    // Heal oops and disarm
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   604
    ZNMethodOopClosure cl;
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   605
    ZNMethodTable::oops_do(nm, &cl);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   606
    ZNMethodTable::disarm_nmethod(nm);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   607
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   608
    // Clear compiled ICs and exception caches
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   609
    if (!nm->unload_nmethod_caches(_unloading_occurred)) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   610
      set_failed();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   611
    }
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
  bool failed() const {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   615
    return Atomic::load(&_failed);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   616
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   617
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   618
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   619
class ZNMethodTableUnlinkTask : public ZTask {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   620
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   621
  ZNMethodTableUnlinkClosure _cl;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   622
  ICRefillVerifier*          _verifier;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   623
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   624
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   625
  ZNMethodTableUnlinkTask(bool unloading_occurred, ICRefillVerifier* verifier) :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   626
      ZTask("ZNMethodTableUnlinkTask"),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   627
      _cl(unloading_occurred),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   628
      _verifier(verifier) {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   629
    ZNMethodTable::nmethods_do_begin();
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   630
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   631
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   632
  ~ZNMethodTableUnlinkTask() {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   633
    ZNMethodTable::nmethods_do_end();
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   634
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   635
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   636
  virtual void work() {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   637
    ICRefillVerifierMark mark(_verifier);
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   638
    ZNMethodTable::nmethods_do(&_cl);
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   639
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   640
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   641
  bool success() const {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   642
    return !_cl.failed();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   643
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   644
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   645
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   646
void ZNMethodTable::unlink(ZWorkers* workers, bool unloading_occurred) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   647
  for (;;) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   648
    ICRefillVerifier verifier;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   649
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   650
    {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   651
      ZNMethodTableUnlinkTask task(unloading_occurred, &verifier);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   652
      workers->run_concurrent(&task);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   653
      if (task.success()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   654
        return;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   655
      }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   656
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   657
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   658
    // Cleaning failed because we ran out of transitional IC stubs,
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   659
    // so we have to refill and try again. Refilling requires taking
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   660
    // a safepoint, so we temporarily leave the suspendible thread set.
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   661
    SuspendibleThreadSetLeaver sts;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   662
    InlineCacheBuffer::refill_ic_stubs();
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
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   666
class ZNMethodTablePurgeClosure : public NMethodClosure {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   667
public:
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   668
  virtual void do_nmethod(nmethod* nm) {
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   669
    if (nm->is_alive() && nm->is_unloading()) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   670
      nm->make_unloaded();
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   671
    }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   672
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   673
};
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   674
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   675
class ZNMethodTablePurgeTask : public ZTask {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   676
private:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   677
  ZNMethodTablePurgeClosure _cl;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   678
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   679
public:
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   680
  ZNMethodTablePurgeTask() :
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   681
      ZTask("ZNMethodTablePurgeTask"),
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   682
      _cl() {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   683
    ZNMethodTable::nmethods_do_begin();
52939
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
  ~ZNMethodTablePurgeTask() {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   687
    ZNMethodTable::nmethods_do_end();
52939
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   688
  }
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   689
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   690
  virtual void work() {
53890
70a6a7b15d36 8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents: 53888
diff changeset
   691
    ZNMethodTable::nmethods_do(&_cl);
52939
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
void ZNMethodTable::purge(ZWorkers* workers) {
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   696
  ZNMethodTablePurgeTask task;
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   697
  workers->run_concurrent(&task);
9a8585f60c32 8214897: ZGC: Concurrent Class Unloading
eosterlund
parents: 52410
diff changeset
   698
}