annotate src/share/vm/utilities/array.hpp @ 1994:6cd6d394f280

7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed()) 7002546: regression on SpecJbb2005 on 7b118 comparing to 7b117 on small heaps Summary: Relaxed assertion checking related to incremental_collection_failed flag to allow for ExplicitGCInvokesConcurrent behaviour where we do not want a failing scavenge to bail to a stop-world collection. Parameterized incremental_collection_will_fail() so we can selectively use, or not use, as appropriate, the statistical prediction at specific use sites. This essentially reverts the scavenge bail-out logic to what it was prior to some recent changes that had inadvertently started using the statistical prediction which can be noisy in the presence of bursty loads. Added some associated verbose non-product debugging messages. Reviewed-by: johnc, tonyp
author ysr
date Tue, 07 Dec 2010 21:55:53 -0800
parents f95d63e2154a
children d2a62e0f25eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2010, 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"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // correct linkage required to compile w/o warnings
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // (must be on file level - cannot be local)
a61af66fc99e Initial load
duke
parents:
diff changeset
33 extern "C" { typedef int (*ftype)(const void*, const void*); }
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 class ResourceArray: public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 int _length; // the number of array elements
a61af66fc99e Initial load
duke
parents:
diff changeset
39 void* _data; // the array memory
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
41 int _nesting; // the resource area nesting level
a61af66fc99e Initial load
duke
parents:
diff changeset
42 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // creation
a61af66fc99e Initial load
duke
parents:
diff changeset
45 ResourceArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 _length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _data = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 DEBUG_ONLY(init_nesting();)
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
49 // client may call initialize, at most once
0
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 ResourceArray(size_t esize, int length) {
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
54 DEBUG_ONLY(_data = NULL);
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
55 initialize(esize, length);
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
56 }
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
57
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
58 void initialize(size_t esize, int length) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59 assert(length >= 0, "illegal length");
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
60 assert(_data == NULL, "must be new object");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _length = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _data = resource_allocate_bytes(esize * length);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 DEBUG_ONLY(init_nesting();)
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void init_nesting();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void sort (size_t esize, ftype f); // sort the array
a61af66fc99e Initial load
duke
parents:
diff changeset
72 void expand (size_t esize, int i, int& size);// expand the array to include slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
73 void remove_at(size_t esize, int i); // remove the element in slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // standard operations
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 bool is_empty() const { return length() == 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 };
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 class CHeapArray: public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int _length; // the number of array elements
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void* _data; // the array memory
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // creation
a61af66fc99e Initial load
duke
parents:
diff changeset
88 CHeapArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 _length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _data = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 CHeapArray(size_t esize, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 assert(length >= 0, "illegal length");
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _length = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _data = (void*) NEW_C_HEAP_ARRAY(char *, esize * length);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
101 void init_nesting();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
105 void sort (size_t esize, ftype f); // sort the array
a61af66fc99e Initial load
duke
parents:
diff changeset
106 void expand (size_t esize, int i, int& size);// expand the array to include slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void remove_at(size_t esize, int i); // remove the element in slot i
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // standard operations
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 bool is_empty() const { return length() == 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 };
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 #define define_generic_array(array_name,element_type, base_class) \
a61af66fc99e Initial load
duke
parents:
diff changeset
116 class array_name: public base_class { \
a61af66fc99e Initial load
duke
parents:
diff changeset
117 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
118 typedef element_type etype; \
a61af66fc99e Initial load
duke
parents:
diff changeset
119 enum { esize = sizeof(etype) }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
120 \
a61af66fc99e Initial load
duke
parents:
diff changeset
121 void base_remove_at(size_t size, int i) { base_class::remove_at(size, i); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
122 \
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
124 /* creation */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
125 array_name() : base_class() {} \
a61af66fc99e Initial load
duke
parents:
diff changeset
126 array_name(const int length) : base_class(esize, length) {} \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
127 array_name(const int length, const etype fx) { initialize(length, fx); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
128 void initialize(const int length) { base_class::initialize(esize, length); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
129 void initialize(const int length, const etype fx) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
130 initialize(length); \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 for (int i = 0; i < length; i++) ((etype*)_data)[i] = fx; \
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
133 \
a61af66fc99e Initial load
duke
parents:
diff changeset
134 /* standard operations */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
135 etype& operator [] (const int i) const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
136 assert(0 <= i && i < length(), "index out of bounds"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return ((etype*)_data)[i]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
138 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
139 \
a61af66fc99e Initial load
duke
parents:
diff changeset
140 int index_of(const etype x) const { \
a61af66fc99e Initial load
duke
parents:
diff changeset
141 int i = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
142 while (i-- > 0 && ((etype*)_data)[i] != x) ; \
a61af66fc99e Initial load
duke
parents:
diff changeset
143 /* i < 0 || ((etype*)_data)_data[i] == x */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return i; \
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
146 \
a61af66fc99e Initial load
duke
parents:
diff changeset
147 void sort(int f(etype*, etype*)) { base_class::sort(esize, (ftype)f); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
148 bool contains(const etype x) const { return index_of(x) >= 0; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
149 \
a61af66fc99e Initial load
duke
parents:
diff changeset
150 /* deprecated operations - for compatibility with GrowableArray only */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
151 etype at(const int i) const { return (*this)[i]; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
152 void at_put(const int i, const etype x) { (*this)[i] = x; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
153 etype* adr_at(const int i) { return &(*this)[i]; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
154 int find(const etype x) { return index_of(x); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 #define define_array(array_name,element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
159 define_generic_array(array_name, element_type, ResourceArray)
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 #define define_stack(stack_name,array_name) \
a61af66fc99e Initial load
duke
parents:
diff changeset
163 class stack_name: public array_name { \
a61af66fc99e Initial load
duke
parents:
diff changeset
164 protected: \
a61af66fc99e Initial load
duke
parents:
diff changeset
165 int _size; \
a61af66fc99e Initial load
duke
parents:
diff changeset
166 \
a61af66fc99e Initial load
duke
parents:
diff changeset
167 void grow(const int i, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
168 assert(i >= length(), "index too small"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (i >= size()) expand(esize, i, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
170 for (int j = length(); j <= i; j++) ((etype*)_data)[j] = fx; \
a61af66fc99e Initial load
duke
parents:
diff changeset
171 _length = i+1; \
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
173 \
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public: \
a61af66fc99e Initial load
duke
parents:
diff changeset
175 /* creation */ \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
176 stack_name() : array_name() { _size = 0; } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
177 stack_name(const int size) { initialize(size); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
178 stack_name(const int size, const etype fx) { initialize(size, fx); } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
179 void initialize(const int size, const etype fx) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
180 _size = size; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
181 array_name::initialize(size, fx); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
182 /* _length == size, allocation and size are the same */ \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
183 } \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
184 void initialize(const int size) { \
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); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
187 _length = 0; /* reset length to zero; _size records the allocation */ \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
188 } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
189 \
a61af66fc99e Initial load
duke
parents:
diff changeset
190 /* standard operations */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
191 int size() const { return _size; } \
a61af66fc99e Initial load
duke
parents:
diff changeset
192 \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
193 int push(const etype x) { \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
194 int len = length(); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
195 if (len >= size()) expand(esize, len, _size); \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
196 ((etype*)_data)[len] = x; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
197 _length = len+1; \
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
198 return len; \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
199 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
200 \
a61af66fc99e Initial load
duke
parents:
diff changeset
201 etype pop() { \
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert(!is_empty(), "stack is empty"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return ((etype*)_data)[--_length]; \
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 top() const { \
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() - 1]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
209 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
210 \
a61af66fc99e Initial load
duke
parents:
diff changeset
211 void push_all(const stack_name* stack) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
212 const int l = stack->length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
213 for (int i = 0; i < l; i++) push(((etype*)(stack->_data))[i]); \
a61af66fc99e Initial load
duke
parents:
diff changeset
214 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
215 \
a61af66fc99e Initial load
duke
parents:
diff changeset
216 etype at_grow(const int i, const etype fx) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
217 if (i >= length()) grow(i, fx); \
a61af66fc99e Initial load
duke
parents:
diff changeset
218 return ((etype*)_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 void at_put_grow(const int i, const etype x, 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 ((etype*)_data)[i] = x; \
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 truncate(const int length) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
227 assert(0 <= length && length <= this->length(), "illegal length"); \
a61af66fc99e Initial load
duke
parents:
diff changeset
228 _length = length; \
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 remove_at(int i) { base_remove_at(esize, i); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
232 void remove(etype x) { remove_at(index_of(x)); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
233 \
a61af66fc99e Initial load
duke
parents:
diff changeset
234 /* inserts the given element before the element at index i */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
235 void insert_before(const int i, const etype el) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
236 int len = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
237 int new_length = len + 1; \
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (new_length >= size()) expand(esize, new_length, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
239 for (int j = len - 1; j >= i; j--) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
240 ((etype*)_data)[j + 1] = ((etype*)_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
241 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
242 _length = new_length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
243 at_put(i, el); \
a61af66fc99e Initial load
duke
parents:
diff changeset
244 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
245 \
a61af66fc99e Initial load
duke
parents:
diff changeset
246 /* inserts contents of the given stack before the element at index i */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
247 void insert_before(const int i, const stack_name *st) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if (st->length() == 0) return; \
a61af66fc99e Initial load
duke
parents:
diff changeset
249 int len = length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
250 int st_len = st->length(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
251 int new_length = len + st_len; \
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if (new_length >= size()) expand(esize, new_length, _size); \
a61af66fc99e Initial load
duke
parents:
diff changeset
253 int j; \
a61af66fc99e Initial load
duke
parents:
diff changeset
254 for (j = len - 1; j >= i; j--) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
255 ((etype*)_data)[j + st_len] = ((etype*)_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
256 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
257 for (j = 0; j < st_len; j++) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
258 ((etype*)_data)[i + j] = ((etype*)st->_data)[j]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
259 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
260 _length = new_length; \
a61af66fc99e Initial load
duke
parents:
diff changeset
261 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
262 \
a61af66fc99e Initial load
duke
parents:
diff changeset
263 /* deprecated operations - for compatibility with GrowableArray only */ \
a61af66fc99e Initial load
duke
parents:
diff changeset
264 int capacity() const { return size(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
265 void clear() { truncate(0); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
266 void trunc_to(const int length) { truncate(length); } \
432
275a3b7ff0d6 6770949: minor tweaks before 6655638
jrose
parents: 0
diff changeset
267 int append(const etype x) { return push(x); } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
268 void appendAll(const stack_name* stack) { push_all(stack); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
269 etype last() const { return top(); } \
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }; \
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 #define define_resource_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
274 define_generic_array(element_type##Array, element_type, ResourceArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
275 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 #define define_resource_pointer_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
278 define_generic_array(element_type##Array, element_type *, ResourceArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
279 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 #define define_c_heap_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
282 define_generic_array(element_type##Array, element_type, CHeapArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
283 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 #define define_c_heap_pointer_list(element_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
286 define_generic_array(element_type##Array, element_type *, CHeapArray) \
a61af66fc99e Initial load
duke
parents:
diff changeset
287 define_stack(element_type##List, element_type##Array)
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // Arrays for basic types
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 define_array(boolArray, bool) define_stack(boolStack, boolArray)
a61af66fc99e Initial load
duke
parents:
diff changeset
293 define_array(intArray , int ) define_stack(intStack , intArray )
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
294
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
295 #endif // SHARE_VM_UTILITIES_ARRAY_HPP