src/hotspot/share/gc/g1/g1CodeRootSetTable.hpp
author eosterlund
Mon, 26 Feb 2018 09:34:12 +0100
changeset 49164 7e958a8ebcd3
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
permissions -rw-r--r--
8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy Reviewed-by: stefank, coleenp, kvn, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40905
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     1
/*
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     4
 *
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     8
 *
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    14
 *
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    18
 *
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    21
 * questions.
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    22
 */
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    23
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    24
#ifndef SHARE_VM_GC_G1_G1CODEROOTSETTABLE_HPP
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    25
#define SHARE_VM_GC_G1_G1CODEROOTSETTABLE_HPP
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    26
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    27
#include "utilities/hashtable.hpp"
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    28
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    29
class nmethod;
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    30
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    31
class G1CodeRootSetTable : public Hashtable<nmethod*, mtGC> {
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    32
  friend class G1CodeRootSetTest;
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    33
  typedef HashtableEntry<nmethod*, mtGC> Entry;
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    34
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    35
  static G1CodeRootSetTable* volatile _purge_list;
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    36
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    37
  G1CodeRootSetTable* _purge_next;
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    38
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    39
  unsigned int compute_hash(nmethod* nm) {
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    40
    uintptr_t hash = (uintptr_t)nm;
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    41
    return hash ^ (hash >> 7); // code heap blocks are 128byte aligned
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    42
  }
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    43
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    44
  void remove_entry(Entry* e, Entry* previous);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    45
  Entry* new_entry(nmethod* nm);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    46
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    47
 public:
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    48
  G1CodeRootSetTable(int size) : Hashtable<nmethod*, mtGC>(size, sizeof(Entry)), _purge_next(NULL) {}
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    49
  ~G1CodeRootSetTable();
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    50
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    51
  // Needs to be protected by locks
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    52
  bool add(nmethod* nm);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    53
  bool remove(nmethod* nm);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    54
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    55
  // Can be called without locking
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    56
  bool contains(nmethod* nm);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    57
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    58
  int entry_size() const { return BasicHashtable<mtGC>::entry_size(); }
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    59
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    60
  void copy_to(G1CodeRootSetTable* new_table);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    61
  void nmethods_do(CodeBlobClosure* blk);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    62
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    63
  template<typename CB>
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    64
  int remove_if(CB& should_remove);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    65
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    66
  static void purge_list_append(G1CodeRootSetTable* tbl);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    67
  static void purge();
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    68
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    69
  static size_t static_mem_size() {
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    70
    return sizeof(_purge_list);
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    71
  }
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    72
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    73
  size_t mem_size();
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    74
};
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    75
94ffc131534f 8164230: Convert TestCodeCacheRemSet_test to GTest
kzhaldyb
parents:
diff changeset
    76
#endif /* SHARE_VM_GC_G1_G1CODEROOTSETTABLE_HPP */