hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp
author tschatzl
Mon, 21 Dec 2015 12:02:08 +0100
changeset 35199 a12e8d5aa2f7
child 35200 7802299b31e7
permissions -rw-r--r--
8145667: Move FromCardCache into separate files Reviewed-by: mgerdin, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     1
/*
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     4
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     8
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    14
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    18
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    21
 * questions.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    22
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    23
 */
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    24
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    26
#define SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    27
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    28
#include "memory/allocation.hpp"
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    29
#include "utilities/ostream.hpp"
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    30
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    31
// The FromCardCache remembers the most recently processed card on the heap on
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    32
// a per-region and per-thread basis.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    33
class FromCardCache : public AllStatic {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    34
 private:
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    35
  // Array of card indices. Indexed by thread X and heap region to minimize
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    36
  // thread contention.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    37
  static int** _cache;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    38
  static uint _max_regions;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    39
  static size_t _static_mem_size;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    40
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    41
 public:
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    42
  enum {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    43
    InvalidCard = -1 // Card value of an invalid card, i.e. a card index not otherwise used.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    44
  };
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    45
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    46
  static void clear(uint region_idx);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    47
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    48
  // Returns true if the given card is in the cache at the given location, or
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    49
  // replaces the card at that location and returns false.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    50
  static bool contains_or_replace(uint worker_id, uint region_idx, int card) {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    51
    int card_in_cache = at(worker_id, region_idx);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    52
    if (card_in_cache == card) {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    53
      return true;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    54
    } else {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    55
      set(worker_id, region_idx, card);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    56
      return false;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    57
    }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    58
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    59
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    60
  static int at(uint worker_id, uint region_idx) {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    61
    return _cache[worker_id][region_idx];
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    62
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    63
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    64
  static void set(uint worker_id, uint region_idx, int val) {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    65
    _cache[worker_id][region_idx] = val;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    66
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    67
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    68
  static void initialize(uint n_par_rs, uint max_num_regions);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    69
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    70
  static void invalidate(uint start_idx, size_t num_regions);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    71
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    72
  static void print(outputStream* out = tty) PRODUCT_RETURN;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    73
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    74
  static size_t static_mem_size() {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    75
    return _static_mem_size;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    76
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    77
};
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    78
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    79
#endif // SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP