src/share/vm/oops/typeArrayKlass.cpp

Tue, 16 Oct 2018 10:40:23 -0400

author
phh
date
Tue, 16 Oct 2018 10:40:23 -0400
changeset 9507
7e72702243a4
parent 6911
ce8f6bb717c9
child 9572
624a0741915c
permissions
-rw-r--r--

8064811: Use THEAD instead of CHECK_NULL in return statements
Summary: Backport from JDK9
Reviewed-by: dholmes, coffeys

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

mercurial