annotate src/share/vm/oops/typeArrayKlass.cpp @ 45:48a3fa21394b

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