author | coleenp |
Thu, 23 Jul 2015 15:17:58 -0400 | |
changeset 31981 | 9caa094a485f |
parent 13728 | 882756847a04 |
child 33160 | c59f1676d27e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
2 |
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
26 |
#include "ci/ciEnv.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
27 |
#include "ci/ciInstance.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
28 |
#include "ci/ciMetadata.hpp" |
7397 | 29 |
#include "code/oopRecorder.hpp" |
30 |
#include "memory/allocation.inline.hpp" |
|
31 |
#include "oops/oop.inline.hpp" |
|
1 | 32 |
|
33 |
#ifdef ASSERT |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
34 |
template <class T> int ValueRecorder<T>::_find_index_calls = 0; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
35 |
template <class T> int ValueRecorder<T>::_hit_indexes = 0; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
36 |
template <class T> int ValueRecorder<T>::_missed_indexes = 0; |
1 | 37 |
#endif //ASSERT |
38 |
||
39 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
40 |
template <class T> ValueRecorder<T>::ValueRecorder(Arena* arena) { |
1 | 41 |
_handles = NULL; |
42 |
_indexes = NULL; |
|
43 |
_arena = arena; |
|
44 |
_complete = false; |
|
45 |
} |
|
46 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
47 |
template <class T> template <class X> ValueRecorder<T>::IndexCache<X>::IndexCache() { |
1 | 48 |
assert(first_index > 0, "initial zero state of cache must be invalid index"); |
49 |
Copy::zero_to_bytes(&_cache[0], sizeof(_cache)); |
|
50 |
} |
|
51 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
52 |
template <class T> int ValueRecorder<T>::size() { |
1 | 53 |
_complete = true; |
54 |
if (_handles == NULL) return 0; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
55 |
return _handles->length() * sizeof(T); |
1 | 56 |
} |
57 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
58 |
template <class T> void ValueRecorder<T>::copy_values_to(nmethod* nm) { |
1 | 59 |
assert(_complete, "must be frozen"); |
60 |
maybe_initialize(); // get non-null handles, even if we have no oops |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
61 |
nm->copy_values(_handles); |
1 | 62 |
} |
63 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
64 |
template <class T> void ValueRecorder<T>::maybe_initialize() { |
1 | 65 |
if (_handles == NULL) { |
66 |
if (_arena != NULL) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
67 |
_handles = new(_arena) GrowableArray<T>(_arena, 10, 0, 0); |
1 | 68 |
_no_finds = new(_arena) GrowableArray<int>( _arena, 10, 0, 0); |
69 |
} else { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
70 |
_handles = new GrowableArray<T>(10, 0, 0); |
1 | 71 |
_no_finds = new GrowableArray<int>( 10, 0, 0); |
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
77 |
template <class T> T ValueRecorder<T>::at(int index) { |
1 | 78 |
// there is always a NULL virtually present as first object |
79 |
if (index == null_index) return NULL; |
|
80 |
return _handles->at(index - first_index); |
|
81 |
} |
|
82 |
||
83 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
84 |
template <class T> int ValueRecorder<T>::add_handle(T h, bool make_findable) { |
1 | 85 |
assert(!_complete, "cannot allocate more elements after size query"); |
86 |
maybe_initialize(); |
|
87 |
// indexing uses 1 as an origin--0 means null |
|
88 |
int index = _handles->length() + first_index; |
|
89 |
_handles->append(h); |
|
90 |
||
91 |
// Support correct operation of find_index(). |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
92 |
assert(!(make_findable && !is_real(h)), "nulls are not findable"); |
1 | 93 |
if (make_findable) { |
94 |
// This index may be returned from find_index(). |
|
95 |
if (_indexes != NULL) { |
|
96 |
int* cloc = _indexes->cache_location(h); |
|
97 |
_indexes->set_cache_location_index(cloc, index); |
|
98 |
} else if (index == index_cache_threshold && _arena != NULL) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
99 |
_indexes = new(_arena) IndexCache<T>(); |
1 | 100 |
for (int i = 0; i < _handles->length(); i++) { |
101 |
// Load the cache with pre-existing elements. |
|
102 |
int index0 = i + first_index; |
|
103 |
if (_no_finds->contains(index0)) continue; |
|
104 |
int* cloc = _indexes->cache_location(_handles->at(i)); |
|
105 |
_indexes->set_cache_location_index(cloc, index0); |
|
106 |
} |
|
107 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
108 |
} else if (is_real(h)) { |
1 | 109 |
// Remember that this index is not to be returned from find_index(). |
110 |
// This case is rare, because most or all uses of allocate_index pass |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
111 |
// an argument of NULL or Universe::non_oop_word. |
1 | 112 |
// Thus, the expected length of _no_finds is zero. |
113 |
_no_finds->append(index); |
|
114 |
} |
|
115 |
||
116 |
return index; |
|
117 |
} |
|
118 |
||
119 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
120 |
template <class T> int ValueRecorder<T>::maybe_find_index(T h) { |
1 | 121 |
debug_only(_find_index_calls++); |
122 |
assert(!_complete, "cannot allocate more elements after size query"); |
|
123 |
maybe_initialize(); |
|
124 |
if (h == NULL) return null_index; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
125 |
assert(is_real(h), "must be valid"); |
1 | 126 |
int* cloc = (_indexes == NULL)? NULL: _indexes->cache_location(h); |
127 |
if (cloc != NULL) { |
|
128 |
int cindex = _indexes->cache_location_index(cloc); |
|
129 |
if (cindex == 0) { |
|
130 |
return -1; // We know this handle is completely new. |
|
131 |
} |
|
132 |
if (cindex >= first_index && _handles->at(cindex - first_index) == h) { |
|
133 |
debug_only(_hit_indexes++); |
|
134 |
return cindex; |
|
135 |
} |
|
136 |
if (!_indexes->cache_location_collision(cloc)) { |
|
137 |
return -1; // We know the current cache occupant is unique to that cloc. |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
// Not found in cache, due to a cache collision. (Or, no cache at all.) |
|
142 |
// Do a linear search, most recent to oldest. |
|
143 |
for (int i = _handles->length() - 1; i >= 0; i--) { |
|
144 |
if (_handles->at(i) == h) { |
|
145 |
int findex = i + first_index; |
|
146 |
if (_no_finds->contains(findex)) continue; // oops; skip this one |
|
147 |
if (cloc != NULL) { |
|
148 |
_indexes->set_cache_location_index(cloc, findex); |
|
149 |
} |
|
150 |
debug_only(_missed_indexes++); |
|
151 |
return findex; |
|
152 |
} |
|
153 |
} |
|
154 |
return -1; |
|
155 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
156 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
157 |
// Explicitly instantiate these types |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
158 |
template class ValueRecorder<Metadata*>; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
159 |
template class ValueRecorder<jobject>; |