test/hotspot/gtest/utilities/test_bitMap_large.cpp
author shade
Sat, 10 Nov 2018 20:47:28 +0100
changeset 52485 e5534cc91a10
permissions -rw-r--r--
8211926: Catastrophic size_t underflow in BitMap::*_large methods Reviewed-by: kbarrett, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52485
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     1
/*
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     2
 * Copyright (c) 2018, Red Hat Inc. All rights reserved.
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     4
 *
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     8
 *
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    13
 * accompanied this code).
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    14
 *
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    18
 *
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    21
 * questions.
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    22
 */
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    23
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    24
#include "precompiled.hpp"
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    25
#include "utilities/bitMap.inline.hpp"
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    26
#include "unittest.hpp"
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    27
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    28
// Bitmap size should be large enough to accept large operations.
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    29
static const BitMap::idx_t BITMAP_SIZE = 8192;
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    30
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    31
// The test would like to fuzz indexes in this window. Having the fuzz
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    32
// window at bitmap word size makes sure the test would touch every combination
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    33
// of indexes (un)aligned on word boundary.
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    34
static const BitMap::idx_t FUZZ_WINDOW = sizeof(BitMap::bm_word_t) * 8;
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    35
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    36
static void verify_set(CHeapBitMap& map, BitMap::idx_t l, BitMap::idx_t r) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    37
  for (BitMap::idx_t c = l; c < r; c++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    38
    EXPECT_TRUE(map.at(c));
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    39
  }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    40
}
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    41
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    42
static void verify_unset(CHeapBitMap& map, BitMap::idx_t l, BitMap::idx_t r) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    43
  for (BitMap::idx_t c = l; c < r; c++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    44
    EXPECT_FALSE(map.at(c));
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    45
  }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    46
}
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    47
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    48
TEST(BitMap, clear_large_range) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    49
  CHeapBitMap map(BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    50
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    51
  map.set_range(0, BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    52
  verify_set(map, 0, BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    53
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    54
  for (size_t size_class = 0; size_class <= BITMAP_SIZE; size_class = MAX2<size_t>(1, size_class*2)) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    55
    for (BitMap::idx_t l = 0; l < FUZZ_WINDOW; l++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    56
      for (BitMap::idx_t tr = l; tr < FUZZ_WINDOW; tr++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    57
        BitMap::idx_t r = MIN2(BITMAP_SIZE, size_class + tr); // avoid overflow
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    58
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    59
        map.clear_large_range(l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    60
        verify_unset(map, l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    61
        verify_set(map, 0, l);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    62
        verify_set(map, r, BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    63
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    64
        // Restore cleared
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    65
        map.set_range(l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    66
        verify_set(map, l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    67
      }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    68
    }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    69
  }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    70
}
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    71
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    72
TEST(BitMap, set_large_range) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    73
  CHeapBitMap map(BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    74
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    75
  map.clear();
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    76
  verify_unset(map, 0, BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    77
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    78
  for (size_t size_class = 0; size_class <= BITMAP_SIZE; size_class = MAX2<size_t>(1, size_class*2)) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    79
    for (BitMap::idx_t l = 0; l < FUZZ_WINDOW; l++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    80
      for (BitMap::idx_t tr = l; tr < FUZZ_WINDOW; tr++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    81
        BitMap::idx_t r = MIN2(BITMAP_SIZE, size_class + tr); // avoid overflow
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    82
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    83
        map.set_large_range(l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    84
        verify_set(map, l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    85
        verify_unset(map, 0, l);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    86
        verify_unset(map, r, BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    87
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    88
        // Restore set
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    89
        map.clear_range(l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    90
        verify_unset(map, l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    91
      }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    92
    }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    93
  }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    94
}
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    95
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    96
TEST(BitMap, par_at_put_large_range) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    97
  CHeapBitMap map(BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    98
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
    99
  map.clear();
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   100
  verify_unset(map, 0, BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   101
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   102
  for (size_t size_class = 0; size_class <= BITMAP_SIZE; size_class = MAX2<size_t>(1, size_class*2)) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   103
    for (BitMap::idx_t l = 0; l < FUZZ_WINDOW; l++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   104
      for (BitMap::idx_t tr = l; tr < FUZZ_WINDOW; tr++) {
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   105
        BitMap::idx_t r = MIN2(BITMAP_SIZE, size_class + tr); // avoid overflow
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   106
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   107
        map.par_at_put_large_range(l, r, true);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   108
        verify_set(map, l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   109
        verify_unset(map, 0, l);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   110
        verify_unset(map, r, BITMAP_SIZE);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   111
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   112
        // Restore set
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   113
        map.clear_range(l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   114
        verify_unset(map, l, r);
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   115
      }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   116
    }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   117
  }
e5534cc91a10 8211926: Catastrophic size_t underflow in BitMap::*_large methods
shade
parents:
diff changeset
   118
}