src/share/vm/oops/typeArrayKlass.cpp

Fri, 16 Nov 2012 09:19:12 -0500

author
coleenp
date
Fri, 16 Nov 2012 09:19:12 -0500
changeset 4280
80e866b1d053
parent 4151
6e5a59a8e4a7
child 4542
db9981fd3124
permissions
-rw-r--r--

Merge

duke@435 1 /*
sspitsyn@3638 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
coleenp@4037 26 #include "classfile/symbolTable.hpp"
stefank@2314 27 #include "classfile/systemDictionary.hpp"
stefank@2314 28 #include "classfile/vmSymbols.hpp"
stefank@2314 29 #include "gc_interface/collectedHeap.hpp"
stefank@2314 30 #include "gc_interface/collectedHeap.inline.hpp"
coleenp@4037 31 #include "memory/metadataFactory.hpp"
stefank@2314 32 #include "memory/resourceArea.hpp"
stefank@2314 33 #include "memory/universe.hpp"
stefank@2314 34 #include "memory/universe.inline.hpp"
stefank@2314 35 #include "oops/instanceKlass.hpp"
coleenp@4037 36 #include "oops/klass.inline.hpp"
coleenp@4037 37 #include "oops/objArrayKlass.hpp"
stefank@2314 38 #include "oops/oop.inline.hpp"
stefank@2314 39 #include "oops/typeArrayKlass.hpp"
stefank@2314 40 #include "oops/typeArrayOop.hpp"
stefank@2314 41 #include "runtime/handles.inline.hpp"
duke@435 42
coleenp@4142 43 bool TypeArrayKlass::compute_is_subtype_of(Klass* k) {
coleenp@4037 44 if (!k->oop_is_typeArray()) {
coleenp@4142 45 return ArrayKlass::compute_is_subtype_of(k);
duke@435 46 }
duke@435 47
coleenp@4142 48 TypeArrayKlass* tak = TypeArrayKlass::cast(k);
duke@435 49 if (dimension() != tak->dimension()) return false;
duke@435 50
duke@435 51 return element_type() == tak->element_type();
duke@435 52 }
duke@435 53
coleenp@4142 54 TypeArrayKlass* TypeArrayKlass::create_klass(BasicType type,
jcoomes@916 55 const char* name_str, TRAPS) {
coleenp@2497 56 Symbol* sym = NULL;
coleenp@2497 57 if (name_str != NULL) {
coleenp@3682 58 sym = SymbolTable::new_permanent_symbol(name_str, CHECK_NULL);
duke@435 59 }
duke@435 60
coleenp@4037 61 ClassLoaderData* null_loader_data = ClassLoaderData::the_null_class_loader_data();
coleenp@4037 62
coleenp@4142 63 TypeArrayKlass* ak = TypeArrayKlass::allocate(null_loader_data, type, sym, CHECK_NULL);
coleenp@4037 64
coleenp@4037 65 // Add all classes to our internal class loader list here,
coleenp@4037 66 // including classes in the bootstrap (NULL) class loader.
coleenp@4037 67 // GC walks these as strong roots.
coleenp@4037 68 null_loader_data->add_class(ak);
duke@435 69
duke@435 70 // Call complete_create_array_klass after all instance variables have been initialized.
coleenp@4037 71 complete_create_array_klass(ak, ak->super(), CHECK_NULL);
duke@435 72
coleenp@4037 73 return ak;
coleenp@4037 74 }
coleenp@4037 75
coleenp@4142 76 TypeArrayKlass* TypeArrayKlass::allocate(ClassLoaderData* loader_data, BasicType type, Symbol* name, TRAPS) {
coleenp@4142 77 assert(TypeArrayKlass::header_size() <= InstanceKlass::header_size(),
coleenp@4037 78 "array klasses must be same size as InstanceKlass");
coleenp@4037 79
coleenp@4142 80 int size = ArrayKlass::static_size(TypeArrayKlass::header_size());
coleenp@4037 81
coleenp@4142 82 return new (loader_data, size, THREAD) TypeArrayKlass(type, name);
coleenp@4037 83 }
coleenp@4037 84
coleenp@4142 85 TypeArrayKlass::TypeArrayKlass(BasicType type, Symbol* name) : ArrayKlass(name) {
coleenp@4037 86 set_layout_helper(array_layout_helper(type));
coleenp@4037 87 assert(oop_is_array(), "sanity");
coleenp@4037 88 assert(oop_is_typeArray(), "sanity");
coleenp@4037 89
coleenp@4037 90 set_max_length(arrayOopDesc::max_array_length(type));
coleenp@4142 91 assert(size() >= TypeArrayKlass::header_size(), "bad size");
coleenp@4037 92
coleenp@4037 93 set_class_loader_data(ClassLoaderData::the_null_class_loader_data());
duke@435 94 }
duke@435 95
coleenp@4142 96 typeArrayOop TypeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
duke@435 97 assert(log2_element_size() >= 0, "bad scale");
duke@435 98 if (length >= 0) {
duke@435 99 if (length <= max_length()) {
duke@435 100 size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
coleenp@4037 101 KlassHandle h_k(THREAD, this);
duke@435 102 typeArrayOop t;
duke@435 103 CollectedHeap* ch = Universe::heap();
kvn@3157 104 if (do_zero) {
kvn@3157 105 t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL);
kvn@3157 106 } else {
kvn@3157 107 t = (typeArrayOop)CollectedHeap::array_allocate_nozero(h_k, (int)size, length, CHECK_NULL);
kvn@3157 108 }
duke@435 109 return t;
duke@435 110 } else {
martin@1311 111 report_java_out_of_memory("Requested array size exceeds VM limit");
sspitsyn@3638 112 JvmtiExport::post_array_size_exhausted();
duke@435 113 THROW_OOP_0(Universe::out_of_memory_error_array_size());
duke@435 114 }
duke@435 115 } else {
duke@435 116 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@435 117 }
duke@435 118 }
duke@435 119
coleenp@4142 120 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
duke@435 121 // For typeArrays this is only called for the last dimension
duke@435 122 assert(rank == 1, "just checking");
duke@435 123 int length = *last_size;
duke@435 124 return allocate(length, THREAD);
duke@435 125 }
duke@435 126
duke@435 127
coleenp@4142 128 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
duke@435 129 assert(s->is_typeArray(), "must be type array");
duke@435 130
duke@435 131 // Check destination
coleenp@4142 132 if (!d->is_typeArray() || element_type() != TypeArrayKlass::cast(d->klass())->element_type()) {
duke@435 133 THROW(vmSymbols::java_lang_ArrayStoreException());
duke@435 134 }
duke@435 135
duke@435 136 // Check is all offsets and lengths are non negative
duke@435 137 if (src_pos < 0 || dst_pos < 0 || length < 0) {
duke@435 138 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
duke@435 139 }
duke@435 140 // Check if the ranges are valid
duke@435 141 if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
duke@435 142 || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
duke@435 143 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
duke@435 144 }
kvn@1769 145 // Check zero copy
kvn@1769 146 if (length == 0)
kvn@1769 147 return;
duke@435 148
duke@435 149 // This is an attempt to make the copy_array fast.
duke@435 150 int l2es = log2_element_size();
duke@435 151 int ihs = array_header_in_bytes() / wordSize;
kvn@1769 152 char* src = (char*) ((oop*)s + ihs) + ((size_t)src_pos << l2es);
kvn@1769 153 char* dst = (char*) ((oop*)d + ihs) + ((size_t)dst_pos << l2es);
kvn@1769 154 Copy::conjoint_memory_atomic(src, dst, (size_t)length << l2es);
duke@435 155 }
duke@435 156
duke@435 157
duke@435 158 // create a klass of array holding typeArrays
coleenp@4142 159 Klass* TypeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
coleenp@4037 160 int dim = dimension();
coleenp@4037 161 assert(dim <= n, "check order of chain");
coleenp@4037 162 if (dim == n)
coleenp@4037 163 return this;
duke@435 164
coleenp@4037 165 if (higher_dimension() == NULL) {
duke@435 166 if (or_null) return NULL;
duke@435 167
duke@435 168 ResourceMark rm;
duke@435 169 JavaThread *jt = (JavaThread *)THREAD;
duke@435 170 {
duke@435 171 MutexLocker mc(Compile_lock, THREAD); // for vtables
duke@435 172 // Atomic create higher dimension and link into list
duke@435 173 MutexLocker mu(MultiArray_lock, THREAD);
duke@435 174
coleenp@4037 175 if (higher_dimension() == NULL) {
coleenp@4142 176 Klass* oak = ObjArrayKlass::allocate_objArray_klass(
coleenp@4037 177 class_loader_data(), dim + 1, this, CHECK_NULL);
coleenp@4142 178 ObjArrayKlass* h_ak = ObjArrayKlass::cast(oak);
coleenp@4037 179 h_ak->set_lower_dimension(this);
kvn@2439 180 OrderAccess::storestore();
coleenp@4037 181 set_higher_dimension(h_ak);
coleenp@4142 182 assert(h_ak->oop_is_objArray(), "incorrect initialization of ObjArrayKlass");
duke@435 183 }
duke@435 184 }
duke@435 185 } else {
duke@435 186 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
duke@435 187 }
coleenp@4142 188 ObjArrayKlass* h_ak = ObjArrayKlass::cast(higher_dimension());
duke@435 189 if (or_null) {
duke@435 190 return h_ak->array_klass_or_null(n);
duke@435 191 }
duke@435 192 return h_ak->array_klass(n, CHECK_NULL);
duke@435 193 }
duke@435 194
coleenp@4142 195 Klass* TypeArrayKlass::array_klass_impl(bool or_null, TRAPS) {
duke@435 196 return array_klass_impl(or_null, dimension() + 1, THREAD);
duke@435 197 }
duke@435 198
coleenp@4142 199 int TypeArrayKlass::oop_size(oop obj) const {
duke@435 200 assert(obj->is_typeArray(),"must be a type array");
duke@435 201 typeArrayOop t = typeArrayOop(obj);
duke@435 202 return t->object_size();
duke@435 203 }
duke@435 204
coleenp@4142 205 void TypeArrayKlass::oop_follow_contents(oop obj) {
duke@435 206 assert(obj->is_typeArray(),"must be a type array");
duke@435 207 // Performance tweak: We skip iterating over the klass pointer since we
coleenp@4142 208 // know that Universe::TypeArrayKlass never moves.
duke@435 209 }
duke@435 210
duke@435 211 #ifndef SERIALGC
coleenp@4142 212 void TypeArrayKlass::oop_follow_contents(ParCompactionManager* cm, oop obj) {
duke@435 213 assert(obj->is_typeArray(),"must be a type array");
duke@435 214 // Performance tweak: We skip iterating over the klass pointer since we
coleenp@4142 215 // know that Universe::TypeArrayKlass never moves.
duke@435 216 }
duke@435 217 #endif // SERIALGC
duke@435 218
coleenp@4142 219 int TypeArrayKlass::oop_adjust_pointers(oop obj) {
duke@435 220 assert(obj->is_typeArray(),"must be a type array");
duke@435 221 typeArrayOop t = typeArrayOop(obj);
duke@435 222 // Performance tweak: We skip iterating over the klass pointer since we
coleenp@4142 223 // know that Universe::TypeArrayKlass never moves.
duke@435 224 return t->object_size();
duke@435 225 }
duke@435 226
coleenp@4142 227 int TypeArrayKlass::oop_oop_iterate(oop obj, ExtendedOopClosure* blk) {
duke@435 228 assert(obj->is_typeArray(),"must be a type array");
duke@435 229 typeArrayOop t = typeArrayOop(obj);
duke@435 230 // Performance tweak: We skip iterating over the klass pointer since we
coleenp@4142 231 // know that Universe::TypeArrayKlass never moves.
duke@435 232 return t->object_size();
duke@435 233 }
duke@435 234
coleenp@4142 235 int TypeArrayKlass::oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
duke@435 236 assert(obj->is_typeArray(),"must be a type array");
duke@435 237 typeArrayOop t = typeArrayOop(obj);
duke@435 238 // Performance tweak: We skip iterating over the klass pointer since we
coleenp@4142 239 // know that Universe::TypeArrayKlass never moves.
duke@435 240 return t->object_size();
duke@435 241 }
duke@435 242
duke@435 243 #ifndef SERIALGC
coleenp@4142 244 void TypeArrayKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
coleenp@4037 245 ShouldNotReachHere();
duke@435 246 assert(obj->is_typeArray(),"must be a type array");
duke@435 247 }
duke@435 248
duke@435 249 int
coleenp@4142 250 TypeArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@435 251 assert(obj->is_typeArray(),"must be a type array");
duke@435 252 return typeArrayOop(obj)->object_size();
duke@435 253 }
duke@435 254 #endif // SERIALGC
duke@435 255
coleenp@4142 256 void TypeArrayKlass::initialize(TRAPS) {
duke@435 257 // Nothing to do. Having this function is handy since objArrayKlasses can be
coleenp@4142 258 // initialized by calling initialize on their bottom_klass, see ObjArrayKlass::initialize
duke@435 259 }
duke@435 260
coleenp@4142 261 const char* TypeArrayKlass::external_name(BasicType type) {
duke@435 262 switch (type) {
duke@435 263 case T_BOOLEAN: return "[Z";
duke@435 264 case T_CHAR: return "[C";
duke@435 265 case T_FLOAT: return "[F";
duke@435 266 case T_DOUBLE: return "[D";
duke@435 267 case T_BYTE: return "[B";
duke@435 268 case T_SHORT: return "[S";
duke@435 269 case T_INT: return "[I";
duke@435 270 case T_LONG: return "[J";
duke@435 271 default: ShouldNotReachHere();
duke@435 272 }
duke@435 273 return NULL;
duke@435 274 }
duke@435 275
coleenp@4037 276
coleenp@4037 277 // Printing
coleenp@4037 278
coleenp@4142 279 void TypeArrayKlass::print_on(outputStream* st) const {
duke@435 280 #ifndef PRODUCT
coleenp@4037 281 assert(is_klass(), "must be klass");
coleenp@4037 282 print_value_on(st);
coleenp@4037 283 Klass::print_on(st);
coleenp@4037 284 #endif //PRODUCT
coleenp@4037 285 }
coleenp@4037 286
coleenp@4142 287 void TypeArrayKlass::print_value_on(outputStream* st) const {
coleenp@4037 288 assert(is_klass(), "must be klass");
coleenp@4037 289 st->print("{type array ");
coleenp@4037 290 switch (element_type()) {
coleenp@4037 291 case T_BOOLEAN: st->print("bool"); break;
coleenp@4037 292 case T_CHAR: st->print("char"); break;
coleenp@4037 293 case T_FLOAT: st->print("float"); break;
coleenp@4037 294 case T_DOUBLE: st->print("double"); break;
coleenp@4037 295 case T_BYTE: st->print("byte"); break;
coleenp@4037 296 case T_SHORT: st->print("short"); break;
coleenp@4037 297 case T_INT: st->print("int"); break;
coleenp@4037 298 case T_LONG: st->print("long"); break;
coleenp@4037 299 default: ShouldNotReachHere();
coleenp@4037 300 }
coleenp@4037 301 st->print("}");
coleenp@4037 302 }
coleenp@4037 303
coleenp@4037 304 #ifndef PRODUCT
duke@435 305
duke@435 306 static void print_boolean_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 307 for (int index = 0; index < print_len; index++) {
duke@435 308 st->print_cr(" - %3d: %s", index, (ta->bool_at(index) == 0) ? "false" : "true");
duke@435 309 }
duke@435 310 }
duke@435 311
duke@435 312
duke@435 313 static void print_char_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 314 for (int index = 0; index < print_len; index++) {
duke@435 315 jchar c = ta->char_at(index);
duke@435 316 st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' ');
duke@435 317 }
duke@435 318 }
duke@435 319
duke@435 320
duke@435 321 static void print_float_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 322 for (int index = 0; index < print_len; index++) {
duke@435 323 st->print_cr(" - %3d: %g", index, ta->float_at(index));
duke@435 324 }
duke@435 325 }
duke@435 326
duke@435 327
duke@435 328 static void print_double_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 329 for (int index = 0; index < print_len; index++) {
duke@435 330 st->print_cr(" - %3d: %g", index, ta->double_at(index));
duke@435 331 }
duke@435 332 }
duke@435 333
duke@435 334
duke@435 335 static void print_byte_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 336 for (int index = 0; index < print_len; index++) {
duke@435 337 jbyte c = ta->byte_at(index);
duke@435 338 st->print_cr(" - %3d: %x %c", index, c, isprint(c) ? c : ' ');
duke@435 339 }
duke@435 340 }
duke@435 341
duke@435 342
duke@435 343 static void print_short_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 344 for (int index = 0; index < print_len; index++) {
duke@435 345 int v = ta->ushort_at(index);
duke@435 346 st->print_cr(" - %3d: 0x%x\t %d", index, v, v);
duke@435 347 }
duke@435 348 }
duke@435 349
duke@435 350
duke@435 351 static void print_int_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 352 for (int index = 0; index < print_len; index++) {
duke@435 353 jint v = ta->int_at(index);
duke@435 354 st->print_cr(" - %3d: 0x%x %d", index, v, v);
duke@435 355 }
duke@435 356 }
duke@435 357
duke@435 358
duke@435 359 static void print_long_array(typeArrayOop ta, int print_len, outputStream* st) {
duke@435 360 for (int index = 0; index < print_len; index++) {
duke@435 361 jlong v = ta->long_at(index);
duke@435 362 st->print_cr(" - %3d: 0x%x 0x%x", index, high(v), low(v));
duke@435 363 }
duke@435 364 }
duke@435 365
duke@435 366
coleenp@4142 367 void TypeArrayKlass::oop_print_on(oop obj, outputStream* st) {
coleenp@4142 368 ArrayKlass::oop_print_on(obj, st);
duke@435 369 typeArrayOop ta = typeArrayOop(obj);
duke@435 370 int print_len = MIN2((intx) ta->length(), MaxElementPrintSize);
duke@435 371 switch (element_type()) {
duke@435 372 case T_BOOLEAN: print_boolean_array(ta, print_len, st); break;
duke@435 373 case T_CHAR: print_char_array(ta, print_len, st); break;
duke@435 374 case T_FLOAT: print_float_array(ta, print_len, st); break;
duke@435 375 case T_DOUBLE: print_double_array(ta, print_len, st); break;
duke@435 376 case T_BYTE: print_byte_array(ta, print_len, st); break;
duke@435 377 case T_SHORT: print_short_array(ta, print_len, st); break;
duke@435 378 case T_INT: print_int_array(ta, print_len, st); break;
duke@435 379 case T_LONG: print_long_array(ta, print_len, st); break;
duke@435 380 default: ShouldNotReachHere();
duke@435 381 }
duke@435 382 int remaining = ta->length() - print_len;
duke@435 383 if (remaining > 0) {
stefank@4126 384 st->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining);
duke@435 385 }
duke@435 386 }
duke@435 387
duke@435 388 #endif // PRODUCT
duke@435 389
coleenp@4142 390 const char* TypeArrayKlass::internal_name() const {
duke@435 391 return Klass::external_name();
duke@435 392 }

mercurial