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