1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
28 #include "classfile/compactHashtable.hpp" |
28 #include "classfile/compactHashtable.hpp" |
29 #include "memory/allocation.inline.hpp" |
29 #include "memory/allocation.inline.hpp" |
30 #include "oops/oop.inline.hpp" |
30 #include "oops/oop.inline.hpp" |
31 |
31 |
32 template <class T, class N> |
32 template <class T, class N> |
33 inline Symbol* CompactHashtable<T, N>::lookup_entry(CompactHashtable<Symbol*, char>* const t, |
33 inline Symbol* CompactHashtable<T, N>::decode_entry(CompactHashtable<Symbol*, char>* const t, |
34 juint* addr, const char* name, int len) { |
34 u4 offset, const char* name, int len) { |
35 Symbol* sym = (Symbol*)((void*)(_base_address + *addr)); |
35 Symbol* sym = (Symbol*)(_base_address + offset); |
36 if (sym->equals(name, len)) { |
36 if (sym->equals(name, len)) { |
37 assert(sym->refcount() == -1, "must be shared"); |
37 assert(sym->refcount() == -1, "must be shared"); |
38 return sym; |
38 return sym; |
39 } |
39 } |
40 |
40 |
41 return NULL; |
41 return NULL; |
42 } |
42 } |
43 |
43 |
44 template <class T, class N> |
44 template <class T, class N> |
45 inline oop CompactHashtable<T, N>::lookup_entry(CompactHashtable<oop, char>* const t, |
45 inline oop CompactHashtable<T, N>::decode_entry(CompactHashtable<oop, char>* const t, |
46 juint* addr, const char* name, int len) { |
46 u4 offset, const char* name, int len) { |
47 narrowOop obj = (narrowOop)(*addr); |
47 narrowOop obj = (narrowOop)offset; |
48 oop string = oopDesc::decode_heap_oop(obj); |
48 oop string = oopDesc::decode_heap_oop(obj); |
49 if (java_lang_String::equals(string, (jchar*)name, len)) { |
49 if (java_lang_String::equals(string, (jchar*)name, len)) { |
50 return string; |
50 return string; |
51 } |
51 } |
52 |
52 |
54 } |
54 } |
55 |
55 |
56 template <class T, class N> |
56 template <class T, class N> |
57 inline T CompactHashtable<T,N>::lookup(const N* name, unsigned int hash, int len) { |
57 inline T CompactHashtable<T,N>::lookup(const N* name, unsigned int hash, int len) { |
58 if (_entry_count > 0) { |
58 if (_entry_count > 0) { |
59 assert(!DumpSharedSpaces, "run-time only"); |
|
60 int index = hash % _bucket_count; |
59 int index = hash % _bucket_count; |
61 juint bucket_info = _buckets[index]; |
60 u4 bucket_info = _buckets[index]; |
62 juint bucket_offset = BUCKET_OFFSET(bucket_info); |
61 u4 bucket_offset = BUCKET_OFFSET(bucket_info); |
63 int bucket_type = BUCKET_TYPE(bucket_info); |
62 int bucket_type = BUCKET_TYPE(bucket_info); |
64 juint* bucket = _buckets + bucket_offset; |
63 u4* entry = _entries + bucket_offset; |
65 juint* bucket_end = _buckets; |
|
66 |
64 |
67 if (bucket_type == COMPACT_BUCKET_TYPE) { |
65 if (bucket_type == VALUE_ONLY_BUCKET_TYPE) { |
68 // the compact bucket has one entry with entry offset only |
66 T res = decode_entry(this, entry[0], name, len); |
69 T res = lookup_entry(this, &bucket[0], name, len); |
|
70 if (res != NULL) { |
67 if (res != NULL) { |
71 return res; |
68 return res; |
72 } |
69 } |
73 } else { |
70 } else { |
74 // This is a regular bucket, which has more than one |
71 // This is a regular bucket, which has more than one |
75 // entries. Each entry is a pair of entry (hash, offset). |
72 // entries. Each entry is a pair of entry (hash, offset). |
76 // Seek until the end of the bucket. |
73 // Seek until the end of the bucket. |
77 bucket_end += BUCKET_OFFSET(_buckets[index + 1]); |
74 u4* entry_max = _entries + BUCKET_OFFSET(_buckets[index + 1]); |
78 while (bucket < bucket_end) { |
75 while (entry < entry_max) { |
79 unsigned int h = (unsigned int)(bucket[0]); |
76 unsigned int h = (unsigned int)(entry[0]); |
80 if (h == hash) { |
77 if (h == hash) { |
81 T res = lookup_entry(this, &bucket[1], name, len); |
78 T res = decode_entry(this, entry[1], name, len); |
82 if (res != NULL) { |
79 if (res != NULL) { |
83 return res; |
80 return res; |
84 } |
81 } |
85 } |
82 } |
86 bucket += 2; |
83 entry += 2; |
87 } |
84 } |
88 } |
85 } |
89 } |
86 } |
90 return NULL; |
87 return NULL; |
91 } |
88 } |
92 |
89 |
93 inline void CompactHashtableWriter::add(unsigned int hash, Symbol* symbol) { |
|
94 add(hash, new Entry(hash, symbol)); |
|
95 } |
|
96 |
|
97 inline void CompactHashtableWriter::add(unsigned int hash, oop string) { |
|
98 add(hash, new Entry(hash, string)); |
|
99 } |
|
100 |
|
101 |
|
102 #endif // SHARE_VM_CLASSFILE_COMPACTHASHTABLE_INLINE_HPP |
90 #endif // SHARE_VM_CLASSFILE_COMPACTHASHTABLE_INLINE_HPP |