test/hotspot/gtest/utilities/test_resourceHash.cpp
author rehn
Thu, 07 Jun 2018 14:11:56 +0200
changeset 50445 bd6b78feb6a3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8195097: Make it possible to process StringTable outside safepoint Reviewed-by: coleenp, gziemski, iklam, jiangli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     1
/*
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     4
 *
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     8
 *
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    13
 * accompanied this code).
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    14
 *
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    18
 *
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    21
 * questions.
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    22
 */
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    23
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    24
#include "precompiled.hpp"
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    25
#include "memory/allocation.hpp"
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    26
#include "memory/resourceArea.hpp"
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    27
#include "unittest.hpp"
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    28
#include "utilities/debug.hpp"
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    29
#include "utilities/resourceHash.hpp"
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    30
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    31
class CommonResourceHashtableTest : public ::testing::Test {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    32
 protected:
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    33
  typedef void* K;
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    34
  typedef int V;
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    35
  const static MEMFLAGS MEM_TYPE = mtInternal;
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    36
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    37
  static unsigned identity_hash(const K& k) {
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    38
    return (unsigned) (uintptr_t) k;
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    39
  }
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    40
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    41
  static unsigned bad_hash(const K& k) {
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    42
    return 1;
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    43
  }
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    44
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    45
  static void* as_K(uintptr_t val) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    46
    return (void*) val;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    47
  }
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    48
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    49
  class EqualityTestIter {
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    50
   public:
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    51
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    52
    bool do_entry(K const& k, V const& v) {
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    53
      if ((uintptr_t) k != (uintptr_t) v) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    54
        EXPECT_EQ((uintptr_t) k, (uintptr_t) v);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    55
        return false;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    56
      } else {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    57
        return true; // continue iteration
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    58
      }
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    59
    }
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    60
  };
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    61
};
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    62
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    63
class SmallResourceHashtableTest : public CommonResourceHashtableTest {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    64
 protected:
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    65
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    66
  template<
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    67
  unsigned (*HASH) (K const&) = primitive_hash<K>,
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    68
  bool (*EQUALS)(K const&, K const&) = primitive_equals<K>,
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    69
  unsigned SIZE = 256,
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    70
  ResourceObj::allocation_type ALLOC_TYPE = ResourceObj::RESOURCE_AREA
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    71
  >
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    72
  class Runner : public AllStatic {
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    73
   public:
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    74
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    75
    static void test(V step) {
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    76
      EqualityTestIter et;
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    77
      ResourceHashtable<K, V, HASH, EQUALS, SIZE, ALLOC_TYPE, MEM_TYPE> rh;
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    78
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    79
      ASSERT_FALSE(rh.contains(as_K(step)));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    80
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    81
      ASSERT_TRUE(rh.put(as_K(step), step));
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    82
      ASSERT_TRUE(rh.contains(as_K(step)));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    83
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    84
      ASSERT_FALSE(rh.put(as_K(step), step));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    85
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    86
      ASSERT_TRUE(rh.put(as_K(2 * step), 2 * step));
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    87
      ASSERT_TRUE(rh.put(as_K(3 * step), 3 * step));
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    88
      ASSERT_TRUE(rh.put(as_K(4 * step), 4 * step));
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    89
      ASSERT_TRUE(rh.put(as_K(5 * step), 5 * step));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    90
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    91
      ASSERT_FALSE(rh.remove(as_K(0x0)));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    92
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
    93
      rh.iterate(&et);
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    94
      if (::testing::Test::HasFailure()) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    95
        return;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    96
      }
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    97
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    98
      ASSERT_TRUE(rh.remove(as_K(step)));
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
    99
      rh.iterate(&et);
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   100
    }
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   101
  };
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   102
};
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   103
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   104
TEST_VM_F(SmallResourceHashtableTest, default) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   105
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   106
  Runner<>::test(0x1);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   107
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   108
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   109
TEST_VM_F(SmallResourceHashtableTest, default_shifted) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   110
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   111
  Runner<>::test(0x10);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   112
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   113
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   114
TEST_VM_F(SmallResourceHashtableTest, bad_hash) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   115
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   116
  Runner<bad_hash>::test(0x1);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   117
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   118
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   119
TEST_VM_F(SmallResourceHashtableTest, bad_hash_shifted) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   120
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   121
  Runner<bad_hash>::test(0x10);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   122
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   123
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   124
TEST_VM_F(SmallResourceHashtableTest, identity_hash) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   125
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   126
  Runner<identity_hash>::test(0x1);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   127
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   128
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   129
TEST_VM_F(SmallResourceHashtableTest, identity_hash_shifted) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   130
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   131
  Runner<identity_hash>::test(0x10);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   132
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   133
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   134
TEST_VM_F(SmallResourceHashtableTest, primitive_hash_no_rm) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   135
  Runner<primitive_hash<K>, primitive_equals<K>, 512, ResourceObj::C_HEAP>::test(0x1);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   136
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   137
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   138
TEST_VM_F(SmallResourceHashtableTest, primitive_hash_no_rm_shifted) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   139
  Runner<primitive_hash<K>, primitive_equals<K>, 512, ResourceObj::C_HEAP>::test(0x10);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   140
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   141
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   142
TEST_VM_F(SmallResourceHashtableTest, bad_hash_no_rm) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   143
  Runner<bad_hash, primitive_equals<K>, 512, ResourceObj::C_HEAP>::test(0x1);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   144
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   145
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   146
TEST_VM_F(SmallResourceHashtableTest, bad_hash_no_rm_shifted) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   147
  Runner<bad_hash, primitive_equals<K>, 512, ResourceObj::C_HEAP>::test(0x10);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   148
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   149
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   150
TEST_VM_F(SmallResourceHashtableTest, identity_hash_no_rm) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   151
  Runner<identity_hash, primitive_equals<K>, 1, ResourceObj::C_HEAP>::test(0x1);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   152
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   153
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   154
TEST_VM_F(SmallResourceHashtableTest, identity_hash_no_rm_shifted) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   155
  Runner<identity_hash, primitive_equals<K>, 1, ResourceObj::C_HEAP>::test(0x10);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   156
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   157
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   158
class GenericResourceHashtableTest : public CommonResourceHashtableTest {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   159
 protected:
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   160
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   161
  template<
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   162
  unsigned (*HASH) (K const&) = primitive_hash<K>,
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   163
  bool (*EQUALS)(K const&, K const&) = primitive_equals<K>,
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   164
  unsigned SIZE = 256,
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   165
  ResourceObj::allocation_type ALLOC_TYPE = ResourceObj::RESOURCE_AREA
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   166
  >
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   167
  class Runner : public AllStatic {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   168
   public:
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   169
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   170
    static void test(unsigned num_elements = SIZE) {
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   171
      EqualityTestIter et;
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   172
      ResourceHashtable<K, V, HASH, EQUALS, SIZE, ALLOC_TYPE, MEM_TYPE> rh;
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   173
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   174
      for (uintptr_t i = 0; i < num_elements; ++i) {
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   175
        ASSERT_TRUE(rh.put(as_K(i), i));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   176
      }
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   177
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   178
      rh.iterate(&et);
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   179
      if (::testing::Test::HasFailure()) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   180
        return;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   181
      }
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   182
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   183
      for (uintptr_t i = num_elements; i > 0; --i) {
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   184
        uintptr_t index = i - 1;
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   185
        ASSERT_TRUE((rh.remove(as_K(index))));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   186
      }
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   187
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   188
      rh.iterate(&et);
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   189
      if (::testing::Test::HasFailure()) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   190
        return;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   191
      }
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   192
      for (uintptr_t i = num_elements; i > 0; --i) {
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   193
        uintptr_t index = i - 1;
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   194
        ASSERT_FALSE(rh.remove(as_K(index)));
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   195
      }
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   196
      rh.iterate(&et);
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   197
    }
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   198
  };
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   199
};
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   200
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   201
TEST_VM_F(GenericResourceHashtableTest, default) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   202
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   203
  Runner<>::test();
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   204
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   205
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   206
TEST_VM_F(GenericResourceHashtableTest, bad_hash) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   207
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   208
  Runner<bad_hash>::test();
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   209
}
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   210
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   211
TEST_VM_F(GenericResourceHashtableTest, identity_hash) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   212
  ResourceMark rm;
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   213
  Runner<identity_hash>::test();
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   214
}
33754
49614940dafc 8055283: Expand ResourceHashtable with C_HEAP allocation, removal and some unit tests
mgerdin
parents:
diff changeset
   215
41668
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   216
TEST_VM_F(GenericResourceHashtableTest, primitive_hash_no_rm) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   217
  Runner<primitive_hash<K>, primitive_equals<K>, 512, ResourceObj::C_HEAP>::test();
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   218
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   219
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   220
TEST_VM_F(GenericResourceHashtableTest, bad_hash_no_rm) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   221
  Runner<bad_hash, primitive_equals<K>, 512, ResourceObj::C_HEAP>::test();
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   222
}
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   223
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   224
TEST_VM_F(GenericResourceHashtableTest, identity_hash_no_rm) {
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   225
  Runner<identity_hash, primitive_equals<K>, 1, ResourceObj::C_HEAP>::test(512);
e9c6bbf513e5 8166462: Convert TestResourcehash_test to Gtest
kzhaldyb
parents: 39977
diff changeset
   226
}