src/share/vm/gc_implementation/g1/g1BiasedArray.cpp

Mon, 24 Mar 2014 15:30:14 +0100

author
tschatzl
date
Mon, 24 Mar 2014 15:30:14 +0100
changeset 6402
191174b49bec
parent 5773
a19bea467577
child 6409
5479cb006184
permissions
-rw-r--r--

8035406: Improve data structure for Code Cache remembered sets
Summary: Change the code cache remembered sets data structure from a GrowableArray to a chunked list of nmethods. This makes the data structure more amenable to parallelization, and decreases freeing time.
Reviewed-by: mgerdin, brutisso

     1 /*
     2  * Copyright (c) 2013, 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  */
    25 #include "precompiled.hpp"
    26 #include "gc_implementation/g1/g1BiasedArray.hpp"
    28 #ifndef PRODUCT
    29 void G1BiasedMappedArrayBase::verify_index(idx_t index) const {
    30   guarantee(_base != NULL, "Array not initialized");
    31   guarantee(index < length(), err_msg("Index out of bounds index: "SIZE_FORMAT" length: "SIZE_FORMAT, index, length()));
    32 }
    34 void G1BiasedMappedArrayBase::verify_biased_index(idx_t biased_index) const {
    35   guarantee(_biased_base != NULL, "Array not initialized");
    36   guarantee(biased_index >= bias() && biased_index < (bias() + length()),
    37     err_msg("Biased index out of bounds, index: "SIZE_FORMAT" bias: "SIZE_FORMAT" length: "SIZE_FORMAT, biased_index, bias(), length()));
    38 }
    40 void G1BiasedMappedArrayBase::verify_biased_index_inclusive_end(idx_t biased_index) const {
    41   guarantee(_biased_base != NULL, "Array not initialized");
    42   guarantee(biased_index >= bias() && biased_index <= (bias() + length()),
    43     err_msg("Biased index out of inclusive bounds, index: "SIZE_FORMAT" bias: "SIZE_FORMAT" length: "SIZE_FORMAT, biased_index, bias(), length()));
    44 }
    46 class TestMappedArray : public G1BiasedMappedArray<int> {
    47 protected:
    48   virtual int default_value() const { return 0xBAADBABE; }
    49 public:
    50   static void test_biasedarray() {
    51     const size_t REGION_SIZE_IN_WORDS = 512;
    52     const size_t NUM_REGIONS = 20;
    53     HeapWord* fake_heap = (HeapWord*)LP64_ONLY(0xBAAA00000) NOT_LP64(0xBA000000); // Any value that is non-zero
    55     TestMappedArray array;
    56     array.initialize(fake_heap, fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS,
    57             REGION_SIZE_IN_WORDS * HeapWordSize);
    58     // Check address calculation (bounds)
    59     assert(array.bottom_address_mapped() == fake_heap,
    60       err_msg("bottom mapped address should be "PTR_FORMAT", but is "PTR_FORMAT, fake_heap, array.bottom_address_mapped()));
    61     assert(array.end_address_mapped() == (fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS), "must be");
    63     int* bottom = array.address_mapped_to(fake_heap);
    64     assert((void*)bottom == (void*) array.base(), "must be");
    65     int* end = array.address_mapped_to(fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS);
    66     assert((void*)end == (void*)(array.base() + array.length()), "must be");
    67     // The entire array should contain default value elements
    68     for (int* current = bottom; current < end; current++) {
    69       assert(*current == array.default_value(), "must be");
    70     }
    72     // Test setting values in the table
    74     HeapWord* region_start_address = fake_heap + REGION_SIZE_IN_WORDS * (NUM_REGIONS / 2);
    75     HeapWord* region_end_address = fake_heap + (REGION_SIZE_IN_WORDS * (NUM_REGIONS / 2) + REGION_SIZE_IN_WORDS - 1);
    77     // Set/get by address tests: invert some value; first retrieve one
    78     int actual_value = array.get_by_index(NUM_REGIONS / 2);
    79     array.set_by_index(NUM_REGIONS / 2, ~actual_value);
    80     // Get the same value by address, should correspond to the start of the "region"
    81     int value = array.get_by_address(region_start_address);
    82     assert(value == ~actual_value, "must be");
    83     // Get the same value by address, at one HeapWord before the start
    84     value = array.get_by_address(region_start_address - 1);
    85     assert(value == array.default_value(), "must be");
    86     // Get the same value by address, at the end of the "region"
    87     value = array.get_by_address(region_end_address);
    88     assert(value == ~actual_value, "must be");
    89     // Make sure the next value maps to another index
    90     value = array.get_by_address(region_end_address + 1);
    91     assert(value == array.default_value(), "must be");
    93     // Reset the value in the array
    94     array.set_by_address(region_start_address + (region_end_address - region_start_address) / 2, actual_value);
    96     // The entire array should have the default value again
    97     for (int* current = bottom; current < end; current++) {
    98       assert(*current == array.default_value(), "must be");
    99     }
   101     // Set/get by index tests: invert some value
   102     idx_t index = NUM_REGIONS / 2;
   103     actual_value = array.get_by_index(index);
   104     array.set_by_index(index, ~actual_value);
   106     value = array.get_by_index(index);
   107     assert(value == ~actual_value, "must be");
   109     value = array.get_by_index(index - 1);
   110     assert(value == array.default_value(), "must be");
   112     value = array.get_by_index(index + 1);
   113     assert(value == array.default_value(), "must be");
   115     array.set_by_index(0, 0);
   116     value = array.get_by_index(0);
   117     assert(value == 0, "must be");
   119     array.set_by_index(array.length() - 1, 0);
   120     value = array.get_by_index(array.length() - 1);
   121     assert(value == 0, "must be");
   123     array.set_by_index(index, 0);
   125     // The array should have three zeros, and default values otherwise
   126     size_t num_zeros = 0;
   127     for (int* current = bottom; current < end; current++) {
   128       assert(*current == array.default_value() || *current == 0, "must be");
   129       if (*current == 0) {
   130         num_zeros++;
   131       }
   132     }
   133     assert(num_zeros == 3, "must be");
   134   }
   135 };
   137 void TestG1BiasedArray_test() {
   138   TestMappedArray::test_biasedarray();
   139 }
   141 #endif

mercurial