| 1 | /* |
| 2 | * Copyright (c) 2016, 2019, 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 | #ifndef SHARE_GC_G1_G1CODEROOTSETTABLE_HPP |
| 25 | #define SHARE_GC_G1_G1CODEROOTSETTABLE_HPP |
| 26 | |
| 27 | #include "utilities/hashtable.hpp" |
| 28 | |
| 29 | class nmethod; |
| 30 | |
| 31 | class G1CodeRootSetTable : public Hashtable<nmethod*, mtGC> { |
| 32 | friend class G1CodeRootSetTest; |
| 33 | typedef HashtableEntry<nmethod*, mtGC> Entry; |
| 34 | |
| 35 | static G1CodeRootSetTable* volatile _purge_list; |
| 36 | |
| 37 | G1CodeRootSetTable* _purge_next; |
| 38 | |
| 39 | unsigned int compute_hash(nmethod* nm) { |
| 40 | uintptr_t hash = (uintptr_t)nm; |
| 41 | return hash ^ (hash >> 7); // code heap blocks are 128byte aligned |
| 42 | } |
| 43 | |
| 44 | void remove_entry(Entry* e, Entry* previous); |
| 45 | Entry* new_entry(nmethod* nm); |
| 46 | |
| 47 | public: |
| 48 | G1CodeRootSetTable(int size) : Hashtable<nmethod*, mtGC>(size, sizeof(Entry)), _purge_next(NULL) {} |
| 49 | ~G1CodeRootSetTable(); |
| 50 | |
| 51 | // Needs to be protected by locks |
| 52 | bool add(nmethod* nm); |
| 53 | bool remove(nmethod* nm); |
| 54 | |
| 55 | // Can be called without locking |
| 56 | bool contains(nmethod* nm); |
| 57 | |
| 58 | int entry_size() const { return BasicHashtable<mtGC>::entry_size(); } |
| 59 | |
| 60 | void copy_to(G1CodeRootSetTable* new_table); |
| 61 | void nmethods_do(CodeBlobClosure* blk); |
| 62 | |
| 63 | template<typename CB> |
| 64 | int remove_if(CB& should_remove); |
| 65 | |
| 66 | static void purge_list_append(G1CodeRootSetTable* tbl); |
| 67 | static void purge(); |
| 68 | |
| 69 | static size_t static_mem_size() { |
| 70 | return sizeof(_purge_list); |
| 71 | } |
| 72 | |
| 73 | size_t mem_size(); |
| 74 | }; |
| 75 | |
| 76 | #endif // SHARE_GC_G1_G1CODEROOTSETTABLE_HPP |
| 77 | |