annotate src/share/vm/utilities/array.hpp @ 6972:bd7a7ce2e264

6830717: replay of compilations would help with debugging Summary: When java process crashed in compiler thread, repeat the compilation process will help finding root cause. This is done with using SA dump application class data and replay data from core dump, then use debug version of jvm to recompile the problematic java method. Reviewed-by: kvn, twisti, sspitsyn Contributed-by: yumin.qi@oracle.com
author minqi
date Mon, 12 Nov 2012 14:03:53 -0800
parents da91efe96a93
children a1ebd310d5c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 470
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 470
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 470
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_UTILITIES_ARRAY_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_UTILITIES_ARRAY_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "memory/allocation.inline.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
30 #include "memory/metaspace.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // correct linkage required to compile w/o warnings
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // (must be on file level - cannot be local)
a61af66fc99e Initial load
duke
parents:
diff changeset
34 extern "C" { typedef int (*ftype)(const void*, const void*); }
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 class ResourceArray: public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
39 int _length; // the number of array elements
a61af66fc99e Initial load
duke
parents:
diff changeset
40 void* _data; // the array memory
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
42 int _nesting; // the resource area nesting level
a61af66fc99e Initial load
duke
parents:
diff changeset
43 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // creation
a61af66fc99e Initial load
duke
parents:
diff changeset
46 ResourceArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _data = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 DEBUG_ONLY(init_nesting();)
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
50 // client may call initialize, at most once
0
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ResourceArray(size_t esize, int length) {
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
55 DEBUG_ONLY(_data = NULL);
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
56 initialize(esize, length);
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
57 }
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
58
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
59 void initialize(size_t esize, int length) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
60 assert(length >= 0, "illegal length");
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
61 assert(_data == NULL, "must be new object");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _length = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _data = resource_allocate_bytes(esize * length);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 DEBUG_ONLY(init_nesting();)
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
68 void init_nesting();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
72 void sort (size_t esize, ftype f); // sort the array
a61af66fc99e Initial load
duke
parents:
diff changeset
73 void expand (size_t esize, int i, int& size);// expand the array to include slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void remove_at(size_t esize, int i); // remove the element in slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // standard operations
a61af66fc99e Initial load
duke
parents:
diff changeset
78 int length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 bool is_empty() const { return length() == 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 };
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
83 template <MEMFLAGS F>class CHeapArray: public CHeapObj<F> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
84 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int _length; // the number of array elements
a61af66fc99e Initial load
duke
parents:
diff changeset
86 void* _data; // the array memory
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // creation
a61af66fc99e Initial load
duke
parents:
diff changeset
89 CHeapArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _data = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 CHeapArray(size_t esize, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 assert(length >= 0, "illegal length");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _length = length;
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
98 _data = (void*) NEW_C_HEAP_ARRAY(char *, esize * length, F);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
101 void initialize(size_t esize, int length) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
102 // In debug set array to 0?
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
103 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
104
0
a61af66fc99e Initial load
duke
parents:
diff changeset
105 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
106 void init_nesting();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
110 void sort (size_t esize, ftype f); // sort the array
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void expand (size_t esize, int i, int& size);// expand the array to include slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void remove_at(size_t esize, int i); // remove the element in slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // standard operations
a61af66fc99e Initial load
duke
parents:
diff changeset
116 int length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 bool is_empty() const { return length() == 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 };
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 #define define_generic_array(array_name,element_type, base_class) \
a61af66fc99e Initial load
duke
parents:
diff changeset
121 class array_name: public base_class { \
a61af66fc99e Initial load
duke
parents:
diff changeset
122 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
123 typedef element_type etype; \
a61af66fc99e Initial load
duke
parents:
diff changeset
124 enum { esize = sizeof(etype) }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
125 \
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void base_remove_at(size_t size, int i) { base_class::remove_at(size, i); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
127 \
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
129 /* creation */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
130 array_name() : base_class() {} \
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
131 explicit array_name(const int length) : base_class(esize, length) {} \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
132 array_name(const int length, const etype fx) { initialize(length, fx); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
133 void initialize(const int length) { base_class::initialize(esize, length); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
134 void initialize(const int length, const etype fx) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
135 initialize(length); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
136 for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx; \
a61af66fc99e Initial load
duke
parents:
diff changeset
137 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
138 \
a61af66fc99e Initial load
duke
parents:
diff changeset
139 /* standard operations */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
140 etype& operator [] (const int i) const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
141 assert(0 <= i && i < length(), "index out of bounds"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return ((etype*)_data)[i]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
143 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
144 \
a61af66fc99e Initial load
duke
parents:
diff changeset
145 int index_of(const etype x) const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
146 int i = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
147 while (i-- > 0 && ((etype*)_data)[i] != x) ; \
a61af66fc99e Initial load
duke
parents:
diff changeset
148 /* i < 0 || ((etype*)_data)_data[i] == x */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return i; \
a61af66fc99e Initial load
duke
parents:
diff changeset
150 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
151 \
a61af66fc99e Initial load
duke
parents:
diff changeset
152 void sort(int f(etype*, etype*)) { base_class::sort(esize, (ftype)f); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
153 bool contains(const etype x) const { return index_of(x) >= 0; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
154 \
a61af66fc99e Initial load
duke
parents:
diff changeset
155 /* deprecated operations - for compatibility with GrowableArray only */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
156 etype at(const int i) const { return (*this)[i]; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void at_put(const int i, const etype x) { (*this)[i] = x; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
158 etype* adr_at(const int i) { return &(*this)[i]; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
159 int find(const etype x) { return index_of(x); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 #define define_array(array_name,element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
164 define_generic_array(array_name, element_type, ResourceArray)
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 #define define_stack(stack_name,array_name) \
a61af66fc99e Initial load
duke
parents:
diff changeset
168 class stack_name: public array_name { \
a61af66fc99e Initial load
duke
parents:
diff changeset
169 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
170 int _size; \
a61af66fc99e Initial load
duke
parents:
diff changeset
171 \
a61af66fc99e Initial load
duke
parents:
diff changeset
172 void grow(const int i, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
173 assert(i >= length(), "index too small"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (i >= size()) expand(esize, i, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
175 for (int j = length(); j <= i; j++) ((etype*)_data)[j] = fx; \
a61af66fc99e Initial load
duke
parents:
diff changeset
176 _length = i+1; \
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
178 \
a61af66fc99e Initial load
duke
parents:
diff changeset
179 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
180 /* creation */ \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
181 stack_name() : array_name() { _size = 0; } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
182 stack_name(const int size) { initialize(size); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
183 stack_name(const int size, const etype fx) { initialize(size, fx); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
184 void initialize(const int size, const etype fx) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
185 _size = size; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
186 array_name::initialize(size, fx); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
187 /* _length == size, allocation and size are the same */ \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
188 } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
189 void initialize(const int size) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
190 _size = size; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
191 array_name::initialize(size); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
192 _length = 0; /* reset length to zero; _size records the allocation */ \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
193 } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
194 \
a61af66fc99e Initial load
duke
parents:
diff changeset
195 /* standard operations */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
196 int size() const { return _size; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
197 \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
198 int push(const etype x) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
199 int len = length(); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
200 if (len >= size()) expand(esize, len, _size); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
201 ((etype*)_data)[len] = x; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
202 _length = len+1; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
203 return len; \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
204 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
205 \
a61af66fc99e Initial load
duke
parents:
diff changeset
206 etype pop() { \
a61af66fc99e Initial load
duke
parents:
diff changeset
207 assert(!is_empty(), "stack is empty"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return ((etype*)_data)[--_length]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
209 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
210 \
a61af66fc99e Initial load
duke
parents:
diff changeset
211 etype top() const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
212 assert(!is_empty(), "stack is empty"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
213 return ((etype*)_data)[length() - 1]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
214 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
215 \
a61af66fc99e Initial load
duke
parents:
diff changeset
216 void push_all(const stack_name* stack) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
217 const int l = stack->length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
218 for (int i = 0; i < l; i++) push(((etype*)(stack->_data))[i]); \
a61af66fc99e Initial load
duke
parents:
diff changeset
219 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
220 \
a61af66fc99e Initial load
duke
parents:
diff changeset
221 etype at_grow(const int i, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (i >= length()) grow(i, fx); \
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return ((etype*)_data)[i]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
224 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
225 \
a61af66fc99e Initial load
duke
parents:
diff changeset
226 void at_put_grow(const int i, const etype x, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (i >= length()) grow(i, fx); \
a61af66fc99e Initial load
duke
parents:
diff changeset
228 ((etype*)_data)[i] = x; \
a61af66fc99e Initial load
duke
parents:
diff changeset
229 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
230 \
a61af66fc99e Initial load
duke
parents:
diff changeset
231 void truncate(const int length) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
232 assert(0 <= length && length <= this->length(), "illegal length"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
233 _length = length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
234 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
235 \
a61af66fc99e Initial load
duke
parents:
diff changeset
236 void remove_at(int i) { base_remove_at(esize, i); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
237 void remove(etype x) { remove_at(index_of(x)); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
238 \
a61af66fc99e Initial load
duke
parents:
diff changeset
239 /* inserts the given element before the element at index i */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
240 void insert_before(const int i, const etype el) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
241 int len = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
242 int new_length = len + 1; \
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (new_length >= size()) expand(esize, new_length, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
244 for (int j = len - 1; j >= i; j--) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
245 ((etype*)_data)[j + 1] = ((etype*)_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
246 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
247 _length = new_length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
248 at_put(i, el); \
a61af66fc99e Initial load
duke
parents:
diff changeset
249 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
250 \
a61af66fc99e Initial load
duke
parents:
diff changeset
251 /* inserts contents of the given stack before the element at index i */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
252 void insert_before(const int i, const stack_name *st) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (st->length() == 0) return; \
a61af66fc99e Initial load
duke
parents:
diff changeset
254 int len = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
255 int st_len = st->length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
256 int new_length = len + st_len; \
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (new_length >= size()) expand(esize, new_length, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
258 int j; \
a61af66fc99e Initial load
duke
parents:
diff changeset
259 for (j = len - 1; j >= i; j--) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
260 ((etype*)_data)[j + st_len] = ((etype*)_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
261 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
262 for (j = 0; j < st_len; j++) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
263 ((etype*)_data)[i + j] = ((etype*)st->_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
264 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
265 _length = new_length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
266 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
267 \
a61af66fc99e Initial load
duke
parents:
diff changeset
268 /* deprecated operations - for compatibility with GrowableArray only */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
269 int capacity() const { return size(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
270 void clear() { truncate(0); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void trunc_to(const int length) { truncate(length); } \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
272 int append(const etype x) { return push(x); } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
273 void appendAll(const stack_name* stack) { push_all(stack); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
274 etype last() const { return top(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 #define define_resource_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
279 define_generic_array(element_type##Array, element_type, ResourceArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
280 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 #define define_resource_pointer_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
283 define_generic_array(element_type##Array, element_type *, ResourceArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
284 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 #define define_c_heap_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
287 define_generic_array(element_type##Array, element_type, CHeapArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
288 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 #define define_c_heap_pointer_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
291 define_generic_array(element_type##Array, element_type *, CHeapArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
292 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // Arrays for basic types
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 define_array(boolArray, bool) define_stack(boolStack, boolArray)
a61af66fc99e Initial load
duke
parents:
diff changeset
298 define_array(intArray , int ) define_stack(intStack , intArray )
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
299
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
300 // Array for metadata allocation
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
301
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
302 template <typename T>
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
303 class Array: public MetaspaceObj {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
304 friend class MetadataFactory;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
305 friend class VMStructs;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
306 friend class MethodHandleCompiler; // special case
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
307 protected:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
308 int _length; // the number of array elements
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
309 T _data[1]; // the array memory
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
310
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
311 void initialize(int length) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
312 _length = length;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
313 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
314
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
315 private:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
316 // Turn off copy constructor and assignment operator.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
317 Array(const Array<T>&);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
318 void operator=(const Array<T>&);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
319
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
320 void* operator new(size_t size, ClassLoaderData* loader_data, int length, bool read_only, TRAPS) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
321 size_t word_size = Array::size(length);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
322 return (void*) Metaspace::allocate(loader_data, word_size, read_only,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
323 Metaspace::NonClassType, CHECK_NULL);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
324 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
325
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
326 static size_t byte_sizeof(int length) { return sizeof(Array<T>) + MAX2(length - 1, 0) * sizeof(T); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
327
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
328 explicit Array(int length) : _length(length) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
329 assert(length >= 0, "illegal length");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
330 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
331
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
332 Array(int length, T init) : _length(length) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
333 assert(length >= 0, "illegal length");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
334 for (int i = 0; i < length; i++) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
335 _data[i] = init;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
336 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
337 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
338
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
339 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
340
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
341 // standard operations
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
342 int length() const { return _length; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
343 T* data() { return _data; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
344 bool is_empty() const { return length() == 0; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
345
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
346 int index_of(const T& x) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
347 int i = length();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
348 while (i-- > 0 && _data[i] != x) ;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
349
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
350 return i;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
351 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
352
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
353 // sort the array.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
354 bool contains(const T& x) const { return index_of(x) >= 0; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
355
6972
bd7a7ce2e264 6830717: replay of compilations would help with debugging
minqi
parents: 6725
diff changeset
356 T at(int i) const { assert(i >= 0 && i< _length, err_msg_res("oob: 0 <= %d < %d", i, _length)); return _data[i]; }
bd7a7ce2e264 6830717: replay of compilations would help with debugging
minqi
parents: 6725
diff changeset
357 void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, err_msg_res("oob: 0 <= %d < %d", i, _length)); _data[i] = x; }
bd7a7ce2e264 6830717: replay of compilations would help with debugging
minqi
parents: 6725
diff changeset
358 T* adr_at(const int i) { assert(i >= 0 && i< _length, err_msg_res("oob: 0 <= %d < %d", i, _length)); return &_data[i]; }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
359 int find(const T& x) { return index_of(x); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
360
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
361 T at_acquire(const int which) { return OrderAccess::load_acquire(adr_at(which)); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
362 void release_at_put(int which, T contents) { OrderAccess::release_store(adr_at(which), contents); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
363
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
364 static int size(int length) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
365 return align_size_up(byte_sizeof(length), BytesPerWord) / BytesPerWord;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
366 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
367
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
368 int size() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
369 return size(_length);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
370 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
371
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
372 static int length_offset_in_bytes() { return (int) (offset_of(Array<T>, _length)); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
373 // Note, this offset don't have to be wordSize aligned.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
374 static int base_offset_in_bytes() { return (int) (offset_of(Array<T>, _data)); };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
375
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
376 // FIXME: How to handle this?
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
377 void print_value_on(outputStream* st) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
378 st->print("Array<T>(" INTPTR_FORMAT ")", this);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
379 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
380
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
381 #ifndef PRODUCT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
382 void print(outputStream* st) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
383 for (int i = 0; i< _length; i++) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
384 st->print_cr("%d: " INTPTR_FORMAT, i, (intptr_t)at(i));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
385 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
386 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
387 void print() { print(tty); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
388 #endif // PRODUCT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
389 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
390
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
391
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
392 #endif // SHARE_VM_UTILITIES_ARRAY_HPP