g1FromCardCache.hpp revision 9866:e55a12654b8a
12528Sjlahoda/*
22528Sjlahoda * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
32528Sjlahoda * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42528Sjlahoda *
52528Sjlahoda * This code is free software; you can redistribute it and/or modify it
62528Sjlahoda * under the terms of the GNU General Public License version 2 only, as
72528Sjlahoda * published by the Free Software Foundation.
82528Sjlahoda *
92528Sjlahoda * This code is distributed in the hope that it will be useful, but WITHOUT
102528Sjlahoda * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112528Sjlahoda * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
122528Sjlahoda * version 2 for more details (a copy is included in the LICENSE file that
132528Sjlahoda * accompanied this code).
142528Sjlahoda *
152528Sjlahoda * 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#ifndef SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP
26#define SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP
27
28#include "memory/allocation.hpp"
29#include "utilities/ostream.hpp"
30
31// G1FromCardCache remembers the most recently processed card on the heap on
32// a per-region and per-thread basis.
33class G1FromCardCache : public AllStatic {
34 private:
35  // Array of card indices. Indexed by thread X and heap region to minimize
36  // thread contention.
37  static int** _cache;
38  static uint _max_regions;
39  static size_t _static_mem_size;
40
41 public:
42  enum {
43    InvalidCard = -1 // Card value of an invalid card, i.e. a card index not otherwise used.
44  };
45
46  static void clear(uint region_idx);
47
48  // Returns true if the given card is in the cache at the given location, or
49  // replaces the card at that location and returns false.
50  static bool contains_or_replace(uint worker_id, uint region_idx, int card) {
51    int card_in_cache = at(worker_id, region_idx);
52    if (card_in_cache == card) {
53      return true;
54    } else {
55      set(worker_id, region_idx, card);
56      return false;
57    }
58  }
59
60  static int at(uint worker_id, uint region_idx) {
61    return _cache[worker_id][region_idx];
62  }
63
64  static void set(uint worker_id, uint region_idx, int val) {
65    _cache[worker_id][region_idx] = val;
66  }
67
68  static void initialize(uint n_par_rs, uint max_num_regions);
69
70  static void invalidate(uint start_idx, size_t num_regions);
71
72  static void print(outputStream* out = tty) PRODUCT_RETURN;
73
74  static size_t static_mem_size() {
75    return _static_mem_size;
76  }
77};
78
79#endif // SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP
80