Mercurial > hg > graal-compiler
annotate src/share/vm/oops/typeArrayKlass.cpp @ 5935:a735aec54ea4
7123170: JCK vm/jvmti/ResourceExhausted/resexh001/resexh00101/ tests fails since 7u4 b02
Summary: The JVMTI ResourceExhausted events must be generated in all places where OOME is thrown
Reviewed-by: acorn, coleenp, dcubed, dholmes, dsamersoff, jwilhelm, tonyp
Contributed-by: serguei.spitsyn@oracle.com
author | sspitsyn |
---|---|
date | Wed, 14 Mar 2012 20:06:48 -0700 |
parents | a92cdbac8b9e |
children | fc9d8850ab8b |
rev | line source |
---|---|
0 | 1 /* |
5935
a735aec54ea4
7123170: JCK vm/jvmti/ResourceExhausted/resexh001/resexh00101/ tests fails since 7u4 b02
sspitsyn
parents:
3961
diff
changeset
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1334
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1334
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:
1334
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "classfile/vmSymbols.hpp" | |
28 #include "gc_interface/collectedHeap.hpp" | |
29 #include "gc_interface/collectedHeap.inline.hpp" | |
30 #include "memory/resourceArea.hpp" | |
31 #include "memory/universe.hpp" | |
32 #include "memory/universe.inline.hpp" | |
33 #include "oops/instanceKlass.hpp" | |
34 #include "oops/klassOop.hpp" | |
35 #include "oops/objArrayKlassKlass.hpp" | |
36 #include "oops/oop.inline.hpp" | |
37 #include "oops/typeArrayKlass.hpp" | |
38 #include "oops/typeArrayOop.hpp" | |
39 #include "runtime/handles.inline.hpp" | |
0 | 40 |
41 bool typeArrayKlass::compute_is_subtype_of(klassOop k) { | |
42 if (!k->klass_part()->oop_is_typeArray()) { | |
43 return arrayKlass::compute_is_subtype_of(k); | |
44 } | |
45 | |
46 typeArrayKlass* tak = typeArrayKlass::cast(k); | |
47 if (dimension() != tak->dimension()) return false; | |
48 | |
49 return element_type() == tak->element_type(); | |
50 } | |
51 | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
0
diff
changeset
|
52 klassOop typeArrayKlass::create_klass(BasicType type, int scale, |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
0
diff
changeset
|
53 const char* name_str, TRAPS) { |
0 | 54 typeArrayKlass o; |
55 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2119
diff
changeset
|
56 Symbol* sym = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2119
diff
changeset
|
57 if (name_str != NULL) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2119
diff
changeset
|
58 sym = SymbolTable::new_symbol(name_str, CHECK_NULL); |
0 | 59 } |
60 KlassHandle klassklass (THREAD, Universe::typeArrayKlassKlassObj()); | |
61 | |
62 arrayKlassHandle k = base_create_array_klass(o.vtbl_value(), header_size(), klassklass, CHECK_NULL); | |
63 typeArrayKlass* ak = typeArrayKlass::cast(k()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2119
diff
changeset
|
64 ak->set_name(sym); |
0 | 65 ak->set_layout_helper(array_layout_helper(type)); |
66 assert(scale == (1 << ak->log2_element_size()), "scale must check out"); | |
67 assert(ak->oop_is_javaArray(), "sanity"); | |
68 assert(ak->oop_is_typeArray(), "sanity"); | |
69 ak->set_max_length(arrayOopDesc::max_array_length(type)); | |
70 assert(k()->size() > header_size(), "bad size"); | |
71 | |
72 // Call complete_create_array_klass after all instance variables have been initialized. | |
73 KlassHandle super (THREAD, k->super()); | |
74 complete_create_array_klass(k, super, CHECK_NULL); | |
75 | |
76 return k(); | |
77 } | |
78 | |
3961
a92cdbac8b9e
7081933: Use zeroing elimination optimization for large array
kvn
parents:
3774
diff
changeset
|
79 typeArrayOop typeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) { |
0 | 80 assert(log2_element_size() >= 0, "bad scale"); |
81 if (length >= 0) { | |
82 if (length <= max_length()) { | |
83 size_t size = typeArrayOopDesc::object_size(layout_helper(), length); | |
84 KlassHandle h_k(THREAD, as_klassOop()); | |
85 typeArrayOop t; | |
86 CollectedHeap* ch = Universe::heap(); | |
3961
a92cdbac8b9e
7081933: Use zeroing elimination optimization for large array
kvn
parents:
3774
diff
changeset
|
87 if (do_zero) { |
a92cdbac8b9e
7081933: Use zeroing elimination optimization for large array
kvn
parents:
3774
diff
changeset
|
88 t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL); |
a92cdbac8b9e
7081933: Use zeroing elimination optimization for large array
kvn
parents:
3774
diff
changeset
|
89 } else { |
a92cdbac8b9e
7081933: Use zeroing elimination optimization for large array
kvn
parents:
3774
diff
changeset
|
90 t = (typeArrayOop)CollectedHeap::array_allocate_nozero(h_k, (int)size, length, CHECK_NULL); |
a92cdbac8b9e
7081933: Use zeroing elimination optimization for large array
kvn
parents:
3774
diff
changeset
|
91 } |
0 | 92 assert(t->is_parsable(), "Don't publish unless parsable"); |
93 return t; | |
94 } else { | |
876
1413494da700
6850957: Honor -XX:OnOutOfMemoryError when array size exceeds VM limit
martin
parents:
579
diff
changeset
|
95 report_java_out_of_memory("Requested array size exceeds VM limit"); |
5935
a735aec54ea4
7123170: JCK vm/jvmti/ResourceExhausted/resexh001/resexh00101/ tests fails since 7u4 b02
sspitsyn
parents:
3961
diff
changeset
|
96 JvmtiExport::post_array_size_exhausted(); |
0 | 97 THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
98 } | |
99 } else { | |
100 THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); | |
101 } | |
102 } | |
103 | |
104 typeArrayOop typeArrayKlass::allocate_permanent(int length, TRAPS) { | |
105 if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); | |
106 int size = typeArrayOopDesc::object_size(layout_helper(), length); | |
107 KlassHandle h_k(THREAD, as_klassOop()); | |
108 typeArrayOop t = (typeArrayOop) | |
109 CollectedHeap::permanent_array_allocate(h_k, size, length, CHECK_NULL); | |
110 assert(t->is_parsable(), "Can't publish until parsable"); | |
111 return t; | |
112 } | |
113 | |
114 oop typeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) { | |
115 // For typeArrays this is only called for the last dimension | |
116 assert(rank == 1, "just checking"); | |
117 int length = *last_size; | |
118 return allocate(length, THREAD); | |
119 } | |
120 | |
121 | |
122 void typeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) { | |
123 assert(s->is_typeArray(), "must be type array"); | |
124 | |
125 // Check destination | |
126 if (!d->is_typeArray() || element_type() != typeArrayKlass::cast(d->klass())->element_type()) { | |
127 THROW(vmSymbols::java_lang_ArrayStoreException()); | |
128 } | |
129 | |
130 // Check is all offsets and lengths are non negative | |
131 if (src_pos < 0 || dst_pos < 0 || length < 0) { | |
132 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); | |
133 } | |
134 // Check if the ranges are valid | |
135 if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) | |
136 || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) { | |
137 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); | |
138 } | |
1334
b5d78a3b8843
6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents:
876
diff
changeset
|
139 // Check zero copy |
b5d78a3b8843
6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents:
876
diff
changeset
|
140 if (length == 0) |
b5d78a3b8843
6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents:
876
diff
changeset
|
141 return; |
0 | 142 |
143 // This is an attempt to make the copy_array fast. | |
144 int l2es = log2_element_size(); | |
145 int ihs = array_header_in_bytes() / wordSize; | |
1334
b5d78a3b8843
6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents:
876
diff
changeset
|
146 char* src = (char*) ((oop*)s + ihs) + ((size_t)src_pos << l2es); |
b5d78a3b8843
6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents:
876
diff
changeset
|
147 char* dst = (char*) ((oop*)d + ihs) + ((size_t)dst_pos << l2es); |
b5d78a3b8843
6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
kvn
parents:
876
diff
changeset
|
148 Copy::conjoint_memory_atomic(src, dst, (size_t)length << l2es); |
0 | 149 } |
150 | |
151 | |
152 // create a klass of array holding typeArrays | |
153 klassOop typeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) { | |
154 typeArrayKlassHandle h_this(THREAD, as_klassOop()); | |
155 return array_klass_impl(h_this, or_null, n, THREAD); | |
156 } | |
157 | |
158 klassOop typeArrayKlass::array_klass_impl(typeArrayKlassHandle h_this, bool or_null, int n, TRAPS) { | |
159 int dimension = h_this->dimension(); | |
160 assert(dimension <= n, "check order of chain"); | |
161 if (dimension == n) | |
162 return h_this(); | |
163 | |
164 objArrayKlassHandle h_ak(THREAD, h_this->higher_dimension()); | |
165 if (h_ak.is_null()) { | |
166 if (or_null) return NULL; | |
167 | |
168 ResourceMark rm; | |
169 JavaThread *jt = (JavaThread *)THREAD; | |
170 { | |
171 MutexLocker mc(Compile_lock, THREAD); // for vtables | |
172 // Atomic create higher dimension and link into list | |
173 MutexLocker mu(MultiArray_lock, THREAD); | |
174 | |
175 h_ak = objArrayKlassHandle(THREAD, h_this->higher_dimension()); | |
176 if (h_ak.is_null()) { | |
177 klassOop oak = objArrayKlassKlass::cast( | |
178 Universe::objArrayKlassKlassObj())->allocate_objArray_klass( | |
179 dimension + 1, h_this, CHECK_NULL); | |
180 h_ak = objArrayKlassHandle(THREAD, oak); | |
181 h_ak->set_lower_dimension(h_this()); | |
2119 | 182 OrderAccess::storestore(); |
0 | 183 h_this->set_higher_dimension(h_ak()); |
184 assert(h_ak->oop_is_objArray(), "incorrect initialization of objArrayKlass"); | |
185 } | |
186 } | |
187 } else { | |
188 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); | |
189 } | |
190 if (or_null) { | |
191 return h_ak->array_klass_or_null(n); | |
192 } | |
193 return h_ak->array_klass(n, CHECK_NULL); | |
194 } | |
195 | |
196 klassOop typeArrayKlass::array_klass_impl(bool or_null, TRAPS) { | |
197 return array_klass_impl(or_null, dimension() + 1, THREAD); | |
198 } | |
199 | |
200 int typeArrayKlass::oop_size(oop obj) const { | |
201 assert(obj->is_typeArray(),"must be a type array"); | |
202 typeArrayOop t = typeArrayOop(obj); | |
203 return t->object_size(); | |
204 } | |
205 | |
206 void typeArrayKlass::oop_follow_contents(oop obj) { | |
207 assert(obj->is_typeArray(),"must be a type array"); | |
208 // Performance tweak: We skip iterating over the klass pointer since we | |
209 // know that Universe::typeArrayKlass never moves. | |
210 } | |
211 | |
212 #ifndef SERIALGC | |
213 void typeArrayKlass::oop_follow_contents(ParCompactionManager* cm, oop obj) { | |
214 assert(obj->is_typeArray(),"must be a type array"); | |
215 // Performance tweak: We skip iterating over the klass pointer since we | |
216 // know that Universe::typeArrayKlass never moves. | |
217 } | |
218 #endif // SERIALGC | |
219 | |
220 int typeArrayKlass::oop_adjust_pointers(oop obj) { | |
221 assert(obj->is_typeArray(),"must be a type array"); | |
222 typeArrayOop t = typeArrayOop(obj); | |
223 // Performance tweak: We skip iterating over the klass pointer since we | |
224 // know that Universe::typeArrayKlass never moves. | |
225 return t->object_size(); | |
226 } | |
227 | |
228 int typeArrayKlass::oop_oop_iterate(oop obj, OopClosure* blk) { | |
229 assert(obj->is_typeArray(),"must be a type array"); | |
230 typeArrayOop t = typeArrayOop(obj); | |
231 // Performance tweak: We skip iterating over the klass pointer since we | |
232 // know that Universe::typeArrayKlass never moves. | |
233 return t->object_size(); | |
234 } | |
235 | |
236 int typeArrayKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { | |
237 assert(obj->is_typeArray(),"must be a type array"); | |
238 typeArrayOop t = typeArrayOop(obj); | |
239 // Performance tweak: We skip iterating over the klass pointer since we | |
240 // know that Universe::typeArrayKlass never moves. | |
241 return t->object_size(); | |
242 } | |
243 | |
244 #ifndef SERIALGC | |
245 void typeArrayKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { | |
246 assert(obj->is_typeArray(),"must be a type array"); | |
247 } | |
248 | |
249 int | |
250 typeArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { | |
251 assert(obj->is_typeArray(),"must be a type array"); | |
252 return typeArrayOop(obj)->object_size(); | |
253 } | |
254 #endif // SERIALGC | |
255 | |
256 void typeArrayKlass::initialize(TRAPS) { | |
257 // Nothing to do. Having this function is handy since objArrayKlasses can be | |
258 // initialized by calling initialize on their bottom_klass, see objArrayKlass::initialize | |
259 } | |
260 | |
261 const char* typeArrayKlass::external_name(BasicType type) { | |
262 switch (type) { | |
263 case T_BOOLEAN: return "[Z"; | |
264 case T_CHAR: return "[C"; | |
265 case T_FLOAT: return "[F"; | |
266 case T_DOUBLE: return "[D"; | |
267 case T_BYTE: return "[B"; | |
268 case T_SHORT: return "[S"; | |
269 case T_INT: return "[I"; | |
270 case T_LONG: return "[J"; | |
271 default: ShouldNotReachHere(); | |
272 } | |
273 return NULL; | |
274 } | |
275 | |
276 #ifndef PRODUCT | |
277 // Printing | |
278 | |
279 static void print_boolean_array(typeArrayOop ta, int print_len, outputStream* st) { | |
280 for (int index = 0; index < print_len; index++) { | |
281 st->print_cr(" - %3d: %s", index, (ta->bool_at(index) == 0) ? "false" : "true"); | |
282 } | |
283 } | |
284 | |
285 | |
286 static void print_char_array(typeArrayOop ta, int print_len, outputStream* st) { | |
287 for (int index = 0; index < print_len; index++) { | |
288 jchar c = ta->char_at(index); | |
289 st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' '); | |
290 } | |
291 } | |
292 | |
293 | |
294 static void print_float_array(typeArrayOop ta, int print_len, outputStream* st) { | |
295 for (int index = 0; index < print_len; index++) { | |
296 st->print_cr(" - %3d: %g", index, ta->float_at(index)); | |
297 } | |
298 } | |
299 | |
300 | |
301 static void print_double_array(typeArrayOop ta, int print_len, outputStream* st) { | |
302 for (int index = 0; index < print_len; index++) { | |
303 st->print_cr(" - %3d: %g", index, ta->double_at(index)); | |
304 } | |
305 } | |
306 | |
307 | |
308 static void print_byte_array(typeArrayOop ta, int print_len, outputStream* st) { | |
309 for (int index = 0; index < print_len; index++) { | |
310 jbyte c = ta->byte_at(index); | |
311 st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' '); | |
312 } | |
313 } | |
314 | |
315 | |
316 static void print_short_array(typeArrayOop ta, int print_len, outputStream* st) { | |
317 for (int index = 0; index < print_len; index++) { | |
318 int v = ta->ushort_at(index); | |
319 st->print_cr(" - %3d: 0x%x\t %d", index, v, v); | |
320 } | |
321 } | |
322 | |
323 | |
324 static void print_int_array(typeArrayOop ta, int print_len, outputStream* st) { | |
325 for (int index = 0; index < print_len; index++) { | |
326 jint v = ta->int_at(index); | |
327 st->print_cr(" - %3d: 0x%x %d", index, v, v); | |
328 } | |
329 } | |
330 | |
331 | |
332 static void print_long_array(typeArrayOop ta, int print_len, outputStream* st) { | |
333 for (int index = 0; index < print_len; index++) { | |
334 jlong v = ta->long_at(index); | |
335 st->print_cr(" - %3d: 0x%x 0x%x", index, high(v), low(v)); | |
336 } | |
337 } | |
338 | |
339 | |
340 void typeArrayKlass::oop_print_on(oop obj, outputStream* st) { | |
341 arrayKlass::oop_print_on(obj, st); | |
342 typeArrayOop ta = typeArrayOop(obj); | |
343 int print_len = MIN2((intx) ta->length(), MaxElementPrintSize); | |
344 switch (element_type()) { | |
345 case T_BOOLEAN: print_boolean_array(ta, print_len, st); break; | |
346 case T_CHAR: print_char_array(ta, print_len, st); break; | |
347 case T_FLOAT: print_float_array(ta, print_len, st); break; | |
348 case T_DOUBLE: print_double_array(ta, print_len, st); break; | |
349 case T_BYTE: print_byte_array(ta, print_len, st); break; | |
350 case T_SHORT: print_short_array(ta, print_len, st); break; | |
351 case T_INT: print_int_array(ta, print_len, st); break; | |
352 case T_LONG: print_long_array(ta, print_len, st); break; | |
353 default: ShouldNotReachHere(); | |
354 } | |
355 int remaining = ta->length() - print_len; | |
356 if (remaining > 0) { | |
357 tty->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining); | |
358 } | |
359 } | |
360 | |
361 #endif // PRODUCT | |
362 | |
363 const char* typeArrayKlass::internal_name() const { | |
364 return Klass::external_name(); | |
365 } |