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