@@ -4262,7 +4262,7 @@ bool LibraryCallKit::inline_native_subtype_check() {
4262
4262
4263
4263
// ---------------------generate_array_guard_common------------------------
4264
4264
Node* LibraryCallKit::generate_array_guard_common (Node* kls, RegionNode* region,
4265
- bool obj_array, bool not_array) {
4265
+ bool obj_array, bool not_array, Node** obj ) {
4266
4266
4267
4267
if (stopped ()) {
4268
4268
return nullptr ;
@@ -4304,7 +4304,14 @@ Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
4304
4304
// invert the test if we are looking for a non-array
4305
4305
if (not_array) btest = BoolTest (btest).negate ();
4306
4306
Node* bol = _gvn.transform (new BoolNode (cmp, btest));
4307
- return generate_fair_guard (bol, region);
4307
+ Node* ctrl = generate_fair_guard (bol, region);
4308
+ Node* is_array_ctrl = not_array ? control () : ctrl;
4309
+ if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top ()) {
4310
+ // Keep track of the fact that 'obj' is an array to prevent
4311
+ // array specific accesses from floating above the guard.
4312
+ *obj = _gvn.transform (new CastPPNode (is_array_ctrl, *obj, TypeAryPtr::BOTTOM));
4313
+ }
4314
+ return ctrl;
4308
4315
}
4309
4316
4310
4317
@@ -4399,7 +4406,7 @@ bool LibraryCallKit::inline_native_getLength() {
4399
4406
if (stopped ()) return true ;
4400
4407
4401
4408
// Deoptimize if it is a non-array.
4402
- Node* non_array = generate_non_array_guard (load_object_klass (array), nullptr );
4409
+ Node* non_array = generate_non_array_guard (load_object_klass (array), nullptr , &array );
4403
4410
4404
4411
if (non_array != nullptr ) {
4405
4412
PreserveJVMState pjvms (this );
@@ -5259,12 +5266,13 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
5259
5266
record_for_igvn (result_reg);
5260
5267
5261
5268
Node* obj_klass = load_object_klass (obj);
5262
- Node* array_ctl = generate_array_guard (obj_klass, (RegionNode*)nullptr );
5269
+ Node* array_obj = obj;
5270
+ Node* array_ctl = generate_array_guard (obj_klass, (RegionNode*)nullptr , &array_obj);
5263
5271
if (array_ctl != nullptr ) {
5264
5272
// It's an array.
5265
5273
PreserveJVMState pjvms (this );
5266
5274
set_control (array_ctl);
5267
- Node* obj_length = load_array_length (obj );
5275
+ Node* obj_length = load_array_length (array_obj );
5268
5276
Node* array_size = nullptr ; // Size of the array without object alignment padding.
5269
5277
Node* alloc_obj = new_array (obj_klass, obj_length, 0 , &array_size, /* deoptimize_on_exception=*/ true );
5270
5278
@@ -5278,7 +5286,7 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
5278
5286
set_control (is_obja);
5279
5287
// Generate a direct call to the right arraycopy function(s).
5280
5288
// Clones are always tightly coupled.
5281
- ArrayCopyNode* ac = ArrayCopyNode::make (this , true , obj , intcon (0 ), alloc_obj, intcon (0 ), obj_length, true , false );
5289
+ ArrayCopyNode* ac = ArrayCopyNode::make (this , true , array_obj , intcon (0 ), alloc_obj, intcon (0 ), obj_length, true , false );
5282
5290
ac->set_clone_oop_array ();
5283
5291
Node* n = _gvn.transform (ac);
5284
5292
assert (n == ac, " cannot disappear" );
@@ -5299,7 +5307,7 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
5299
5307
// the object.)
5300
5308
5301
5309
if (!stopped ()) {
5302
- copy_to_clone (obj , alloc_obj, array_size, true );
5310
+ copy_to_clone (array_obj , alloc_obj, array_size, true );
5303
5311
5304
5312
// Present the results of the copy.
5305
5313
result_reg->init_req (_array_path, control ());
@@ -5920,8 +5928,8 @@ bool LibraryCallKit::inline_arraycopy() {
5920
5928
record_for_igvn (slow_region);
5921
5929
5922
5930
// (1) src and dest are arrays.
5923
- generate_non_array_guard (load_object_klass (src), slow_region);
5924
- generate_non_array_guard (load_object_klass (dest), slow_region);
5931
+ generate_non_array_guard (load_object_klass (src), slow_region, &src );
5932
+ generate_non_array_guard (load_object_klass (dest), slow_region, &dest );
5925
5933
5926
5934
// (2) src and dest arrays must have elements of the same BasicType
5927
5935
// done at macro expansion or at Ideal transformation time
@@ -8537,7 +8545,7 @@ bool LibraryCallKit::inline_getObjectSize() {
8537
8545
PhiNode* result_val = new PhiNode (result_reg, TypeLong::LONG);
8538
8546
record_for_igvn (result_reg);
8539
8547
8540
- Node* array_ctl = generate_array_guard (klass_node, nullptr );
8548
+ Node* array_ctl = generate_array_guard (klass_node, nullptr , &obj );
8541
8549
if (array_ctl != nullptr ) {
8542
8550
// Array case: size is round(header + element_size*arraylength).
8543
8551
// Since arraylength is different for every array instance, we have to
0 commit comments