src/share/vm/opto/parse3.cpp

Fri, 11 Jul 2014 19:51:36 -0400

author
drchase
date
Fri, 11 Jul 2014 19:51:36 -0400
changeset 7161
fc2c88ea11a9
parent 6507
752ba2e5f6d0
child 6876
710a3c8b516e
child 7859
c1c199dde5c9
permissions
-rw-r--r--

8036588: VerifyFieldClosure fails instanceKlass:3133
Summary: Changed deopt live-pointer test to use returns-object instead of live-and-returns-object
Reviewed-by: iveresov, kvn, jrose

duke@435 1 /*
drchase@4540 2 * Copyright (c) 1998, 2013, 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"
stefank@2314 26 #include "compiler/compileLog.hpp"
stefank@2314 27 #include "interpreter/linkResolver.hpp"
stefank@2314 28 #include "memory/universe.inline.hpp"
stefank@2314 29 #include "oops/objArrayKlass.hpp"
stefank@2314 30 #include "opto/addnode.hpp"
stefank@2314 31 #include "opto/memnode.hpp"
stefank@2314 32 #include "opto/parse.hpp"
stefank@2314 33 #include "opto/rootnode.hpp"
stefank@2314 34 #include "opto/runtime.hpp"
stefank@2314 35 #include "opto/subnode.hpp"
stefank@2314 36 #include "runtime/deoptimization.hpp"
stefank@2314 37 #include "runtime/handles.inline.hpp"
duke@435 38
duke@435 39 //=============================================================================
duke@435 40 // Helper methods for _get* and _put* bytecodes
duke@435 41 //=============================================================================
duke@435 42 bool Parse::static_field_ok_in_clinit(ciField *field, ciMethod *method) {
duke@435 43 // Could be the field_holder's <clinit> method, or <clinit> for a subklass.
duke@435 44 // Better to check now than to Deoptimize as soon as we execute
duke@435 45 assert( field->is_static(), "Only check if field is static");
duke@435 46 // is_being_initialized() is too generous. It allows access to statics
duke@435 47 // by threads that are not running the <clinit> before the <clinit> finishes.
duke@435 48 // return field->holder()->is_being_initialized();
duke@435 49
duke@435 50 // The following restriction is correct but conservative.
duke@435 51 // It is also desirable to allow compilation of methods called from <clinit>
duke@435 52 // but this generated code will need to be made safe for execution by
duke@435 53 // other threads, or the transition from interpreted to compiled code would
duke@435 54 // need to be guarded.
duke@435 55 ciInstanceKlass *field_holder = field->holder();
duke@435 56
duke@435 57 bool access_OK = false;
duke@435 58 if (method->holder()->is_subclass_of(field_holder)) {
duke@435 59 if (method->is_static()) {
duke@435 60 if (method->name() == ciSymbol::class_initializer_name()) {
duke@435 61 // OK to access static fields inside initializer
duke@435 62 access_OK = true;
duke@435 63 }
duke@435 64 } else {
duke@435 65 if (method->name() == ciSymbol::object_initializer_name()) {
duke@435 66 // It's also OK to access static fields inside a constructor,
duke@435 67 // because any thread calling the constructor must first have
duke@435 68 // synchronized on the class by executing a '_new' bytecode.
duke@435 69 access_OK = true;
duke@435 70 }
duke@435 71 }
duke@435 72 }
duke@435 73
duke@435 74 return access_OK;
duke@435 75
duke@435 76 }
duke@435 77
duke@435 78
duke@435 79 void Parse::do_field_access(bool is_get, bool is_field) {
duke@435 80 bool will_link;
duke@435 81 ciField* field = iter().get_field(will_link);
duke@435 82 assert(will_link, "getfield: typeflow responsibility");
duke@435 83
duke@435 84 ciInstanceKlass* field_holder = field->holder();
duke@435 85
duke@435 86 if (is_field == field->is_static()) {
duke@435 87 // Interpreter will throw java_lang_IncompatibleClassChangeError
duke@435 88 // Check this before allowing <clinit> methods to access static fields
duke@435 89 uncommon_trap(Deoptimization::Reason_unhandled,
duke@435 90 Deoptimization::Action_none);
duke@435 91 return;
duke@435 92 }
duke@435 93
duke@435 94 if (!is_field && !field_holder->is_initialized()) {
duke@435 95 if (!static_field_ok_in_clinit(field, method())) {
duke@435 96 uncommon_trap(Deoptimization::Reason_uninitialized,
duke@435 97 Deoptimization::Action_reinterpret,
duke@435 98 NULL, "!static_field_ok_in_clinit");
duke@435 99 return;
duke@435 100 }
duke@435 101 }
duke@435 102
twisti@3101 103 // Deoptimize on putfield writes to call site target field.
twisti@3050 104 if (!is_get && field->is_call_site_target()) {
twisti@3050 105 uncommon_trap(Deoptimization::Reason_unhandled,
twisti@3050 106 Deoptimization::Action_reinterpret,
twisti@3101 107 NULL, "put to call site target field");
twisti@3050 108 return;
twisti@3050 109 }
twisti@3050 110
duke@435 111 assert(field->will_link(method()->holder(), bc()), "getfield: typeflow responsibility");
duke@435 112
duke@435 113 // Note: We do not check for an unloaded field type here any more.
duke@435 114
duke@435 115 // Generate code for the object pointer.
duke@435 116 Node* obj;
duke@435 117 if (is_field) {
duke@435 118 int obj_depth = is_get ? 0 : field->type()->size();
twisti@4313 119 obj = null_check(peek(obj_depth));
duke@435 120 // Compile-time detect of null-exception?
duke@435 121 if (stopped()) return;
duke@435 122
never@2658 123 #ifdef ASSERT
duke@435 124 const TypeInstPtr *tjp = TypeInstPtr::make(TypePtr::NotNull, iter().get_declared_field_holder());
duke@435 125 assert(_gvn.type(obj)->higher_equal(tjp), "cast_up is no longer needed");
never@2658 126 #endif
duke@435 127
duke@435 128 if (is_get) {
twisti@4313 129 (void) pop(); // pop receiver before getting
never@2658 130 do_get_xxx(obj, field, is_field);
duke@435 131 } else {
never@2658 132 do_put_xxx(obj, field, is_field);
twisti@4313 133 (void) pop(); // pop receiver after putting
duke@435 134 }
duke@435 135 } else {
never@2658 136 const TypeInstPtr* tip = TypeInstPtr::make(field_holder->java_mirror());
never@2658 137 obj = _gvn.makecon(tip);
duke@435 138 if (is_get) {
never@2658 139 do_get_xxx(obj, field, is_field);
duke@435 140 } else {
never@2658 141 do_put_xxx(obj, field, is_field);
duke@435 142 }
duke@435 143 }
duke@435 144 }
duke@435 145
duke@435 146
never@2658 147 void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) {
duke@435 148 // Does this field have a constant value? If so, just push the value.
twisti@1573 149 if (field->is_constant()) {
vlivanov@5658 150 // final or stable field
vlivanov@5658 151 const Type* stable_type = NULL;
vlivanov@5658 152 if (FoldStableValues && field->is_stable()) {
vlivanov@5658 153 stable_type = Type::get_const_type(field->type());
vlivanov@5658 154 if (field->type()->is_array_klass()) {
vlivanov@5658 155 int stable_dimension = field->type()->as_array_klass()->dimension();
vlivanov@5658 156 stable_type = stable_type->is_aryptr()->cast_to_stable(true, stable_dimension);
vlivanov@5658 157 }
vlivanov@5658 158 }
twisti@1573 159 if (field->is_static()) {
twisti@1573 160 // final static field
kvn@5110 161 if (C->eliminate_boxing()) {
kvn@5110 162 // The pointers in the autobox arrays are always non-null.
kvn@5110 163 ciSymbol* klass_name = field->holder()->name();
kvn@5110 164 if (field->name() == ciSymbol::cache_field_name() &&
kvn@5110 165 field->holder()->uses_default_loader() &&
kvn@5110 166 (klass_name == ciSymbol::java_lang_Character_CharacterCache() ||
kvn@5110 167 klass_name == ciSymbol::java_lang_Byte_ByteCache() ||
kvn@5110 168 klass_name == ciSymbol::java_lang_Short_ShortCache() ||
kvn@5110 169 klass_name == ciSymbol::java_lang_Integer_IntegerCache() ||
kvn@5110 170 klass_name == ciSymbol::java_lang_Long_LongCache())) {
kvn@5110 171 bool require_const = true;
kvn@5110 172 bool autobox_cache = true;
kvn@5110 173 if (push_constant(field->constant_value(), require_const, autobox_cache)) {
kvn@5110 174 return;
kvn@5110 175 }
kvn@5110 176 }
kvn@5110 177 }
vlivanov@5658 178 if (push_constant(field->constant_value(), false, false, stable_type))
twisti@1573 179 return;
vlivanov@5658 180 } else {
vlivanov@5658 181 // final or stable non-static field
twisti@3102 182 // Treat final non-static fields of trusted classes (classes in
twisti@3102 183 // java.lang.invoke and sun.invoke packages and subpackages) as
twisti@3102 184 // compile time constants.
twisti@1573 185 if (obj->is_Con()) {
twisti@1573 186 const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr();
twisti@1573 187 ciObject* constant_oop = oop_ptr->const_oop();
twisti@1573 188 ciConstant constant = field->constant_value_of(constant_oop);
vlivanov@5658 189 if (FoldStableValues && field->is_stable() && constant.is_null_or_zero()) {
vlivanov@5658 190 // fall through to field load; the field is not yet initialized
vlivanov@5658 191 } else {
vlivanov@5658 192 if (push_constant(constant, true, false, stable_type))
vlivanov@5658 193 return;
vlivanov@5658 194 }
twisti@1573 195 }
twisti@1573 196 }
twisti@1573 197 }
duke@435 198
duke@435 199 ciType* field_klass = field->type();
duke@435 200 bool is_vol = field->is_volatile();
duke@435 201
duke@435 202 // Compute address and memory type.
duke@435 203 int offset = field->offset_in_bytes();
duke@435 204 const TypePtr* adr_type = C->alias_type(field)->adr_type();
duke@435 205 Node *adr = basic_plus_adr(obj, obj, offset);
duke@435 206 BasicType bt = field->layout_type();
duke@435 207
duke@435 208 // Build the resultant type of the load
duke@435 209 const Type *type;
duke@435 210
duke@435 211 bool must_assert_null = false;
duke@435 212
duke@435 213 if( bt == T_OBJECT ) {
duke@435 214 if (!field->type()->is_loaded()) {
duke@435 215 type = TypeInstPtr::BOTTOM;
duke@435 216 must_assert_null = true;
twisti@1573 217 } else if (field->is_constant() && field->is_static()) {
duke@435 218 // This can happen if the constant oop is non-perm.
duke@435 219 ciObject* con = field->constant_value().as_object();
duke@435 220 // Do not "join" in the previous type; it doesn't add value,
duke@435 221 // and may yield a vacuous result if the field is of interface type.
duke@435 222 type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
duke@435 223 assert(type != NULL, "field singleton type must be consistent");
duke@435 224 } else {
duke@435 225 type = TypeOopPtr::make_from_klass(field_klass->as_klass());
duke@435 226 }
duke@435 227 } else {
duke@435 228 type = Type::get_const_basic_type(bt);
duke@435 229 }
goetz@6502 230 if (support_IRIW_for_not_multiple_copy_atomic_cpu && field->is_volatile()) {
goetz@6502 231 insert_mem_bar(Op_MemBarVolatile); // StoreLoad barrier
goetz@6502 232 }
duke@435 233 // Build the load.
goetz@6479 234 //
goetz@6479 235 MemNode::MemOrd mo = is_vol ? MemNode::acquire : MemNode::unordered;
goetz@6479 236 Node* ld = make_load(NULL, adr, type, bt, adr_type, mo, is_vol);
duke@435 237
duke@435 238 // Adjust Java stack
duke@435 239 if (type2size[bt] == 1)
duke@435 240 push(ld);
duke@435 241 else
duke@435 242 push_pair(ld);
duke@435 243
duke@435 244 if (must_assert_null) {
duke@435 245 // Do not take a trap here. It's possible that the program
duke@435 246 // will never load the field's class, and will happily see
duke@435 247 // null values in this field forever. Don't stumble into a
duke@435 248 // trap for such a program, or we might get a long series
duke@435 249 // of useless recompilations. (Or, we might load a class
duke@435 250 // which should not be loaded.) If we ever see a non-null
duke@435 251 // value, we will then trap and recompile. (The trap will
duke@435 252 // not need to mention the class index, since the class will
duke@435 253 // already have been loaded if we ever see a non-null value.)
duke@435 254 // uncommon_trap(iter().get_field_signature_index());
duke@435 255 #ifndef PRODUCT
duke@435 256 if (PrintOpto && (Verbose || WizardMode)) {
duke@435 257 method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
duke@435 258 }
duke@435 259 #endif
duke@435 260 if (C->log() != NULL) {
duke@435 261 C->log()->elem("assert_null reason='field' klass='%d'",
duke@435 262 C->log()->identify(field->type()));
duke@435 263 }
duke@435 264 // If there is going to be a trap, put it at the next bytecode:
duke@435 265 set_bci(iter().next_bci());
twisti@4313 266 null_assert(peek());
duke@435 267 set_bci(iter().cur_bci()); // put it back
duke@435 268 }
duke@435 269
duke@435 270 // If reference is volatile, prevent following memory ops from
duke@435 271 // floating up past the volatile read. Also prevents commoning
duke@435 272 // another volatile read.
duke@435 273 if (field->is_volatile()) {
duke@435 274 // Memory barrier includes bogus read of value to force load BEFORE membar
duke@435 275 insert_mem_bar(Op_MemBarAcquire, ld);
duke@435 276 }
duke@435 277 }
duke@435 278
never@2658 279 void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
duke@435 280 bool is_vol = field->is_volatile();
duke@435 281 // If reference is volatile, prevent following memory ops from
duke@435 282 // floating down past the volatile write. Also prevents commoning
duke@435 283 // another volatile read.
duke@435 284 if (is_vol) insert_mem_bar(Op_MemBarRelease);
duke@435 285
duke@435 286 // Compute address and memory type.
duke@435 287 int offset = field->offset_in_bytes();
duke@435 288 const TypePtr* adr_type = C->alias_type(field)->adr_type();
duke@435 289 Node* adr = basic_plus_adr(obj, obj, offset);
duke@435 290 BasicType bt = field->layout_type();
duke@435 291 // Value to be stored
duke@435 292 Node* val = type2size[bt] == 1 ? pop() : pop_pair();
duke@435 293 // Round doubles before storing
duke@435 294 if (bt == T_DOUBLE) val = dstore_rounding(val);
duke@435 295
goetz@6479 296 // Conservatively release stores of object references.
goetz@6479 297 const MemNode::MemOrd mo =
goetz@6479 298 is_vol ?
goetz@6479 299 // Volatile fields need releasing stores.
goetz@6479 300 MemNode::release :
goetz@6479 301 // Non-volatile fields also need releasing stores if they hold an
goetz@6479 302 // object reference, because the object reference might point to
goetz@6479 303 // a freshly created object.
goetz@6479 304 StoreNode::release_if_reference(bt);
goetz@6479 305
duke@435 306 // Store the value.
duke@435 307 Node* store;
duke@435 308 if (bt == T_OBJECT) {
never@1260 309 const TypeOopPtr* field_type;
duke@435 310 if (!field->type()->is_loaded()) {
duke@435 311 field_type = TypeInstPtr::BOTTOM;
duke@435 312 } else {
duke@435 313 field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
duke@435 314 }
goetz@6479 315 store = store_oop_to_object(control(), obj, adr, adr_type, val, field_type, bt, mo);
duke@435 316 } else {
goetz@6479 317 store = store_to_memory(control(), adr, val, bt, adr_type, mo, is_vol);
duke@435 318 }
duke@435 319
duke@435 320 // If reference is volatile, prevent following volatiles ops from
duke@435 321 // floating up before the volatile write.
duke@435 322 if (is_vol) {
goetz@6502 323 // If not multiple copy atomic, we do the MemBarVolatile before the load.
goetz@6502 324 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
goetz@6502 325 insert_mem_bar(Op_MemBarVolatile); // Use fat membar
goetz@6502 326 }
goetz@6502 327 // Remember we wrote a volatile field.
goetz@6502 328 // For not multiple copy atomic cpu (ppc64) a barrier should be issued
goetz@6502 329 // in constructors which have such stores. See do_exits() in parse1.cpp.
goetz@6502 330 if (is_field) {
goetz@6502 331 set_wrote_volatile(true);
goetz@6502 332 }
duke@435 333 }
duke@435 334
duke@435 335 // If the field is final, the rules of Java say we are in <init> or <clinit>.
duke@435 336 // Note the presence of writes to final non-static fields, so that we
duke@435 337 // can insert a memory barrier later on to keep the writes from floating
duke@435 338 // out of the constructor.
vlivanov@5658 339 // Any method can write a @Stable field; insert memory barriers after those also.
vlivanov@5658 340 if (is_field && (field->is_final() || field->is_stable())) {
duke@435 341 set_wrote_final(true);
kvn@5110 342 // Preserve allocation ptr to create precedent edge to it in membar
kvn@5110 343 // generated on exit from constructor.
kvn@5110 344 if (C->eliminate_boxing() &&
kvn@5110 345 adr_type->isa_oopptr() && adr_type->is_oopptr()->is_ptr_to_boxed_value() &&
kvn@5110 346 AllocateNode::Ideal_allocation(obj, &_gvn) != NULL) {
kvn@5110 347 set_alloc_with_final(obj);
kvn@5110 348 }
duke@435 349 }
duke@435 350 }
duke@435 351
duke@435 352
vlivanov@5658 353
vlivanov@5658 354 bool Parse::push_constant(ciConstant constant, bool require_constant, bool is_autobox_cache, const Type* stable_type) {
vlivanov@5658 355 const Type* con_type = Type::make_from_constant(constant, require_constant, is_autobox_cache);
duke@435 356 switch (constant.basic_type()) {
duke@435 357 case T_ARRAY:
vlivanov@5658 358 case T_OBJECT:
jrose@1424 359 // cases:
jrose@1424 360 // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0)
jrose@1424 361 // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
jrose@1424 362 // An oop is not scavengable if it is in the perm gen.
vlivanov@5658 363 if (stable_type != NULL && con_type != NULL && con_type->isa_oopptr())
roland@6313 364 con_type = con_type->join_speculative(stable_type);
vlivanov@5658 365 break;
vlivanov@5658 366
vlivanov@5658 367 case T_ILLEGAL:
duke@435 368 // Invalid ciConstant returned due to OutOfMemoryError in the CI
duke@435 369 assert(C->env()->failing(), "otherwise should not see this");
duke@435 370 // These always occur because of object types; we are going to
duke@435 371 // bail out anyway, so make the stack depths match up
duke@435 372 push( zerocon(T_OBJECT) );
duke@435 373 return false;
duke@435 374 }
vlivanov@5658 375
vlivanov@5658 376 if (con_type == NULL)
vlivanov@5658 377 // we cannot inline the oop, but we can use it later to narrow a type
duke@435 378 return false;
duke@435 379
vlivanov@5658 380 push_node(constant.basic_type(), makecon(con_type));
duke@435 381 return true;
duke@435 382 }
duke@435 383
duke@435 384
duke@435 385 //=============================================================================
duke@435 386 void Parse::do_anewarray() {
duke@435 387 bool will_link;
duke@435 388 ciKlass* klass = iter().get_klass(will_link);
duke@435 389
duke@435 390 // Uncommon Trap when class that array contains is not loaded
duke@435 391 // we need the loaded class for the rest of graph; do not
duke@435 392 // initialize the container class (see Java spec)!!!
duke@435 393 assert(will_link, "anewarray: typeflow responsibility");
duke@435 394
duke@435 395 ciObjArrayKlass* array_klass = ciObjArrayKlass::make(klass);
duke@435 396 // Check that array_klass object is loaded
duke@435 397 if (!array_klass->is_loaded()) {
duke@435 398 // Generate uncommon_trap for unloaded array_class
duke@435 399 uncommon_trap(Deoptimization::Reason_unloaded,
duke@435 400 Deoptimization::Action_reinterpret,
duke@435 401 array_klass);
duke@435 402 return;
duke@435 403 }
duke@435 404
duke@435 405 kill_dead_locals();
duke@435 406
duke@435 407 const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass);
duke@435 408 Node* count_val = pop();
cfang@1165 409 Node* obj = new_array(makecon(array_klass_type), count_val, 1);
duke@435 410 push(obj);
duke@435 411 }
duke@435 412
duke@435 413
duke@435 414 void Parse::do_newarray(BasicType elem_type) {
duke@435 415 kill_dead_locals();
duke@435 416
duke@435 417 Node* count_val = pop();
duke@435 418 const TypeKlassPtr* array_klass = TypeKlassPtr::make(ciTypeArrayKlass::make(elem_type));
cfang@1165 419 Node* obj = new_array(makecon(array_klass), count_val, 1);
duke@435 420 // Push resultant oop onto stack
duke@435 421 push(obj);
duke@435 422 }
duke@435 423
duke@435 424 // Expand simple expressions like new int[3][5] and new Object[2][nonConLen].
duke@435 425 // Also handle the degenerate 1-dimensional case of anewarray.
cfang@1165 426 Node* Parse::expand_multianewarray(ciArrayKlass* array_klass, Node* *lengths, int ndimensions, int nargs) {
duke@435 427 Node* length = lengths[0];
duke@435 428 assert(length != NULL, "");
cfang@1165 429 Node* array = new_array(makecon(TypeKlassPtr::make(array_klass)), length, nargs);
duke@435 430 if (ndimensions > 1) {
duke@435 431 jint length_con = find_int_con(length, -1);
duke@435 432 guarantee(length_con >= 0, "non-constant multianewarray");
duke@435 433 ciArrayKlass* array_klass_1 = array_klass->as_obj_array_klass()->element_klass()->as_array_klass();
duke@435 434 const TypePtr* adr_type = TypeAryPtr::OOPS;
never@1262 435 const TypeOopPtr* elemtype = _gvn.type(array)->is_aryptr()->elem()->make_oopptr();
duke@435 436 const intptr_t header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
duke@435 437 for (jint i = 0; i < length_con; i++) {
cfang@1165 438 Node* elem = expand_multianewarray(array_klass_1, &lengths[1], ndimensions-1, nargs);
coleenp@548 439 intptr_t offset = header + ((intptr_t)i << LogBytesPerHeapOop);
duke@435 440 Node* eaddr = basic_plus_adr(array, offset);
goetz@6479 441 store_oop_to_array(control(), array, eaddr, adr_type, elem, elemtype, T_OBJECT, MemNode::unordered);
duke@435 442 }
duke@435 443 }
duke@435 444 return array;
duke@435 445 }
duke@435 446
duke@435 447 void Parse::do_multianewarray() {
duke@435 448 int ndimensions = iter().get_dimensions();
duke@435 449
duke@435 450 // the m-dimensional array
duke@435 451 bool will_link;
duke@435 452 ciArrayKlass* array_klass = iter().get_klass(will_link)->as_array_klass();
duke@435 453 assert(will_link, "multianewarray: typeflow responsibility");
duke@435 454
duke@435 455 // Note: Array classes are always initialized; no is_initialized check.
duke@435 456
duke@435 457 kill_dead_locals();
duke@435 458
duke@435 459 // get the lengths from the stack (first dimension is on top)
iveresov@3002 460 Node** length = NEW_RESOURCE_ARRAY(Node*, ndimensions + 1);
duke@435 461 length[ndimensions] = NULL; // terminating null for make_runtime_call
duke@435 462 int j;
duke@435 463 for (j = ndimensions-1; j >= 0 ; j--) length[j] = pop();
duke@435 464
duke@435 465 // The original expression was of this form: new T[length0][length1]...
duke@435 466 // It is often the case that the lengths are small (except the last).
duke@435 467 // If that happens, use the fast 1-d creator a constant number of times.
duke@435 468 const jint expand_limit = MIN2((juint)MultiArrayExpandLimit, (juint)100);
duke@435 469 jint expand_count = 1; // count of allocations in the expansion
duke@435 470 jint expand_fanout = 1; // running total fanout
duke@435 471 for (j = 0; j < ndimensions-1; j++) {
duke@435 472 jint dim_con = find_int_con(length[j], -1);
duke@435 473 expand_fanout *= dim_con;
duke@435 474 expand_count += expand_fanout; // count the level-J sub-arrays
rasbold@541 475 if (dim_con <= 0
duke@435 476 || dim_con > expand_limit
duke@435 477 || expand_count > expand_limit) {
duke@435 478 expand_count = 0;
duke@435 479 break;
duke@435 480 }
duke@435 481 }
duke@435 482
duke@435 483 // Can use multianewarray instead of [a]newarray if only one dimension,
duke@435 484 // or if all non-final dimensions are small constants.
kvn@1687 485 if (ndimensions == 1 || (1 <= expand_count && expand_count <= expand_limit)) {
kvn@1687 486 Node* obj = NULL;
kvn@1687 487 // Set the original stack and the reexecute bit for the interpreter
kvn@1687 488 // to reexecute the multianewarray bytecode if deoptimization happens.
kvn@1687 489 // Do it unconditionally even for one dimension multianewarray.
kvn@1687 490 // Note: the reexecute bit will be set in GraphKit::add_safepoint_edges()
kvn@1687 491 // when AllocateArray node for newarray is created.
kvn@1687 492 { PreserveReexecuteState preexecs(this);
twisti@4313 493 inc_sp(ndimensions);
kvn@1687 494 // Pass 0 as nargs since uncommon trap code does not need to restore stack.
kvn@1687 495 obj = expand_multianewarray(array_klass, &length[0], ndimensions, 0);
kvn@1687 496 } //original reexecute and sp are set back here
duke@435 497 push(obj);
duke@435 498 return;
duke@435 499 }
duke@435 500
duke@435 501 address fun = NULL;
duke@435 502 switch (ndimensions) {
iveresov@3002 503 case 1: ShouldNotReachHere(); break;
duke@435 504 case 2: fun = OptoRuntime::multianewarray2_Java(); break;
duke@435 505 case 3: fun = OptoRuntime::multianewarray3_Java(); break;
duke@435 506 case 4: fun = OptoRuntime::multianewarray4_Java(); break;
duke@435 507 case 5: fun = OptoRuntime::multianewarray5_Java(); break;
duke@435 508 };
iveresov@3002 509 Node* c = NULL;
duke@435 510
iveresov@3002 511 if (fun != NULL) {
iveresov@3002 512 c = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
iveresov@3002 513 OptoRuntime::multianewarray_Type(ndimensions),
iveresov@3002 514 fun, NULL, TypeRawPtr::BOTTOM,
iveresov@3002 515 makecon(TypeKlassPtr::make(array_klass)),
iveresov@3002 516 length[0], length[1], length[2],
drchase@4540 517 (ndimensions > 2) ? length[3] : NULL,
drchase@4540 518 (ndimensions > 3) ? length[4] : NULL);
iveresov@3002 519 } else {
iveresov@3002 520 // Create a java array for dimension sizes
iveresov@3002 521 Node* dims = NULL;
iveresov@3002 522 { PreserveReexecuteState preexecs(this);
twisti@4313 523 inc_sp(ndimensions);
iveresov@3002 524 Node* dims_array_klass = makecon(TypeKlassPtr::make(ciArrayKlass::make(ciType::make(T_INT))));
iveresov@3002 525 dims = new_array(dims_array_klass, intcon(ndimensions), 0);
iveresov@3002 526
iveresov@3002 527 // Fill-in it with values
iveresov@3002 528 for (j = 0; j < ndimensions; j++) {
iveresov@3002 529 Node *dims_elem = array_element_address(dims, intcon(j), T_INT);
goetz@6479 530 store_to_memory(control(), dims_elem, length[j], T_INT, TypeAryPtr::INTS, MemNode::unordered);
iveresov@3002 531 }
iveresov@3002 532 }
iveresov@3002 533
iveresov@3002 534 c = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
iveresov@3002 535 OptoRuntime::multianewarrayN_Type(),
iveresov@3002 536 OptoRuntime::multianewarrayN_Java(), NULL, TypeRawPtr::BOTTOM,
iveresov@3002 537 makecon(TypeKlassPtr::make(array_klass)),
iveresov@3002 538 dims);
iveresov@3002 539 }
kvn@4364 540 make_slow_call_ex(c, env()->Throwable_klass(), false);
iveresov@3002 541
kvn@4115 542 Node* res = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms));
duke@435 543
duke@435 544 const Type* type = TypeOopPtr::make_from_klass_raw(array_klass);
duke@435 545
duke@435 546 // Improve the type: We know it's not null, exact, and of a given length.
duke@435 547 type = type->is_ptr()->cast_to_ptr_type(TypePtr::NotNull);
duke@435 548 type = type->is_aryptr()->cast_to_exactness(true);
duke@435 549
duke@435 550 const TypeInt* ltype = _gvn.find_int_type(length[0]);
duke@435 551 if (ltype != NULL)
duke@435 552 type = type->is_aryptr()->cast_to_size(ltype);
duke@435 553
iveresov@3002 554 // We cannot sharpen the nested sub-arrays, since the top level is mutable.
duke@435 555
kvn@4115 556 Node* cast = _gvn.transform( new (C) CheckCastPPNode(control(), res, type) );
duke@435 557 push(cast);
duke@435 558
duke@435 559 // Possible improvements:
duke@435 560 // - Make a fast path for small multi-arrays. (W/ implicit init. loops.)
duke@435 561 // - Issue CastII against length[*] values, to TypeInt::POS.
duke@435 562 }

mercurial