1 /*
2 * Copyright (c) 2012, 2015, 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 */
24
25 #ifndef SHARE_VM_UTILITIES_RESOURCEHASH_HPP
26 #define SHARE_VM_UTILITIES_RESOURCEHASH_HPP
27
28 #include "memory/allocation.hpp"
29
30 template<typename K> struct ResourceHashtableFns {
31 typedef unsigned (*hash_fn)(K const&);
32 typedef bool (*equals_fn)(K const&, K const&);
33 };
34
35 template<typename K> unsigned primitive_hash(const K& k) {
36 unsigned hash = (unsigned)((uintptr_t)k);
37 return hash ^ (hash >> 3); // just in case we're dealing with aligned ptrs
38 }
39
40 template<typename K> bool primitive_equals(const K& k0, const K& k1) {
41 return k0 == k1;
42 }
43
44 template<
45 typename K, typename V,
46 // xlC does not compile this:
47 // http://stackoverflow.com/questions/8532961/template-argument-of-type-that-is-defined-by-inner-typedef-from-other-template-c
48 //typename ResourceHashtableFns<K>::hash_fn HASH = primitive_hash<K>,
49 //typename ResourceHashtableFns<K>::equals_fn EQUALS = primitive_equals<K>,
50 unsigned (*HASH) (K const&) = primitive_hash<K>,
51 bool (*EQUALS)(K const&, K const&) = primitive_equals<K>,
52 unsigned SIZE = 256,
53 ResourceObj::allocation_type ALLOC_TYPE = ResourceObj::RESOURCE_AREA,
54 MEMFLAGS MEM_TYPE = mtInternal
55 >
56 class ResourceHashtable : public ResourceObj {
57 private:
58
59 class Node : public ResourceObj {
60 public:
61 unsigned _hash;
62 K _key;
|
1 /*
2 * Copyright (c) 2012, 2018, 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 */
24
25 #ifndef SHARE_VM_UTILITIES_RESOURCEHASH_HPP
26 #define SHARE_VM_UTILITIES_RESOURCEHASH_HPP
27
28 #include "memory/allocation.hpp"
29
30 template<typename K> struct ResourceHashtableFns {
31 typedef unsigned (*hash_fn)(K const&);
32 typedef bool (*equals_fn)(K const&, K const&);
33 };
34
35 template<
36 typename K, typename V,
37 // xlC does not compile this:
38 // http://stackoverflow.com/questions/8532961/template-argument-of-type-that-is-defined-by-inner-typedef-from-other-template-c
39 //typename ResourceHashtableFns<K>::hash_fn HASH = primitive_hash<K>,
40 //typename ResourceHashtableFns<K>::equals_fn EQUALS = primitive_equals<K>,
41 unsigned (*HASH) (K const&) = primitive_hash<K>,
42 bool (*EQUALS)(K const&, K const&) = primitive_equals<K>,
43 unsigned SIZE = 256,
44 ResourceObj::allocation_type ALLOC_TYPE = ResourceObj::RESOURCE_AREA,
45 MEMFLAGS MEM_TYPE = mtInternal
46 >
47 class ResourceHashtable : public ResourceObj {
48 private:
49
50 class Node : public ResourceObj {
51 public:
52 unsigned _hash;
53 K _key;
|