Wed, 06 Jan 2010 22:21:39 -0800
Merge
duke@435 | 1 | /* |
xdono@1014 | 2 | * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_typeArrayKlass.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | bool typeArrayKlass::compute_is_subtype_of(klassOop k) { |
duke@435 | 29 | if (!k->klass_part()->oop_is_typeArray()) { |
duke@435 | 30 | return arrayKlass::compute_is_subtype_of(k); |
duke@435 | 31 | } |
duke@435 | 32 | |
duke@435 | 33 | typeArrayKlass* tak = typeArrayKlass::cast(k); |
duke@435 | 34 | if (dimension() != tak->dimension()) return false; |
duke@435 | 35 | |
duke@435 | 36 | return element_type() == tak->element_type(); |
duke@435 | 37 | } |
duke@435 | 38 | |
jcoomes@916 | 39 | klassOop typeArrayKlass::create_klass(BasicType type, int scale, |
jcoomes@916 | 40 | const char* name_str, TRAPS) { |
duke@435 | 41 | typeArrayKlass o; |
duke@435 | 42 | |
duke@435 | 43 | symbolHandle sym(symbolOop(NULL)); |
duke@435 | 44 | // bootstrapping: don't create sym if symbolKlass not created yet |
jcoomes@916 | 45 | if (Universe::symbolKlassObj() != NULL && name_str != NULL) { |
jcoomes@916 | 46 | sym = oopFactory::new_symbol_handle(name_str, CHECK_NULL); |
duke@435 | 47 | } |
duke@435 | 48 | KlassHandle klassklass (THREAD, Universe::typeArrayKlassKlassObj()); |
duke@435 | 49 | |
duke@435 | 50 | arrayKlassHandle k = base_create_array_klass(o.vtbl_value(), header_size(), klassklass, CHECK_NULL); |
duke@435 | 51 | typeArrayKlass* ak = typeArrayKlass::cast(k()); |
duke@435 | 52 | ak->set_name(sym()); |
duke@435 | 53 | ak->set_layout_helper(array_layout_helper(type)); |
duke@435 | 54 | assert(scale == (1 << ak->log2_element_size()), "scale must check out"); |
duke@435 | 55 | assert(ak->oop_is_javaArray(), "sanity"); |
duke@435 | 56 | assert(ak->oop_is_typeArray(), "sanity"); |
duke@435 | 57 | ak->set_max_length(arrayOopDesc::max_array_length(type)); |
duke@435 | 58 | assert(k()->size() > header_size(), "bad size"); |
duke@435 | 59 | |
duke@435 | 60 | // Call complete_create_array_klass after all instance variables have been initialized. |
duke@435 | 61 | KlassHandle super (THREAD, k->super()); |
duke@435 | 62 | complete_create_array_klass(k, super, CHECK_NULL); |
duke@435 | 63 | |
duke@435 | 64 | return k(); |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | typeArrayOop typeArrayKlass::allocate(int length, TRAPS) { |
duke@435 | 68 | assert(log2_element_size() >= 0, "bad scale"); |
duke@435 | 69 | if (length >= 0) { |
duke@435 | 70 | if (length <= max_length()) { |
duke@435 | 71 | size_t size = typeArrayOopDesc::object_size(layout_helper(), length); |
duke@435 | 72 | KlassHandle h_k(THREAD, as_klassOop()); |
duke@435 | 73 | typeArrayOop t; |
duke@435 | 74 | CollectedHeap* ch = Universe::heap(); |
duke@435 | 75 | if (size < ch->large_typearray_limit()) { |
duke@435 | 76 | t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL); |
duke@435 | 77 | } else { |
duke@435 | 78 | t = (typeArrayOop)CollectedHeap::large_typearray_allocate(h_k, (int)size, length, CHECK_NULL); |
duke@435 | 79 | } |
duke@435 | 80 | assert(t->is_parsable(), "Don't publish unless parsable"); |
duke@435 | 81 | return t; |
duke@435 | 82 | } else { |
martin@1311 | 83 | report_java_out_of_memory("Requested array size exceeds VM limit"); |
duke@435 | 84 | THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
duke@435 | 85 | } |
duke@435 | 86 | } else { |
duke@435 | 87 | THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
duke@435 | 88 | } |
duke@435 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | typeArrayOop typeArrayKlass::allocate_permanent(int length, TRAPS) { |
duke@435 | 92 | if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
duke@435 | 93 | int size = typeArrayOopDesc::object_size(layout_helper(), length); |
duke@435 | 94 | KlassHandle h_k(THREAD, as_klassOop()); |
duke@435 | 95 | typeArrayOop t = (typeArrayOop) |
duke@435 | 96 | CollectedHeap::permanent_array_allocate(h_k, size, length, CHECK_NULL); |
duke@435 | 97 | assert(t->is_parsable(), "Can't publish until parsable"); |
duke@435 | 98 | return t; |
duke@435 | 99 | } |
duke@435 | 100 | |
duke@435 | 101 | oop typeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) { |
duke@435 | 102 | // For typeArrays this is only called for the last dimension |
duke@435 | 103 | assert(rank == 1, "just checking"); |
duke@435 | 104 | int length = *last_size; |
duke@435 | 105 | return allocate(length, THREAD); |
duke@435 | 106 | } |
duke@435 | 107 | |
duke@435 | 108 | |
duke@435 | 109 | void typeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) { |
duke@435 | 110 | assert(s->is_typeArray(), "must be type array"); |
duke@435 | 111 | |
duke@435 | 112 | // Check destination |
duke@435 | 113 | if (!d->is_typeArray() || element_type() != typeArrayKlass::cast(d->klass())->element_type()) { |
duke@435 | 114 | THROW(vmSymbols::java_lang_ArrayStoreException()); |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | // Check is all offsets and lengths are non negative |
duke@435 | 118 | if (src_pos < 0 || dst_pos < 0 || length < 0) { |
duke@435 | 119 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); |
duke@435 | 120 | } |
duke@435 | 121 | // Check if the ranges are valid |
duke@435 | 122 | if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) |
duke@435 | 123 | || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) { |
duke@435 | 124 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); |
duke@435 | 125 | } |
duke@435 | 126 | |
duke@435 | 127 | // This is an attempt to make the copy_array fast. |
duke@435 | 128 | // NB: memmove takes care of overlapping memory segments. |
duke@435 | 129 | // Potential problem: memmove is not guaranteed to be word atomic |
duke@435 | 130 | // Revisit in Merlin |
duke@435 | 131 | int l2es = log2_element_size(); |
duke@435 | 132 | int ihs = array_header_in_bytes() / wordSize; |
duke@435 | 133 | char* src = (char*) ((oop*)s + ihs) + (src_pos << l2es); |
duke@435 | 134 | char* dst = (char*) ((oop*)d + ihs) + (dst_pos << l2es); |
duke@435 | 135 | memmove(dst, src, length << l2es); |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | |
duke@435 | 139 | // create a klass of array holding typeArrays |
duke@435 | 140 | klassOop typeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
duke@435 | 141 | typeArrayKlassHandle h_this(THREAD, as_klassOop()); |
duke@435 | 142 | return array_klass_impl(h_this, or_null, n, THREAD); |
duke@435 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | klassOop typeArrayKlass::array_klass_impl(typeArrayKlassHandle h_this, bool or_null, int n, TRAPS) { |
duke@435 | 146 | int dimension = h_this->dimension(); |
duke@435 | 147 | assert(dimension <= n, "check order of chain"); |
duke@435 | 148 | if (dimension == n) |
duke@435 | 149 | return h_this(); |
duke@435 | 150 | |
duke@435 | 151 | objArrayKlassHandle h_ak(THREAD, h_this->higher_dimension()); |
duke@435 | 152 | if (h_ak.is_null()) { |
duke@435 | 153 | if (or_null) return NULL; |
duke@435 | 154 | |
duke@435 | 155 | ResourceMark rm; |
duke@435 | 156 | JavaThread *jt = (JavaThread *)THREAD; |
duke@435 | 157 | { |
duke@435 | 158 | MutexLocker mc(Compile_lock, THREAD); // for vtables |
duke@435 | 159 | // Atomic create higher dimension and link into list |
duke@435 | 160 | MutexLocker mu(MultiArray_lock, THREAD); |
duke@435 | 161 | |
duke@435 | 162 | h_ak = objArrayKlassHandle(THREAD, h_this->higher_dimension()); |
duke@435 | 163 | if (h_ak.is_null()) { |
duke@435 | 164 | klassOop oak = objArrayKlassKlass::cast( |
duke@435 | 165 | Universe::objArrayKlassKlassObj())->allocate_objArray_klass( |
duke@435 | 166 | dimension + 1, h_this, CHECK_NULL); |
duke@435 | 167 | h_ak = objArrayKlassHandle(THREAD, oak); |
duke@435 | 168 | h_ak->set_lower_dimension(h_this()); |
duke@435 | 169 | h_this->set_higher_dimension(h_ak()); |
duke@435 | 170 | assert(h_ak->oop_is_objArray(), "incorrect initialization of objArrayKlass"); |
duke@435 | 171 | } |
duke@435 | 172 | } |
duke@435 | 173 | } else { |
duke@435 | 174 | CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); |
duke@435 | 175 | } |
duke@435 | 176 | if (or_null) { |
duke@435 | 177 | return h_ak->array_klass_or_null(n); |
duke@435 | 178 | } |
duke@435 | 179 | return h_ak->array_klass(n, CHECK_NULL); |
duke@435 | 180 | } |
duke@435 | 181 | |
duke@435 | 182 | klassOop typeArrayKlass::array_klass_impl(bool or_null, TRAPS) { |
duke@435 | 183 | return array_klass_impl(or_null, dimension() + 1, THREAD); |
duke@435 | 184 | } |
duke@435 | 185 | |
duke@435 | 186 | int typeArrayKlass::oop_size(oop obj) const { |
duke@435 | 187 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 188 | typeArrayOop t = typeArrayOop(obj); |
duke@435 | 189 | return t->object_size(); |
duke@435 | 190 | } |
duke@435 | 191 | |
duke@435 | 192 | void typeArrayKlass::oop_follow_contents(oop obj) { |
duke@435 | 193 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 194 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 195 | // know that Universe::typeArrayKlass never moves. |
duke@435 | 196 | } |
duke@435 | 197 | |
duke@435 | 198 | #ifndef SERIALGC |
duke@435 | 199 | void typeArrayKlass::oop_follow_contents(ParCompactionManager* cm, oop obj) { |
duke@435 | 200 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 201 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 202 | // know that Universe::typeArrayKlass never moves. |
duke@435 | 203 | } |
duke@435 | 204 | #endif // SERIALGC |
duke@435 | 205 | |
duke@435 | 206 | int typeArrayKlass::oop_adjust_pointers(oop obj) { |
duke@435 | 207 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 208 | typeArrayOop t = typeArrayOop(obj); |
duke@435 | 209 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 210 | // know that Universe::typeArrayKlass never moves. |
duke@435 | 211 | return t->object_size(); |
duke@435 | 212 | } |
duke@435 | 213 | |
duke@435 | 214 | int typeArrayKlass::oop_oop_iterate(oop obj, OopClosure* blk) { |
duke@435 | 215 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 216 | typeArrayOop t = typeArrayOop(obj); |
duke@435 | 217 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 218 | // know that Universe::typeArrayKlass never moves. |
duke@435 | 219 | return t->object_size(); |
duke@435 | 220 | } |
duke@435 | 221 | |
duke@435 | 222 | int typeArrayKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { |
duke@435 | 223 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 224 | typeArrayOop t = typeArrayOop(obj); |
duke@435 | 225 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 226 | // know that Universe::typeArrayKlass never moves. |
duke@435 | 227 | return t->object_size(); |
duke@435 | 228 | } |
duke@435 | 229 | |
duke@435 | 230 | #ifndef SERIALGC |
duke@435 | 231 | void typeArrayKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) { |
duke@435 | 232 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 233 | } |
duke@435 | 234 | |
duke@435 | 235 | void typeArrayKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { |
duke@435 | 236 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 237 | } |
duke@435 | 238 | |
duke@435 | 239 | int |
duke@435 | 240 | typeArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { |
duke@435 | 241 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 242 | return typeArrayOop(obj)->object_size(); |
duke@435 | 243 | } |
duke@435 | 244 | |
duke@435 | 245 | int |
duke@435 | 246 | typeArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, |
duke@435 | 247 | HeapWord* beg_addr, HeapWord* end_addr) { |
duke@435 | 248 | assert(obj->is_typeArray(),"must be a type array"); |
duke@435 | 249 | return typeArrayOop(obj)->object_size(); |
duke@435 | 250 | } |
duke@435 | 251 | #endif // SERIALGC |
duke@435 | 252 | |
duke@435 | 253 | void typeArrayKlass::initialize(TRAPS) { |
duke@435 | 254 | // Nothing to do. Having this function is handy since objArrayKlasses can be |
duke@435 | 255 | // initialized by calling initialize on their bottom_klass, see objArrayKlass::initialize |
duke@435 | 256 | } |
duke@435 | 257 | |
duke@435 | 258 | const char* typeArrayKlass::external_name(BasicType type) { |
duke@435 | 259 | switch (type) { |
duke@435 | 260 | case T_BOOLEAN: return "[Z"; |
duke@435 | 261 | case T_CHAR: return "[C"; |
duke@435 | 262 | case T_FLOAT: return "[F"; |
duke@435 | 263 | case T_DOUBLE: return "[D"; |
duke@435 | 264 | case T_BYTE: return "[B"; |
duke@435 | 265 | case T_SHORT: return "[S"; |
duke@435 | 266 | case T_INT: return "[I"; |
duke@435 | 267 | case T_LONG: return "[J"; |
duke@435 | 268 | default: ShouldNotReachHere(); |
duke@435 | 269 | } |
duke@435 | 270 | return NULL; |
duke@435 | 271 | } |
duke@435 | 272 | |
duke@435 | 273 | #ifndef PRODUCT |
duke@435 | 274 | // Printing |
duke@435 | 275 | |
duke@435 | 276 | static void print_boolean_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 277 | for (int index = 0; index < print_len; index++) { |
duke@435 | 278 | st->print_cr(" - %3d: %s", index, (ta->bool_at(index) == 0) ? "false" : "true"); |
duke@435 | 279 | } |
duke@435 | 280 | } |
duke@435 | 281 | |
duke@435 | 282 | |
duke@435 | 283 | static void print_char_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 284 | for (int index = 0; index < print_len; index++) { |
duke@435 | 285 | jchar c = ta->char_at(index); |
duke@435 | 286 | st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' '); |
duke@435 | 287 | } |
duke@435 | 288 | } |
duke@435 | 289 | |
duke@435 | 290 | |
duke@435 | 291 | static void print_float_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 292 | for (int index = 0; index < print_len; index++) { |
duke@435 | 293 | st->print_cr(" - %3d: %g", index, ta->float_at(index)); |
duke@435 | 294 | } |
duke@435 | 295 | } |
duke@435 | 296 | |
duke@435 | 297 | |
duke@435 | 298 | static void print_double_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 299 | for (int index = 0; index < print_len; index++) { |
duke@435 | 300 | st->print_cr(" - %3d: %g", index, ta->double_at(index)); |
duke@435 | 301 | } |
duke@435 | 302 | } |
duke@435 | 303 | |
duke@435 | 304 | |
duke@435 | 305 | static void print_byte_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 306 | for (int index = 0; index < print_len; index++) { |
duke@435 | 307 | jbyte c = ta->byte_at(index); |
duke@435 | 308 | st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' '); |
duke@435 | 309 | } |
duke@435 | 310 | } |
duke@435 | 311 | |
duke@435 | 312 | |
duke@435 | 313 | static void print_short_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 314 | for (int index = 0; index < print_len; index++) { |
duke@435 | 315 | int v = ta->ushort_at(index); |
duke@435 | 316 | st->print_cr(" - %3d: 0x%x\t %d", index, v, v); |
duke@435 | 317 | } |
duke@435 | 318 | } |
duke@435 | 319 | |
duke@435 | 320 | |
duke@435 | 321 | static void print_int_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 322 | for (int index = 0; index < print_len; index++) { |
duke@435 | 323 | jint v = ta->int_at(index); |
duke@435 | 324 | st->print_cr(" - %3d: 0x%x %d", index, v, v); |
duke@435 | 325 | } |
duke@435 | 326 | } |
duke@435 | 327 | |
duke@435 | 328 | |
duke@435 | 329 | static void print_long_array(typeArrayOop ta, int print_len, outputStream* st) { |
duke@435 | 330 | for (int index = 0; index < print_len; index++) { |
duke@435 | 331 | jlong v = ta->long_at(index); |
duke@435 | 332 | st->print_cr(" - %3d: 0x%x 0x%x", index, high(v), low(v)); |
duke@435 | 333 | } |
duke@435 | 334 | } |
duke@435 | 335 | |
duke@435 | 336 | |
duke@435 | 337 | void typeArrayKlass::oop_print_on(oop obj, outputStream* st) { |
duke@435 | 338 | arrayKlass::oop_print_on(obj, st); |
duke@435 | 339 | typeArrayOop ta = typeArrayOop(obj); |
duke@435 | 340 | int print_len = MIN2((intx) ta->length(), MaxElementPrintSize); |
duke@435 | 341 | switch (element_type()) { |
duke@435 | 342 | case T_BOOLEAN: print_boolean_array(ta, print_len, st); break; |
duke@435 | 343 | case T_CHAR: print_char_array(ta, print_len, st); break; |
duke@435 | 344 | case T_FLOAT: print_float_array(ta, print_len, st); break; |
duke@435 | 345 | case T_DOUBLE: print_double_array(ta, print_len, st); break; |
duke@435 | 346 | case T_BYTE: print_byte_array(ta, print_len, st); break; |
duke@435 | 347 | case T_SHORT: print_short_array(ta, print_len, st); break; |
duke@435 | 348 | case T_INT: print_int_array(ta, print_len, st); break; |
duke@435 | 349 | case T_LONG: print_long_array(ta, print_len, st); break; |
duke@435 | 350 | default: ShouldNotReachHere(); |
duke@435 | 351 | } |
duke@435 | 352 | int remaining = ta->length() - print_len; |
duke@435 | 353 | if (remaining > 0) { |
duke@435 | 354 | tty->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining); |
duke@435 | 355 | } |
duke@435 | 356 | } |
duke@435 | 357 | |
duke@435 | 358 | #endif // PRODUCT |
duke@435 | 359 | |
duke@435 | 360 | const char* typeArrayKlass::internal_name() const { |
duke@435 | 361 | return Klass::external_name(); |
duke@435 | 362 | } |