src/share/vm/oops/typeArrayKlass.cpp

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 4151
6e5a59a8e4a7
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

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

mercurial