author | drchase |
Fri, 09 May 2014 16:50:54 -0400 | |
changeset 24424 | 2658d7834c6e |
parent 24351 | 61b33cc6d3cf |
child 25490 | 59f226da8d81 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22750
a3c879b18f22
8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents:
20285
diff
changeset
|
2 |
* Copyright (c) 2000, 2014, 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:
1623
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1623
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:
1623
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_UTILITIES_ARRAY_HPP |
26 |
#define SHARE_VM_UTILITIES_ARRAY_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "memory/allocation.inline.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
30 |
#include "memory/metaspace.hpp" |
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
22750
diff
changeset
|
31 |
#include "runtime/orderAccess.hpp" |
7397 | 32 |
|
1 | 33 |
// correct linkage required to compile w/o warnings |
34 |
// (must be on file level - cannot be local) |
|
35 |
extern "C" { typedef int (*ftype)(const void*, const void*); } |
|
36 |
||
37 |
||
38 |
class ResourceArray: public ResourceObj { |
|
39 |
protected: |
|
40 |
int _length; // the number of array elements |
|
41 |
void* _data; // the array memory |
|
42 |
#ifdef ASSERT |
|
43 |
int _nesting; // the resource area nesting level |
|
44 |
#endif |
|
45 |
||
46 |
// creation |
|
47 |
ResourceArray() { |
|
48 |
_length = 0; |
|
49 |
_data = NULL; |
|
50 |
DEBUG_ONLY(init_nesting();) |
|
1551 | 51 |
// client may call initialize, at most once |
1 | 52 |
} |
53 |
||
54 |
||
55 |
ResourceArray(size_t esize, int length) { |
|
1551 | 56 |
DEBUG_ONLY(_data = NULL); |
57 |
initialize(esize, length); |
|
58 |
} |
|
59 |
||
60 |
void initialize(size_t esize, int length) { |
|
1 | 61 |
assert(length >= 0, "illegal length"); |
22750
a3c879b18f22
8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents:
20285
diff
changeset
|
62 |
assert(StressRewriter || _data == NULL, "must be new object"); |
1 | 63 |
_length = length; |
64 |
_data = resource_allocate_bytes(esize * length); |
|
65 |
DEBUG_ONLY(init_nesting();) |
|
66 |
} |
|
67 |
||
68 |
#ifdef ASSERT |
|
69 |
void init_nesting(); |
|
70 |
#endif |
|
71 |
||
72 |
// helper functions |
|
73 |
void sort (size_t esize, ftype f); // sort the array |
|
74 |
void expand (size_t esize, int i, int& size);// expand the array to include slot i |
|
75 |
void remove_at(size_t esize, int i); // remove the element in slot i |
|
76 |
||
77 |
public: |
|
78 |
// standard operations |
|
79 |
int length() const { return _length; } |
|
80 |
bool is_empty() const { return length() == 0; } |
|
81 |
}; |
|
82 |
||
83 |
||
13195 | 84 |
template <MEMFLAGS F>class CHeapArray: public CHeapObj<F> { |
1 | 85 |
protected: |
86 |
int _length; // the number of array elements |
|
87 |
void* _data; // the array memory |
|
88 |
||
89 |
// creation |
|
90 |
CHeapArray() { |
|
91 |
_length = 0; |
|
92 |
_data = NULL; |
|
93 |
} |
|
94 |
||
95 |
||
96 |
CHeapArray(size_t esize, int length) { |
|
97 |
assert(length >= 0, "illegal length"); |
|
98 |
_length = length; |
|
13195 | 99 |
_data = (void*) NEW_C_HEAP_ARRAY(char *, esize * length, F); |
1 | 100 |
} |
101 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
102 |
void initialize(size_t esize, int length) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
103 |
// In debug set array to 0? |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
104 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
105 |
|
1 | 106 |
#ifdef ASSERT |
107 |
void init_nesting(); |
|
108 |
#endif |
|
109 |
||
110 |
// helper functions |
|
111 |
void sort (size_t esize, ftype f); // sort the array |
|
112 |
void expand (size_t esize, int i, int& size);// expand the array to include slot i |
|
113 |
void remove_at(size_t esize, int i); // remove the element in slot i |
|
114 |
||
115 |
public: |
|
116 |
// standard operations |
|
117 |
int length() const { return _length; } |
|
118 |
bool is_empty() const { return length() == 0; } |
|
119 |
}; |
|
120 |
||
121 |
#define define_generic_array(array_name,element_type, base_class) \ |
|
122 |
class array_name: public base_class { \ |
|
123 |
protected: \ |
|
124 |
typedef element_type etype; \ |
|
125 |
enum { esize = sizeof(etype) }; \ |
|
126 |
\ |
|
127 |
void base_remove_at(size_t size, int i) { base_class::remove_at(size, i); } \ |
|
128 |
\ |
|
129 |
public: \ |
|
130 |
/* creation */ \ |
|
131 |
array_name() : base_class() {} \ |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
132 |
explicit array_name(const int length) : base_class(esize, length) {} \ |
1551 | 133 |
array_name(const int length, const etype fx) { initialize(length, fx); } \ |
134 |
void initialize(const int length) { base_class::initialize(esize, length); } \ |
|
135 |
void initialize(const int length, const etype fx) { \ |
|
136 |
initialize(length); \ |
|
1 | 137 |
for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx; \ |
138 |
} \ |
|
139 |
\ |
|
140 |
/* standard operations */ \ |
|
141 |
etype& operator [] (const int i) const { \ |
|
142 |
assert(0 <= i && i < length(), "index out of bounds"); \ |
|
143 |
return ((etype*)_data)[i]; \ |
|
144 |
} \ |
|
145 |
\ |
|
146 |
int index_of(const etype x) const { \ |
|
147 |
int i = length(); \ |
|
148 |
while (i-- > 0 && ((etype*)_data)[i] != x) ; \ |
|
149 |
/* i < 0 || ((etype*)_data)_data[i] == x */ \ |
|
150 |
return i; \ |
|
151 |
} \ |
|
152 |
\ |
|
153 |
void sort(int f(etype*, etype*)) { base_class::sort(esize, (ftype)f); } \ |
|
154 |
bool contains(const etype x) const { return index_of(x) >= 0; } \ |
|
155 |
\ |
|
156 |
/* deprecated operations - for compatibility with GrowableArray only */ \ |
|
157 |
etype at(const int i) const { return (*this)[i]; } \ |
|
158 |
void at_put(const int i, const etype x) { (*this)[i] = x; } \ |
|
159 |
etype* adr_at(const int i) { return &(*this)[i]; } \ |
|
160 |
int find(const etype x) { return index_of(x); } \ |
|
161 |
}; \ |
|
162 |
||
163 |
||
164 |
#define define_array(array_name,element_type) \ |
|
165 |
define_generic_array(array_name, element_type, ResourceArray) |
|
166 |
||
167 |
||
168 |
#define define_stack(stack_name,array_name) \ |
|
169 |
class stack_name: public array_name { \ |
|
170 |
protected: \ |
|
171 |
int _size; \ |
|
172 |
\ |
|
173 |
void grow(const int i, const etype fx) { \ |
|
174 |
assert(i >= length(), "index too small"); \ |
|
175 |
if (i >= size()) expand(esize, i, _size); \ |
|
176 |
for (int j = length(); j <= i; j++) ((etype*)_data)[j] = fx; \ |
|
177 |
_length = i+1; \ |
|
178 |
} \ |
|
179 |
\ |
|
180 |
public: \ |
|
181 |
/* creation */ \ |
|
1551 | 182 |
stack_name() : array_name() { _size = 0; } \ |
183 |
stack_name(const int size) { initialize(size); } \ |
|
184 |
stack_name(const int size, const etype fx) { initialize(size, fx); } \ |
|
185 |
void initialize(const int size, const etype fx) { \ |
|
186 |
_size = size; \ |
|
187 |
array_name::initialize(size, fx); \ |
|
188 |
/* _length == size, allocation and size are the same */ \ |
|
189 |
} \ |
|
190 |
void initialize(const int size) { \ |
|
191 |
_size = size; \ |
|
192 |
array_name::initialize(size); \ |
|
193 |
_length = 0; /* reset length to zero; _size records the allocation */ \ |
|
194 |
} \ |
|
1 | 195 |
\ |
196 |
/* standard operations */ \ |
|
197 |
int size() const { return _size; } \ |
|
198 |
\ |
|
1551 | 199 |
int push(const etype x) { \ |
200 |
int len = length(); \ |
|
201 |
if (len >= size()) expand(esize, len, _size); \ |
|
202 |
((etype*)_data)[len] = x; \ |
|
203 |
_length = len+1; \ |
|
204 |
return len; \ |
|
1 | 205 |
} \ |
206 |
\ |
|
207 |
etype pop() { \ |
|
208 |
assert(!is_empty(), "stack is empty"); \ |
|
209 |
return ((etype*)_data)[--_length]; \ |
|
210 |
} \ |
|
211 |
\ |
|
212 |
etype top() const { \ |
|
213 |
assert(!is_empty(), "stack is empty"); \ |
|
214 |
return ((etype*)_data)[length() - 1]; \ |
|
215 |
} \ |
|
216 |
\ |
|
217 |
void push_all(const stack_name* stack) { \ |
|
218 |
const int l = stack->length(); \ |
|
219 |
for (int i = 0; i < l; i++) push(((etype*)(stack->_data))[i]); \ |
|
220 |
} \ |
|
221 |
\ |
|
222 |
etype at_grow(const int i, const etype fx) { \ |
|
223 |
if (i >= length()) grow(i, fx); \ |
|
224 |
return ((etype*)_data)[i]; \ |
|
225 |
} \ |
|
226 |
\ |
|
227 |
void at_put_grow(const int i, const etype x, const etype fx) { \ |
|
228 |
if (i >= length()) grow(i, fx); \ |
|
229 |
((etype*)_data)[i] = x; \ |
|
230 |
} \ |
|
231 |
\ |
|
232 |
void truncate(const int length) { \ |
|
233 |
assert(0 <= length && length <= this->length(), "illegal length"); \ |
|
234 |
_length = length; \ |
|
235 |
} \ |
|
236 |
\ |
|
237 |
void remove_at(int i) { base_remove_at(esize, i); } \ |
|
238 |
void remove(etype x) { remove_at(index_of(x)); } \ |
|
239 |
\ |
|
240 |
/* inserts the given element before the element at index i */ \ |
|
241 |
void insert_before(const int i, const etype el) { \ |
|
242 |
int len = length(); \ |
|
243 |
int new_length = len + 1; \ |
|
244 |
if (new_length >= size()) expand(esize, new_length, _size); \ |
|
245 |
for (int j = len - 1; j >= i; j--) { \ |
|
246 |
((etype*)_data)[j + 1] = ((etype*)_data)[j]; \ |
|
247 |
} \ |
|
248 |
_length = new_length; \ |
|
249 |
at_put(i, el); \ |
|
250 |
} \ |
|
251 |
\ |
|
252 |
/* inserts contents of the given stack before the element at index i */ \ |
|
253 |
void insert_before(const int i, const stack_name *st) { \ |
|
254 |
if (st->length() == 0) return; \ |
|
255 |
int len = length(); \ |
|
256 |
int st_len = st->length(); \ |
|
257 |
int new_length = len + st_len; \ |
|
258 |
if (new_length >= size()) expand(esize, new_length, _size); \ |
|
259 |
int j; \ |
|
260 |
for (j = len - 1; j >= i; j--) { \ |
|
261 |
((etype*)_data)[j + st_len] = ((etype*)_data)[j]; \ |
|
262 |
} \ |
|
263 |
for (j = 0; j < st_len; j++) { \ |
|
264 |
((etype*)_data)[i + j] = ((etype*)st->_data)[j]; \ |
|
265 |
} \ |
|
266 |
_length = new_length; \ |
|
267 |
} \ |
|
268 |
\ |
|
269 |
/* deprecated operations - for compatibility with GrowableArray only */ \ |
|
270 |
int capacity() const { return size(); } \ |
|
271 |
void clear() { truncate(0); } \ |
|
272 |
void trunc_to(const int length) { truncate(length); } \ |
|
1551 | 273 |
int append(const etype x) { return push(x); } \ |
1 | 274 |
void appendAll(const stack_name* stack) { push_all(stack); } \ |
275 |
etype last() const { return top(); } \ |
|
276 |
}; \ |
|
277 |
||
278 |
||
279 |
#define define_resource_list(element_type) \ |
|
280 |
define_generic_array(element_type##Array, element_type, ResourceArray) \ |
|
281 |
define_stack(element_type##List, element_type##Array) |
|
282 |
||
283 |
#define define_resource_pointer_list(element_type) \ |
|
284 |
define_generic_array(element_type##Array, element_type *, ResourceArray) \ |
|
285 |
define_stack(element_type##List, element_type##Array) |
|
286 |
||
287 |
#define define_c_heap_list(element_type) \ |
|
288 |
define_generic_array(element_type##Array, element_type, CHeapArray) \ |
|
289 |
define_stack(element_type##List, element_type##Array) |
|
290 |
||
291 |
#define define_c_heap_pointer_list(element_type) \ |
|
292 |
define_generic_array(element_type##Array, element_type *, CHeapArray) \ |
|
293 |
define_stack(element_type##List, element_type##Array) |
|
294 |
||
295 |
||
296 |
// Arrays for basic types |
|
297 |
||
298 |
define_array(boolArray, bool) define_stack(boolStack, boolArray) |
|
299 |
define_array(intArray , int ) define_stack(intStack , intArray ) |
|
7397 | 300 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
301 |
// Array for metadata allocation |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
302 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
303 |
template <typename T> |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
304 |
class Array: public MetaspaceObj { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
305 |
friend class MetadataFactory; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
306 |
friend class VMStructs; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
307 |
friend class MethodHandleCompiler; // special case |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
308 |
protected: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
309 |
int _length; // the number of array elements |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
310 |
T _data[1]; // the array memory |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
311 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
312 |
void initialize(int length) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
313 |
_length = length; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
314 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
315 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
316 |
private: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
317 |
// Turn off copy constructor and assignment operator. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
318 |
Array(const Array<T>&); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
319 |
void operator=(const Array<T>&); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
320 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17858
diff
changeset
|
321 |
void* operator new(size_t size, ClassLoaderData* loader_data, int length, bool read_only, TRAPS) throw() { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
322 |
size_t word_size = Array::size(length); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
323 |
return (void*) Metaspace::allocate(loader_data, word_size, read_only, |
17858
c292f8791cca
8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents:
14477
diff
changeset
|
324 |
MetaspaceObj::array_type(sizeof(T)), CHECK_NULL); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
325 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
326 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
327 |
static size_t byte_sizeof(int length) { return sizeof(Array<T>) + MAX2(length - 1, 0) * sizeof(T); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
328 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
329 |
explicit Array(int length) : _length(length) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
330 |
assert(length >= 0, "illegal length"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
331 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
332 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
333 |
Array(int length, T init) : _length(length) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
334 |
assert(length >= 0, "illegal length"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
335 |
for (int i = 0; i < length; i++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
336 |
_data[i] = init; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
337 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
338 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
339 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
340 |
public: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
341 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
342 |
// standard operations |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
343 |
int length() const { return _length; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
344 |
T* data() { return _data; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
345 |
bool is_empty() const { return length() == 0; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
346 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
347 |
int index_of(const T& x) const { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
348 |
int i = length(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
349 |
while (i-- > 0 && _data[i] != x) ; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
350 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
351 |
return i; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
352 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
353 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
354 |
// sort the array. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
355 |
bool contains(const T& x) const { return index_of(x) >= 0; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
356 |
|
20285
2248009a3749
8022187: Missing ResourceMark crash when assertion using FormatBufferResource fails
zgu
parents:
19696
diff
changeset
|
357 |
T at(int i) const { assert(i >= 0 && i< _length, err_msg("oob: 0 <= %d < %d", i, _length)); return _data[i]; } |
2248009a3749
8022187: Missing ResourceMark crash when assertion using FormatBufferResource fails
zgu
parents:
19696
diff
changeset
|
358 |
void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, err_msg("oob: 0 <= %d < %d", i, _length)); _data[i] = x; } |
2248009a3749
8022187: Missing ResourceMark crash when assertion using FormatBufferResource fails
zgu
parents:
19696
diff
changeset
|
359 |
T* adr_at(const int i) { assert(i >= 0 && i< _length, err_msg("oob: 0 <= %d < %d", i, _length)); return &_data[i]; } |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
360 |
int find(const T& x) { return index_of(x); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
361 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
362 |
T at_acquire(const int which) { return OrderAccess::load_acquire(adr_at(which)); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
363 |
void release_at_put(int which, T contents) { OrderAccess::release_store(adr_at(which), contents); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
364 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
365 |
static int size(int length) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
366 |
return align_size_up(byte_sizeof(length), BytesPerWord) / BytesPerWord; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
367 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
368 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
369 |
int size() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
370 |
return size(_length); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
371 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
372 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
373 |
static int length_offset_in_bytes() { return (int) (offset_of(Array<T>, _length)); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
374 |
// Note, this offset don't have to be wordSize aligned. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
375 |
static int base_offset_in_bytes() { return (int) (offset_of(Array<T>, _data)); }; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
376 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
377 |
// FIXME: How to handle this? |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
378 |
void print_value_on(outputStream* st) const { |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24351
diff
changeset
|
379 |
st->print("Array<T>(" INTPTR_FORMAT ")", p2i(this)); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
380 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
381 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
382 |
#ifndef PRODUCT |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
383 |
void print(outputStream* st) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
384 |
for (int i = 0; i< _length; i++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
385 |
st->print_cr("%d: " INTPTR_FORMAT, i, (intptr_t)at(i)); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
386 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
387 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
388 |
void print() { print(tty); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
389 |
#endif // PRODUCT |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
390 |
}; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
391 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
392 |
|
7397 | 393 |
#endif // SHARE_VM_UTILITIES_ARRAY_HPP |