1 /*
  2  * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "compiler/compileLog.hpp"
 26 #include "interpreter/linkResolver.hpp"
 27 #include "memory/universe.hpp"
 28 #include "oops/flatArrayKlass.hpp"
 29 #include "oops/objArrayKlass.hpp"
 30 #include "opto/addnode.hpp"
 31 #include "opto/castnode.hpp"
 32 #include "opto/inlinetypenode.hpp"
 33 #include "opto/memnode.hpp"
 34 #include "opto/parse.hpp"
 35 #include "opto/rootnode.hpp"
 36 #include "opto/runtime.hpp"
 37 #include "opto/subnode.hpp"
 38 #include "runtime/deoptimization.hpp"
 39 #include "runtime/handles.inline.hpp"
 40 
 41 //=============================================================================
 42 // Helper methods for _get* and _put* bytecodes
 43 //=============================================================================
 44 
 45 void Parse::do_field_access(bool is_get, bool is_field) {
 46   bool will_link;
 47   ciField* field = iter().get_field(will_link);
 48   assert(will_link, "getfield: typeflow responsibility");
 49 
 50   ciInstanceKlass* field_holder = field->holder();
 51 
 52   if (is_get && is_field && field_holder->is_inlinetype() && peek()->is_InlineType()) {
 53     InlineTypeNode* vt = peek()->as_InlineType();
 54     null_check(vt);
 55     Node* value = vt->field_value_by_offset(field->offset_in_bytes());
 56     if (value->is_InlineType()) {
 57       value = value->as_InlineType()->adjust_scalarization_depth(this);
 58     }
 59     pop();
 60     push_node(field->layout_type(), value);
 61     return;
 62   }
 63 
 64   if (is_field == field->is_static()) {
 65     // Interpreter will throw java_lang_IncompatibleClassChangeError
 66     // Check this before allowing <clinit> methods to access static fields
 67     uncommon_trap(Deoptimization::Reason_unhandled,
 68                   Deoptimization::Action_none);
 69     return;
 70   }
 71 
 72   // Deoptimize on putfield writes to call site target field outside of CallSite ctor.
 73   if (!is_get && field->is_call_site_target() &&
 74       !(method()->holder() == field_holder && method()->is_object_constructor())) {
 75     uncommon_trap(Deoptimization::Reason_unhandled,
 76                   Deoptimization::Action_reinterpret,
 77                   nullptr, "put to call site target field");
 78     return;
 79   }
 80 
 81   if (C->needs_clinit_barrier(field, method())) {
 82     clinit_barrier(field_holder, method());
 83     if (stopped())  return;
 84   }
 85 
 86   assert(field->will_link(method(), bc()), "getfield: typeflow responsibility");
 87 
 88   // Note:  We do not check for an unloaded field type here any more.
 89 
 90   // Generate code for the object pointer.
 91   Node* obj;
 92   if (is_field) {
 93     int obj_depth = is_get ? 0 : field->type()->size();
 94     obj = null_check(peek(obj_depth));
 95     // Compile-time detect of null-exception?
 96     if (stopped())  return;
 97 
 98 #ifdef ASSERT
 99     const TypeInstPtr *tjp = TypeInstPtr::make(TypePtr::NotNull, iter().get_declared_field_holder());
100     assert(_gvn.type(obj)->higher_equal(tjp), "cast_up is no longer needed");
101 #endif
102 
103     if (is_get) {
104       (void) pop();  // pop receiver before getting
105       do_get_xxx(obj, field);
106     } else {
107       do_put_xxx(obj, field, is_field);
108       if (stopped()) {
109         return;
110       }
111       (void) pop();  // pop receiver after putting
112     }
113   } else {
114     const TypeInstPtr* tip = TypeInstPtr::make(field_holder->java_mirror());
115     obj = _gvn.makecon(tip);
116     if (is_get) {
117       do_get_xxx(obj, field);
118     } else {
119       do_put_xxx(obj, field, is_field);
120     }
121   }
122 }
123 
124 void Parse::do_get_xxx(Node* obj, ciField* field) {
125   BasicType bt = field->layout_type();
126   // Does this field have a constant value?  If so, just push the value.
127   if (field->is_constant() && !field->is_flat() &&
128       // Keep consistent with types found by ciTypeFlow: for an
129       // unloaded field type, ciTypeFlow::StateVector::do_getstatic()
130       // speculates the field is null. The code in the rest of this
131       // method does the same. We must not bypass it and use a non
132       // null constant here.
133       (bt != T_OBJECT || field->type()->is_loaded())) {
134     // final or stable field
135     Node* con = make_constant_from_field(field, obj);
136     if (con != nullptr) {
137       push_node(field->layout_type(), con);
138       return;
139     }
140   }
141 
142   ciType* field_klass = field->type();
143   field_klass = improve_abstract_inline_type_klass(field_klass);
144   int offset = field->offset_in_bytes();
145   bool must_assert_null = false;
146 
147   Node* ld = nullptr;
148   if (field->is_null_free() && field_klass->as_inline_klass()->is_empty()) {
149     // Loading from a field of an empty inline type. Just return the default instance.
150     ld = InlineTypeNode::make_all_zero(_gvn, field_klass->as_inline_klass());
151   } else if (field->is_flat()) {
152     // Loading from a flat inline type field.
153     ciInlineKlass* vk = field->type()->as_inline_klass();
154     bool is_naturally_atomic = field->is_null_free() && vk->nof_declared_nonstatic_fields() <= 1;
155     bool needs_atomic_access = (!field->is_null_free() || field->is_volatile()) && !is_naturally_atomic;
156     ld = InlineTypeNode::make_from_flat(this, field_klass->as_inline_klass(), obj, obj, nullptr, field->holder(), offset, needs_atomic_access, field->null_marker_offset());
157   } else {
158     // Build the resultant type of the load
159     const Type* type;
160     if (is_reference_type(bt)) {
161       if (!field_klass->is_loaded()) {
162         type = TypeInstPtr::BOTTOM;
163         must_assert_null = true;
164       } else if (field->is_static_constant()) {
165         // This can happen if the constant oop is non-perm.
166         ciObject* con = field->constant_value().as_object();
167         // Do not "join" in the previous type; it doesn't add value,
168         // and may yield a vacuous result if the field is of interface type.
169         if (con->is_null_object()) {
170           type = TypePtr::NULL_PTR;
171         } else {
172           type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
173         }
174         assert(type != nullptr, "field singleton type must be consistent");
175       } else {
176         type = TypeOopPtr::make_from_klass(field_klass->as_klass());
177         if (field->is_null_free()) {
178           type = type->join_speculative(TypePtr::NOTNULL);
179         }
180       }
181     } else {
182       type = Type::get_const_basic_type(bt);
183     }
184     Node* adr = basic_plus_adr(obj, obj, offset);
185     const TypePtr* adr_type = C->alias_type(field)->adr_type();
186     DecoratorSet decorators = IN_HEAP;
187     decorators |= field->is_volatile() ? MO_SEQ_CST : MO_UNORDERED;
188     ld = access_load_at(obj, adr, adr_type, type, bt, decorators);
189     if (field_klass->is_inlinetype()) {
190       // Load a non-flattened inline type from memory
191       ld = InlineTypeNode::make_from_oop(this, ld, field_klass->as_inline_klass());
192     }
193   }
194 
195   // Adjust Java stack
196   if (type2size[bt] == 1)
197     push(ld);
198   else
199     push_pair(ld);
200 
201   if (must_assert_null) {
202     // Do not take a trap here.  It's possible that the program
203     // will never load the field's class, and will happily see
204     // null values in this field forever.  Don't stumble into a
205     // trap for such a program, or we might get a long series
206     // of useless recompilations.  (Or, we might load a class
207     // which should not be loaded.)  If we ever see a non-null
208     // value, we will then trap and recompile.  (The trap will
209     // not need to mention the class index, since the class will
210     // already have been loaded if we ever see a non-null value.)
211     // uncommon_trap(iter().get_field_signature_index());
212     if (PrintOpto && (Verbose || WizardMode)) {
213       method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
214     }
215     if (C->log() != nullptr) {
216       C->log()->elem("assert_null reason='field' klass='%d'",
217                      C->log()->identify(field_klass));
218     }
219     // If there is going to be a trap, put it at the next bytecode:
220     set_bci(iter().next_bci());
221     null_assert(peek());
222     set_bci(iter().cur_bci()); // put it back
223   }
224 }
225 
226 // If the field klass is an abstract value klass (for which we do not know the layout, yet), it could have a unique
227 // concrete sub klass for which we have a fixed layout. This allows us to use InlineTypeNodes instead.
228 ciType* Parse::improve_abstract_inline_type_klass(ciType* field_klass) {
229   Dependencies* dependencies = C->dependencies();
230   if (UseUniqueSubclasses && dependencies != nullptr && field_klass->is_instance_klass()) {
231     ciInstanceKlass* instance_klass = field_klass->as_instance_klass();
232     if (instance_klass->is_loaded() && instance_klass->is_abstract_value_klass()) {
233       ciInstanceKlass* sub_klass = instance_klass->unique_concrete_subklass();
234       if (sub_klass != nullptr && sub_klass != field_klass) {
235         field_klass = sub_klass;
236         dependencies->assert_abstract_with_unique_concrete_subtype(instance_klass, sub_klass);
237       }
238     }
239   }
240   return field_klass;
241 }
242 
243 void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
244   bool is_vol = field->is_volatile();
245   int offset = field->offset_in_bytes();
246   BasicType bt = field->layout_type();
247   Node* val = type2size[bt] == 1 ? pop() : pop_pair();
248 
249   if (field->is_null_free()) {
250     PreserveReexecuteState preexecs(this);
251     jvms()->set_should_reexecute(true);
252     inc_sp(1);
253     val = null_check(val);
254     if (stopped()) {
255       return;
256     }
257   }
258   if (obj->is_InlineType()) {
259     set_inline_type_field(obj, field, val);
260     return;
261   }
262   if (field->is_null_free() && field->type()->as_inline_klass()->is_empty() && (!method()->is_object_constructor() || field->is_flat())) {
263     // Storing to a field of an empty, null-free inline type that is already initialized. Ignore.
264     return;
265   } else if (field->is_flat()) {
266     // Storing to a flat inline type field.
267     ciInlineKlass* vk = field->type()->as_inline_klass();
268     if (!val->is_InlineType()) {
269       assert(gvn().type(val) == TypePtr::NULL_PTR, "Unexpected value");
270       val = InlineTypeNode::make_null(gvn(), vk);
271     }
272     inc_sp(1);
273     bool is_naturally_atomic = field->is_null_free() && vk->nof_declared_nonstatic_fields() <= 1;
274     bool needs_atomic_access = (!field->is_null_free() || field->is_volatile()) && !is_naturally_atomic;
275     val->as_InlineType()->store_flat(this, obj, obj, nullptr, field->holder(), offset, needs_atomic_access, field->null_marker_offset(), IN_HEAP | MO_UNORDERED);
276     dec_sp(1);
277   } else {
278     // Store the value.
279     const Type* field_type;
280     if (!field->type()->is_loaded()) {
281       field_type = TypeInstPtr::BOTTOM;
282     } else {
283       if (is_reference_type(bt)) {
284         field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
285       } else {
286         field_type = Type::BOTTOM;
287       }
288     }
289     Node* adr = basic_plus_adr(obj, obj, offset);
290     const TypePtr* adr_type = C->alias_type(field)->adr_type();
291     DecoratorSet decorators = IN_HEAP;
292     decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
293     inc_sp(1);
294     access_store_at(obj, adr, adr_type, val, field_type, bt, decorators);
295     dec_sp(1);
296   }
297 
298   if (is_field) {
299     // Remember we wrote a volatile field.
300     // For not multiple copy atomic cpu (ppc64) a barrier should be issued
301     // in constructors which have such stores. See do_exits() in parse1.cpp.
302     if (is_vol) {
303       set_wrote_volatile(true);
304     }
305     set_wrote_fields(true);
306 
307     // If the field is final, the rules of Java say we are in <init> or <clinit>.
308     // If the field is @Stable, we can be in any method, but we only care about
309     // constructors at this point.
310     //
311     // Note the presence of writes to final/@Stable non-static fields, so that we
312     // can insert a memory barrier later on to keep the writes from floating
313     // out of the constructor.
314     if (field->is_final() || field->is_stable()) {
315       if (field->is_final()) {
316         set_wrote_final(true);
317       }
318       if (field->is_stable()) {
319         set_wrote_stable(true);
320       }
321       if (AllocateNode::Ideal_allocation(obj) != nullptr) {
322         // Preserve allocation ptr to create precedent edge to it in membar
323         // generated on exit from constructor.
324         set_alloc_with_final_or_stable(obj);
325       }
326     }
327   }
328 }
329 
330 void Parse::set_inline_type_field(Node* obj, ciField* field, Node* val) {
331   assert(_method->is_object_constructor(), "inline type is initialized outside of constructor");
332   assert(obj->as_InlineType()->is_larval(), "must be larval");
333   assert(!_gvn.type(obj)->maybe_null(), "should never be null");
334 
335   // Re-execute if buffering in below code triggers deoptimization.
336   PreserveReexecuteState preexecs(this);
337   jvms()->set_should_reexecute(true);
338   inc_sp(1);
339 
340   if (!val->is_InlineType() && field->type()->is_inlinetype()) {
341     // Scalarize inline type field value
342     val = InlineTypeNode::make_from_oop(this, val, field->type()->as_inline_klass());
343   } else if (val->is_InlineType() && !field->is_flat()) {
344     // Field value needs to be allocated because it can be merged with a non-inline type.
345     val = val->as_InlineType()->buffer(this);
346   }
347 
348   // Clone the inline type node and set the new field value
349   InlineTypeNode* new_vt = obj->as_InlineType()->clone_if_required(&_gvn, _map);
350   new_vt->set_field_value_by_offset(field->offset_in_bytes(), val);
351   new_vt = new_vt->adjust_scalarization_depth(this);
352 
353   // If the inline type is buffered and the caller might use the buffer, update it.
354   if (new_vt->is_allocated(&gvn()) && (!_caller->has_method() || C->inlining_incrementally() || _caller->method()->is_object_constructor())) {
355     new_vt->store(this, new_vt->get_oop(), new_vt->get_oop(), new_vt->bottom_type()->inline_klass(), 0, field->offset_in_bytes());
356 
357     // Preserve allocation ptr to create precedent edge to it in membar
358     // generated on exit from constructor.
359     AllocateNode* alloc = AllocateNode::Ideal_allocation(new_vt->get_oop());
360     if (alloc != nullptr) {
361       set_alloc_with_final_or_stable(new_vt->get_oop());
362     }
363     set_wrote_final(true);
364   }
365 
366   replace_in_map(obj, _gvn.transform(new_vt));
367   return;
368 }
369 
370 //=============================================================================
371 
372 void Parse::do_newarray() {
373   bool will_link;
374   ciKlass* klass = iter().get_klass(will_link);
375 
376   // Uncommon Trap when class that array contains is not loaded
377   // we need the loaded class for the rest of graph; do not
378   // initialize the container class (see Java spec)!!!
379   assert(will_link, "newarray: typeflow responsibility");
380 
381   ciArrayKlass* array_klass = ciArrayKlass::make(klass);
382 
383   // Check that array_klass object is loaded
384   if (!array_klass->is_loaded()) {
385     // Generate uncommon_trap for unloaded array_class
386     uncommon_trap(Deoptimization::Reason_unloaded,
387                   Deoptimization::Action_reinterpret,
388                   array_klass);
389     return;
390   } else if (array_klass->element_klass() != nullptr &&
391              array_klass->element_klass()->is_inlinetype() &&
392              !array_klass->element_klass()->as_inline_klass()->is_initialized()) {
393     uncommon_trap(Deoptimization::Reason_uninitialized,
394                   Deoptimization::Action_reinterpret,
395                   nullptr);
396     return;
397   }
398 
399   kill_dead_locals();
400 
401   const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass, Type::trust_interfaces);
402   Node* count_val = pop();
403   Node* obj = new_array(makecon(array_klass_type), count_val, 1);
404   push(obj);
405 }
406 
407 
408 void Parse::do_newarray(BasicType elem_type) {
409   kill_dead_locals();
410 
411   Node*   count_val = pop();
412   const TypeKlassPtr* array_klass = TypeKlassPtr::make(ciTypeArrayKlass::make(elem_type));
413   Node*   obj = new_array(makecon(array_klass), count_val, 1);
414   // Push resultant oop onto stack
415   push(obj);
416 }
417 
418 // Expand simple expressions like new int[3][5] and new Object[2][nonConLen].
419 // Also handle the degenerate 1-dimensional case of anewarray.
420 Node* Parse::expand_multianewarray(ciArrayKlass* array_klass, Node* *lengths, int ndimensions, int nargs) {
421   Node* length = lengths[0];
422   assert(length != nullptr, "");
423   Node* array = new_array(makecon(TypeKlassPtr::make(array_klass, Type::trust_interfaces)), length, nargs);
424   if (ndimensions > 1) {
425     jint length_con = find_int_con(length, -1);
426     guarantee(length_con >= 0, "non-constant multianewarray");
427     ciArrayKlass* array_klass_1 = array_klass->as_obj_array_klass()->element_klass()->as_array_klass();
428     const TypePtr* adr_type = TypeAryPtr::OOPS;
429     const TypeOopPtr*    elemtype = _gvn.type(array)->is_aryptr()->elem()->make_oopptr();
430     const intptr_t header   = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
431     for (jint i = 0; i < length_con; i++) {
432       Node*    elem   = expand_multianewarray(array_klass_1, &lengths[1], ndimensions-1, nargs);
433       intptr_t offset = header + ((intptr_t)i << LogBytesPerHeapOop);
434       Node*    eaddr  = basic_plus_adr(array, offset);
435       access_store_at(array, eaddr, adr_type, elem, elemtype, T_OBJECT, IN_HEAP | IS_ARRAY);
436     }
437   }
438   return array;
439 }
440 
441 void Parse::do_multianewarray() {
442   int ndimensions = iter().get_dimensions();
443 
444   // the m-dimensional array
445   bool will_link;
446   ciArrayKlass* array_klass = iter().get_klass(will_link)->as_array_klass();
447   assert(will_link, "multianewarray: typeflow responsibility");
448 
449   // Note:  Array classes are always initialized; no is_initialized check.
450 
451   kill_dead_locals();
452 
453   // get the lengths from the stack (first dimension is on top)
454   Node** length = NEW_RESOURCE_ARRAY(Node*, ndimensions + 1);
455   length[ndimensions] = nullptr;  // terminating null for make_runtime_call
456   int j;
457   ciKlass* elem_klass = array_klass;
458   for (j = ndimensions-1; j >= 0; j--) {
459     length[j] = pop();
460     elem_klass = elem_klass->as_array_klass()->element_klass();
461   }
462   if (elem_klass != nullptr && elem_klass->is_inlinetype() && !elem_klass->as_inline_klass()->is_initialized()) {
463     inc_sp(ndimensions);
464     uncommon_trap(Deoptimization::Reason_uninitialized,
465                   Deoptimization::Action_reinterpret,
466                   nullptr);
467     return;
468   }
469 
470   // The original expression was of this form: new T[length0][length1]...
471   // It is often the case that the lengths are small (except the last).
472   // If that happens, use the fast 1-d creator a constant number of times.
473   const int expand_limit = MIN2((int)MultiArrayExpandLimit, 100);
474   int64_t expand_count = 1;        // count of allocations in the expansion
475   int64_t expand_fanout = 1;       // running total fanout
476   for (j = 0; j < ndimensions-1; j++) {
477     int dim_con = find_int_con(length[j], -1);
478     // To prevent overflow, we use 64-bit values.  Alternatively,
479     // we could clamp dim_con like so:
480     // dim_con = MIN2(dim_con, expand_limit);
481     expand_fanout *= dim_con;
482     expand_count  += expand_fanout; // count the level-J sub-arrays
483     if (dim_con <= 0
484         || dim_con > expand_limit
485         || expand_count > expand_limit) {
486       expand_count = 0;
487       break;
488     }
489   }
490 
491   // Can use multianewarray instead of [a]newarray if only one dimension,
492   // or if all non-final dimensions are small constants.
493   if (ndimensions == 1 || (1 <= expand_count && expand_count <= expand_limit)) {
494     Node* obj = nullptr;
495     // Set the original stack and the reexecute bit for the interpreter
496     // to reexecute the multianewarray bytecode if deoptimization happens.
497     // Do it unconditionally even for one dimension multianewarray.
498     // Note: the reexecute bit will be set in GraphKit::add_safepoint_edges()
499     // when AllocateArray node for newarray is created.
500     { PreserveReexecuteState preexecs(this);
501       inc_sp(ndimensions);
502       // Pass 0 as nargs since uncommon trap code does not need to restore stack.
503       obj = expand_multianewarray(array_klass, &length[0], ndimensions, 0);
504     } //original reexecute and sp are set back here
505     push(obj);
506     return;
507   }
508 
509   address fun = nullptr;
510   switch (ndimensions) {
511   case 1: ShouldNotReachHere(); break;
512   case 2: fun = OptoRuntime::multianewarray2_Java(); break;
513   case 3: fun = OptoRuntime::multianewarray3_Java(); break;
514   case 4: fun = OptoRuntime::multianewarray4_Java(); break;
515   case 5: fun = OptoRuntime::multianewarray5_Java(); break;
516   };
517   Node* c = nullptr;
518 
519   if (fun != nullptr) {
520     c = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
521                           OptoRuntime::multianewarray_Type(ndimensions),
522                           fun, nullptr, TypeRawPtr::BOTTOM,
523                           makecon(TypeKlassPtr::make(array_klass, Type::trust_interfaces)),
524                           length[0], length[1], length[2],
525                           (ndimensions > 2) ? length[3] : nullptr,
526                           (ndimensions > 3) ? length[4] : nullptr);
527   } else {
528     // Create a java array for dimension sizes
529     Node* dims = nullptr;
530     { PreserveReexecuteState preexecs(this);
531       inc_sp(ndimensions);
532       Node* dims_array_klass = makecon(TypeKlassPtr::make(ciArrayKlass::make(ciType::make(T_INT))));
533       dims = new_array(dims_array_klass, intcon(ndimensions), 0);
534 
535       // Fill-in it with values
536       for (j = 0; j < ndimensions; j++) {
537         Node *dims_elem = array_element_address(dims, intcon(j), T_INT);
538         store_to_memory(control(), dims_elem, length[j], T_INT, MemNode::unordered);
539       }
540     }
541 
542     c = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
543                           OptoRuntime::multianewarrayN_Type(),
544                           OptoRuntime::multianewarrayN_Java(), nullptr, TypeRawPtr::BOTTOM,
545                           makecon(TypeKlassPtr::make(array_klass, Type::trust_interfaces)),
546                           dims);
547   }
548   make_slow_call_ex(c, env()->Throwable_klass(), false);
549 
550   Node* res = _gvn.transform(new ProjNode(c, TypeFunc::Parms));
551 
552   const Type* type = TypeOopPtr::make_from_klass_raw(array_klass, Type::trust_interfaces);
553 
554   // Improve the type:  We know it's not null, exact, and of a given length.
555   type = type->is_ptr()->cast_to_ptr_type(TypePtr::NotNull);
556   type = type->is_aryptr()->cast_to_exactness(true);
557 
558   const TypeInt* ltype = _gvn.find_int_type(length[0]);
559   if (ltype != nullptr)
560     type = type->is_aryptr()->cast_to_size(ltype);
561 
562     // We cannot sharpen the nested sub-arrays, since the top level is mutable.
563 
564   Node* cast = _gvn.transform( new CheckCastPPNode(control(), res, type) );
565   push(cast);
566 
567   // Possible improvements:
568   // - Make a fast path for small multi-arrays.  (W/ implicit init. loops.)
569   // - Issue CastII against length[*] values, to TypeInt::POS.
570 }