comparison src/share/vm/jvmci/jvmciHashtable.cpp @ 21562:47bebae7454f

Merge.
author Doug Simon <doug.simon@oracle.com>
date Thu, 28 May 2015 21:58:33 +0200
parents src/share/vm/graal/graalHashtable.cpp@cecb4e39521c
children 59c3f921e454
comparison
equal deleted inserted replaced
21561:ce2113326bc8 21562:47bebae7454f
1 /*
2 * Copyright (c) 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 #include "jvmci/jvmciHashtable.hpp"
25
26 template<class K, class V> bool JVMCIHashtable<K,V>::add(V value, bool replace) {
27 K key = get_key(value);
28 unsigned int hash = compute_hash(key);
29 unsigned int index = hash_to_index(hash);
30 for (JVMCIHashtableEntry<V>* e = bucket(index); e != NULL; e = e->next()) {
31 if (key_equals(get_key(e->literal_addr()), key)) {
32 if (replace) {
33 e->set_literal(value);
34 }
35 return false;
36 }
37 }
38 JVMCIHashtableEntry<V>* e = new JVMCIHashtableEntry<V>(value);
39 e->set_next(_buckets[index]);
40 _buckets[index] = e;
41 ++_number_of_entries;
42 return true;
43 }
44
45 template<class K, class V> V* JVMCIHashtable<K,V>::get(K key) {
46 unsigned int index = index_for(key);
47 for (JVMCIHashtableEntry<V>* e = bucket(index); e != NULL; e = e->next()) {
48 if (key_equals(get_key(e->literal_addr()), key)) {
49 return e->literal_addr();
50 }
51 }
52 return NULL;
53 }
54
55 template<class K, class V> void JVMCIHashtable<K, V>::for_each(ValueClosure<V>* closure) {
56 for (size_t i = 0; i < table_size(); ++i) {
57 for (JVMCIHashtableEntry<V>* e = bucket(i); e != NULL && !closure->is_aborted(); e = e->next()) {
58 closure->do_value(e->literal_addr());
59 }
60 }
61 }
62
63 template<class K, class V> JVMCIHashtable<K,V>::~JVMCIHashtable() {
64 for (size_t i = 0; i < table_size(); ++i) {
65 JVMCIHashtableEntry<V>* e = bucket(i);
66 while (e != NULL) {
67 JVMCIHashtableEntry<V>* current = e;
68 e = e->next();
69 delete current;
70 }
71 }
72 FREE_C_HEAP_ARRAY(JVMCIHashtableEntry*, _buckets, mtCompiler);
73 }
74
75 // Instantiation
76 #include "jvmci/jvmciOptions.hpp"
77 template class JVMCIHashtable<const char*, OptionDesc>;
78 template class JVMCIHashtable<const char*, OptionValue>;