121 }
122
123 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
124 // For typeArrays this is only called for the last dimension
125 assert(rank == 1, "just checking");
126 int length = *last_size;
127 return allocate(length, THREAD);
128 }
129
130
131 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
132 assert(s->is_typeArray(), "must be type array");
133
134 // Check destination
135 if (!d->is_typeArray() || element_type() != TypeArrayKlass::cast(d->klass())->element_type()) {
136 THROW(vmSymbols::java_lang_ArrayStoreException());
137 }
138
139 // Check is all offsets and lengths are non negative
140 if (src_pos < 0 || dst_pos < 0 || length < 0) {
141 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
142 }
143 // Check if the ranges are valid
144 if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
145 || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
146 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
147 }
148 // Check zero copy
149 if (length == 0)
150 return;
151
152 // This is an attempt to make the copy_array fast.
153 int l2es = log2_element_size();
154 int ihs = array_header_in_bytes() / wordSize;
155 void* src = (char*) (s->base(element_type())) + ((size_t)src_pos << l2es);
156 void* dst = (char*) (d->base(element_type())) + ((size_t)dst_pos << l2es);
157 HeapAccess<ARRAYCOPY_ATOMIC>::arraycopy(s, d, src, dst, (size_t)length << l2es);
158 }
159
160
161 // create a klass of array holding typeArrays
162 Klass* TypeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
163 int dim = dimension();
164 assert(dim <= n, "check order of chain");
165 if (dim == n)
166 return this;
167
168 // lock-free read needs acquire semantics
169 if (higher_dimension_acquire() == NULL) {
170 if (or_null) return NULL;
171
172 ResourceMark rm;
173 JavaThread *jt = (JavaThread *)THREAD;
174 {
175 MutexLocker mc(Compile_lock, THREAD); // for vtables
176 // Atomic create higher dimension and link into list
177 MutexLocker mu(MultiArray_lock, THREAD);
178
179 if (higher_dimension() == NULL) {
180 Klass* oak = ObjArrayKlass::allocate_objArray_klass(
223 case T_LONG: return "[J";
224 default: ShouldNotReachHere();
225 }
226 return NULL;
227 }
228
229
230 // Printing
231
232 void TypeArrayKlass::print_on(outputStream* st) const {
233 #ifndef PRODUCT
234 assert(is_klass(), "must be klass");
235 print_value_on(st);
236 Klass::print_on(st);
237 #endif //PRODUCT
238 }
239
240 void TypeArrayKlass::print_value_on(outputStream* st) const {
241 assert(is_klass(), "must be klass");
242 st->print("{type array ");
243 switch (element_type()) {
244 case T_BOOLEAN: st->print("bool"); break;
245 case T_CHAR: st->print("char"); break;
246 case T_FLOAT: st->print("float"); break;
247 case T_DOUBLE: st->print("double"); break;
248 case T_BYTE: st->print("byte"); break;
249 case T_SHORT: st->print("short"); break;
250 case T_INT: st->print("int"); break;
251 case T_LONG: st->print("long"); break;
252 default: ShouldNotReachHere();
253 }
254 st->print("}");
255 }
256
257 #ifndef PRODUCT
258
259 static void print_boolean_array(typeArrayOop ta, int print_len, outputStream* st) {
260 for (int index = 0; index < print_len; index++) {
261 st->print_cr(" - %3d: %s", index, (ta->bool_at(index) == 0) ? "false" : "true");
262 }
263 }
264
265
266 static void print_char_array(typeArrayOop ta, int print_len, outputStream* st) {
267 for (int index = 0; index < print_len; index++) {
268 jchar c = ta->char_at(index);
269 st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' ');
270 }
271 }
272
|
121 }
122
123 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
124 // For typeArrays this is only called for the last dimension
125 assert(rank == 1, "just checking");
126 int length = *last_size;
127 return allocate(length, THREAD);
128 }
129
130
131 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
132 assert(s->is_typeArray(), "must be type array");
133
134 // Check destination
135 if (!d->is_typeArray() || element_type() != TypeArrayKlass::cast(d->klass())->element_type()) {
136 THROW(vmSymbols::java_lang_ArrayStoreException());
137 }
138
139 // Check is all offsets and lengths are non negative
140 if (src_pos < 0 || dst_pos < 0 || length < 0) {
141 // Pass specific exception reason.
142 ResourceMark rm;
143 stringStream ss;
144 if (src_pos < 0) {
145 ss.print("arraycopy source index %i out of bounds for %s[%i].",
146 src_pos, type2name_tab[ArrayKlass::cast(s->klass())->element_type()], s->length());
147 } else if (dst_pos < 0) {
148 ss.print("arraycopy destination index %i out of bounds for %s[%i].",
149 dst_pos, type2name_tab[ArrayKlass::cast(d->klass())->element_type()], d->length());
150 } else {
151 ss.print("arraycopy length %i is negative.", length);
152 }
153 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
154 }
155 // Check if the ranges are valid
156 if ((((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) ||
157 (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length())) {
158 // Pass specific exception reason.
159 ResourceMark rm;
160 stringStream ss;
161 if (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) {
162 ss.print("arraycopy: last source index %u out of bounds for %s[%i].",
163 (unsigned int) length + (unsigned int) src_pos,
164 type2name_tab[ArrayKlass::cast(s->klass())->element_type()], s->length());
165 } else {
166 ss.print("arraycopy: last destination index %u out of bounds for %s[%i].",
167 (unsigned int) length + (unsigned int) dst_pos,
168 type2name_tab[ArrayKlass::cast(d->klass())->element_type()], d->length());
169 }
170 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
171 }
172 // Check zero copy
173 if (length == 0)
174 return;
175
176 // This is an attempt to make the copy_array fast.
177 int l2es = log2_element_size();
178 int ihs = array_header_in_bytes() / wordSize;
179 void* src = (char*) (s->base(element_type())) + ((size_t)src_pos << l2es);
180 void* dst = (char*) (d->base(element_type())) + ((size_t)dst_pos << l2es);
181 HeapAccess<ARRAYCOPY_ATOMIC>::arraycopy(s, d, src, dst, (size_t)length << l2es);
182 }
183
184 // create a klass of array holding typeArrays
185 Klass* TypeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
186 int dim = dimension();
187 assert(dim <= n, "check order of chain");
188 if (dim == n)
189 return this;
190
191 // lock-free read needs acquire semantics
192 if (higher_dimension_acquire() == NULL) {
193 if (or_null) return NULL;
194
195 ResourceMark rm;
196 JavaThread *jt = (JavaThread *)THREAD;
197 {
198 MutexLocker mc(Compile_lock, THREAD); // for vtables
199 // Atomic create higher dimension and link into list
200 MutexLocker mu(MultiArray_lock, THREAD);
201
202 if (higher_dimension() == NULL) {
203 Klass* oak = ObjArrayKlass::allocate_objArray_klass(
246 case T_LONG: return "[J";
247 default: ShouldNotReachHere();
248 }
249 return NULL;
250 }
251
252
253 // Printing
254
255 void TypeArrayKlass::print_on(outputStream* st) const {
256 #ifndef PRODUCT
257 assert(is_klass(), "must be klass");
258 print_value_on(st);
259 Klass::print_on(st);
260 #endif //PRODUCT
261 }
262
263 void TypeArrayKlass::print_value_on(outputStream* st) const {
264 assert(is_klass(), "must be klass");
265 st->print("{type array ");
266 BasicType bt = element_type();
267 if (bt == T_BOOLEAN) {
268 st->print("bool");
269 } else {
270 st->print("%s", type2name_tab[bt]);
271 }
272 st->print("}");
273 }
274
275 #ifndef PRODUCT
276
277 static void print_boolean_array(typeArrayOop ta, int print_len, outputStream* st) {
278 for (int index = 0; index < print_len; index++) {
279 st->print_cr(" - %3d: %s", index, (ta->bool_at(index) == 0) ? "false" : "true");
280 }
281 }
282
283
284 static void print_char_array(typeArrayOop ta, int print_len, outputStream* st) {
285 for (int index = 0; index < print_len; index++) {
286 jchar c = ta->char_at(index);
287 st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' ');
288 }
289 }
290
|