| File: | jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp |
| Warning: | line 221, column 3 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. | |||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||
| 4 | * | |||
| 5 | * This code is free software; you can redistribute it and/or modify it | |||
| 6 | * under the terms of the GNU General Public License version 2 only, as | |||
| 7 | * published by the Free Software Foundation. | |||
| 8 | * | |||
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | |||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |||
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | |||
| 13 | * accompanied this code). | |||
| 14 | * | |||
| 15 | * You should have received a copy of the GNU General Public License version | |||
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | |||
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |||
| 18 | * | |||
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |||
| 20 | * or visit www.oracle.com if you need additional information or have any | |||
| 21 | * questions. | |||
| 22 | * | |||
| 23 | */ | |||
| 24 | ||||
| 25 | #include "precompiled.hpp" | |||
| 26 | #include "code/codeCache.hpp" | |||
| 27 | #include "code/nmethod.hpp" | |||
| 28 | #include "gc/g1/g1CodeRootSetTable.hpp" | |||
| 29 | #include "gc/g1/g1CodeCacheRemSet.hpp" | |||
| 30 | #include "gc/g1/heapRegion.hpp" | |||
| 31 | #include "memory/heap.hpp" | |||
| 32 | #include "memory/iterator.hpp" | |||
| 33 | #include "oops/access.inline.hpp" | |||
| 34 | #include "oops/oop.inline.hpp" | |||
| 35 | #include "runtime/atomic.hpp" | |||
| 36 | #include "services/memTracker.hpp" | |||
| 37 | #include "utilities/hashtable.inline.hpp" | |||
| 38 | #include "utilities/stack.inline.hpp" | |||
| 39 | ||||
| 40 | G1CodeRootSetTable* volatile G1CodeRootSetTable::_purge_list = NULL__null; | |||
| 41 | ||||
| 42 | size_t G1CodeRootSetTable::mem_size() { | |||
| 43 | return sizeof(G1CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size()); | |||
| 44 | } | |||
| 45 | ||||
| 46 | G1CodeRootSetTable::Entry* G1CodeRootSetTable::new_entry(nmethod* nm) { | |||
| 47 | unsigned int hash = compute_hash(nm); | |||
| 48 | return (Entry*)Hashtable<nmethod*, mtGC>::new_entry(hash, nm); | |||
| 49 | } | |||
| 50 | ||||
| 51 | void G1CodeRootSetTable::remove_entry(Entry* e, Entry* previous) { | |||
| 52 | int index = hash_to_index(e->hash()); | |||
| 53 | assert((e == bucket(index)) == (previous == NULL), "if e is the first entry then previous should be null")do { if (!((e == bucket(index)) == (previous == __null))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp" , 53, "assert(" "(e == bucket(index)) == (previous == __null)" ") failed", "if e is the first entry then previous should be null" ); ::breakpoint(); } } while (0); | |||
| 54 | ||||
| 55 | if (previous == NULL__null) { | |||
| 56 | set_entry(index, e->next()); | |||
| 57 | } else { | |||
| 58 | previous->set_next(e->next()); | |||
| 59 | } | |||
| 60 | free_entry(e); | |||
| 61 | } | |||
| 62 | ||||
| 63 | G1CodeRootSetTable::~G1CodeRootSetTable() { | |||
| 64 | for (int index = 0; index < table_size(); ++index) { | |||
| 65 | for (Entry* e = bucket(index); e != NULL__null; ) { | |||
| 66 | Entry* to_remove = e; | |||
| 67 | // read next before freeing. | |||
| 68 | e = e->next(); | |||
| 69 | BasicHashtable<mtGC>::free_entry(to_remove); | |||
| 70 | } | |||
| 71 | } | |||
| 72 | assert(number_of_entries() == 0, "should have removed all entries")do { if (!(number_of_entries() == 0)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp" , 72, "assert(" "number_of_entries() == 0" ") failed", "should have removed all entries" ); ::breakpoint(); } } while (0); | |||
| 73 | } | |||
| 74 | ||||
| 75 | bool G1CodeRootSetTable::add(nmethod* nm) { | |||
| 76 | if (!contains(nm)) { | |||
| 77 | Entry* e = new_entry(nm); | |||
| 78 | int index = hash_to_index(e->hash()); | |||
| 79 | add_entry(index, e); | |||
| 80 | return true; | |||
| 81 | } | |||
| 82 | return false; | |||
| 83 | } | |||
| 84 | ||||
| 85 | bool G1CodeRootSetTable::contains(nmethod* nm) { | |||
| 86 | int index = hash_to_index(compute_hash(nm)); | |||
| 87 | for (Entry* e = bucket(index); e != NULL__null; e = e->next()) { | |||
| 88 | if (e->literal() == nm) { | |||
| 89 | return true; | |||
| 90 | } | |||
| 91 | } | |||
| 92 | return false; | |||
| 93 | } | |||
| 94 | ||||
| 95 | bool G1CodeRootSetTable::remove(nmethod* nm) { | |||
| 96 | int index = hash_to_index(compute_hash(nm)); | |||
| 97 | Entry* previous = NULL__null; | |||
| 98 | for (Entry* e = bucket(index); e != NULL__null; previous = e, e = e->next()) { | |||
| 99 | if (e->literal() == nm) { | |||
| 100 | remove_entry(e, previous); | |||
| 101 | return true; | |||
| 102 | } | |||
| 103 | } | |||
| 104 | return false; | |||
| 105 | } | |||
| 106 | ||||
| 107 | void G1CodeRootSetTable::copy_to(G1CodeRootSetTable* new_table) { | |||
| 108 | for (int index = 0; index < table_size(); ++index) { | |||
| 109 | for (Entry* e = bucket(index); e != NULL__null; e = e->next()) { | |||
| 110 | new_table->add(e->literal()); | |||
| 111 | } | |||
| 112 | } | |||
| 113 | } | |||
| 114 | ||||
| 115 | void G1CodeRootSetTable::nmethods_do(CodeBlobClosure* blk) { | |||
| 116 | for (int index = 0; index < table_size(); ++index) { | |||
| 117 | for (Entry* e = bucket(index); e != NULL__null; e = e->next()) { | |||
| 118 | blk->do_code_blob(e->literal()); | |||
| 119 | } | |||
| 120 | } | |||
| 121 | } | |||
| 122 | ||||
| 123 | template<typename CB> | |||
| 124 | int G1CodeRootSetTable::remove_if(CB& should_remove) { | |||
| 125 | int num_removed = 0; | |||
| 126 | for (int index = 0; index < table_size(); ++index) { | |||
| 127 | Entry* previous = NULL__null; | |||
| 128 | Entry* e = bucket(index); | |||
| 129 | while (e != NULL__null) { | |||
| 130 | Entry* next = e->next(); | |||
| 131 | if (should_remove(e->literal())) { | |||
| 132 | remove_entry(e, previous); | |||
| 133 | ++num_removed; | |||
| 134 | } else { | |||
| 135 | previous = e; | |||
| 136 | } | |||
| 137 | e = next; | |||
| 138 | } | |||
| 139 | } | |||
| 140 | return num_removed; | |||
| 141 | } | |||
| 142 | ||||
| 143 | G1CodeRootSet::~G1CodeRootSet() { | |||
| 144 | delete _table; | |||
| 145 | } | |||
| 146 | ||||
| 147 | G1CodeRootSetTable* G1CodeRootSet::load_acquire_table() { | |||
| 148 | return Atomic::load_acquire(&_table); | |||
| 149 | } | |||
| 150 | ||||
| 151 | void G1CodeRootSet::allocate_small_table() { | |||
| 152 | G1CodeRootSetTable* temp = new G1CodeRootSetTable(SmallSize); | |||
| 153 | ||||
| 154 | Atomic::release_store(&_table, temp); | |||
| 155 | } | |||
| 156 | ||||
| 157 | void G1CodeRootSetTable::purge_list_append(G1CodeRootSetTable* table) { | |||
| 158 | for (;;) { | |||
| 159 | table->_purge_next = _purge_list; | |||
| 160 | G1CodeRootSetTable* old = Atomic::cmpxchg(&_purge_list, table->_purge_next, table); | |||
| 161 | if (old == table->_purge_next) { | |||
| 162 | break; | |||
| 163 | } | |||
| 164 | } | |||
| 165 | } | |||
| 166 | ||||
| 167 | void G1CodeRootSetTable::purge() { | |||
| 168 | G1CodeRootSetTable* table = _purge_list; | |||
| 169 | _purge_list = NULL__null; | |||
| 170 | while (table != NULL__null) { | |||
| 171 | G1CodeRootSetTable* to_purge = table; | |||
| 172 | table = table->_purge_next; | |||
| 173 | delete to_purge; | |||
| 174 | } | |||
| 175 | } | |||
| 176 | ||||
| 177 | void G1CodeRootSet::move_to_large() { | |||
| 178 | G1CodeRootSetTable* temp = new G1CodeRootSetTable(LargeSize); | |||
| 179 | ||||
| 180 | _table->copy_to(temp); | |||
| 181 | ||||
| 182 | G1CodeRootSetTable::purge_list_append(_table); | |||
| 183 | ||||
| 184 | Atomic::release_store(&_table, temp); | |||
| 185 | } | |||
| 186 | ||||
| 187 | void G1CodeRootSet::purge() { | |||
| 188 | G1CodeRootSetTable::purge(); | |||
| 189 | } | |||
| 190 | ||||
| 191 | size_t G1CodeRootSet::static_mem_size() { | |||
| 192 | return G1CodeRootSetTable::static_mem_size(); | |||
| 193 | } | |||
| 194 | ||||
| 195 | void G1CodeRootSet::add(nmethod* method) { | |||
| 196 | bool added = false; | |||
| 197 | if (is_empty()) { | |||
| 198 | allocate_small_table(); | |||
| 199 | } | |||
| 200 | added = _table->add(method); | |||
| 201 | if (added) { | |||
| 202 | if (_length == Threshold) { | |||
| 203 | move_to_large(); | |||
| 204 | } | |||
| 205 | ++_length; | |||
| 206 | } | |||
| 207 | assert(_length == (size_t)_table->number_of_entries(), "sizes should match")do { if (!(_length == (size_t)_table->number_of_entries()) ) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp" , 207, "assert(" "_length == (size_t)_table->number_of_entries()" ") failed", "sizes should match"); ::breakpoint(); } } while (0); | |||
| 208 | } | |||
| 209 | ||||
| 210 | bool G1CodeRootSet::remove(nmethod* method) { | |||
| 211 | bool removed = false; | |||
| 212 | if (_table != NULL__null) { | |||
| ||||
| 213 | removed = _table->remove(method); | |||
| 214 | } | |||
| 215 | if (removed
| |||
| 216 | _length--; | |||
| 217 | if (_length == 0) { | |||
| 218 | clear(); | |||
| 219 | } | |||
| 220 | } | |||
| 221 | assert((_length == 0 && _table == NULL) ||do { if (!((_length == 0 && _table == __null) || (_length == (size_t)_table->number_of_entries()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp" , 222, "assert(" "(_length == 0 && _table == __null) || (_length == (size_t)_table->number_of_entries())" ") failed", "sizes should match"); ::breakpoint(); } } while (0) | |||
| ||||
| 222 | (_length == (size_t)_table->number_of_entries()), "sizes should match")do { if (!((_length == 0 && _table == __null) || (_length == (size_t)_table->number_of_entries()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp" , 222, "assert(" "(_length == 0 && _table == __null) || (_length == (size_t)_table->number_of_entries())" ") failed", "sizes should match"); ::breakpoint(); } } while (0); | |||
| 223 | return removed; | |||
| 224 | } | |||
| 225 | ||||
| 226 | bool G1CodeRootSet::contains(nmethod* method) { | |||
| 227 | G1CodeRootSetTable* table = load_acquire_table(); // contains() may be called outside of lock, so ensure mem sync. | |||
| 228 | if (table != NULL__null) { | |||
| 229 | return table->contains(method); | |||
| 230 | } | |||
| 231 | return false; | |||
| 232 | } | |||
| 233 | ||||
| 234 | void G1CodeRootSet::clear() { | |||
| 235 | delete _table; | |||
| 236 | _table = NULL__null; | |||
| 237 | _length = 0; | |||
| 238 | } | |||
| 239 | ||||
| 240 | size_t G1CodeRootSet::mem_size() { | |||
| 241 | return sizeof(*this) + (_table != NULL__null ? _table->mem_size() : 0); | |||
| 242 | } | |||
| 243 | ||||
| 244 | void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const { | |||
| 245 | if (_table != NULL__null) { | |||
| 246 | _table->nmethods_do(blk); | |||
| 247 | } | |||
| 248 | } | |||
| 249 | ||||
| 250 | class CleanCallback : public StackObj { | |||
| 251 | class PointsIntoHRDetectionClosure : public OopClosure { | |||
| 252 | HeapRegion* _hr; | |||
| 253 | public: | |||
| 254 | bool _points_into; | |||
| 255 | PointsIntoHRDetectionClosure(HeapRegion* hr) : _hr(hr), _points_into(false) {} | |||
| 256 | ||||
| 257 | void do_oop(narrowOop* o) { | |||
| 258 | do_oop_work(o); | |||
| 259 | } | |||
| 260 | ||||
| 261 | void do_oop(oop* o) { | |||
| 262 | do_oop_work(o); | |||
| 263 | } | |||
| 264 | ||||
| 265 | template <typename T> | |||
| 266 | void do_oop_work(T* p) { | |||
| 267 | if (_hr->is_in(RawAccess<>::oop_load(p))) { | |||
| 268 | _points_into = true; | |||
| 269 | } | |||
| 270 | } | |||
| 271 | }; | |||
| 272 | ||||
| 273 | PointsIntoHRDetectionClosure _detector; | |||
| 274 | CodeBlobToOopClosure _blobs; | |||
| 275 | ||||
| 276 | public: | |||
| 277 | CleanCallback(HeapRegion* hr) : _detector(hr), _blobs(&_detector, !CodeBlobToOopClosure::FixRelocations) {} | |||
| 278 | ||||
| 279 | bool operator() (nmethod* nm) { | |||
| 280 | _detector._points_into = false; | |||
| 281 | _blobs.do_code_blob(nm); | |||
| 282 | return !_detector._points_into; | |||
| 283 | } | |||
| 284 | }; | |||
| 285 | ||||
| 286 | void G1CodeRootSet::clean(HeapRegion* owner) { | |||
| 287 | CleanCallback should_clean(owner); | |||
| 288 | if (_table != NULL__null) { | |||
| 289 | int removed = _table->remove_if(should_clean); | |||
| 290 | assert((size_t)removed <= _length, "impossible")do { if (!((size_t)removed <= _length)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp" , 290, "assert(" "(size_t)removed <= _length" ") failed", "impossible" ); ::breakpoint(); } } while (0); | |||
| 291 | _length -= removed; | |||
| 292 | } | |||
| 293 | if (_length == 0) { | |||
| 294 | clear(); | |||
| 295 | } | |||
| 296 | } |