@@ -4256,7 +4256,7 @@ bool LibraryCallKit::inline_native_subtype_check() {
4256
4256
4257
4257
// ---------------------generate_array_guard_common------------------------
4258
4258
Node* LibraryCallKit::generate_array_guard_common (Node* kls, RegionNode* region,
4259
- bool obj_array, bool not_array) {
4259
+ bool obj_array, bool not_array, Node** obj ) {
4260
4260
4261
4261
if (stopped ()) {
4262
4262
return nullptr ;
@@ -4298,7 +4298,14 @@ Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
4298
4298
// invert the test if we are looking for a non-array
4299
4299
if (not_array) btest = BoolTest (btest).negate ();
4300
4300
Node* bol = _gvn.transform (new BoolNode (cmp, btest));
4301
- return generate_fair_guard (bol, region);
4301
+ Node* ctrl = generate_fair_guard (bol, region);
4302
+ Node* is_array_ctrl = not_array ? control () : ctrl;
4303
+ if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top ()) {
4304
+ // Keep track of the fact that 'obj' is an array to prevent
4305
+ // array specific accesses from floating above the guard.
4306
+ *obj = _gvn.transform (new CastPPNode (is_array_ctrl, *obj, TypeAryPtr::BOTTOM));
4307
+ }
4308
+ return ctrl;
4302
4309
}
4303
4310
4304
4311
@@ -4393,7 +4400,7 @@ bool LibraryCallKit::inline_native_getLength() {
4393
4400
if (stopped ()) return true ;
4394
4401
4395
4402
// Deoptimize if it is a non-array.
4396
- Node* non_array = generate_non_array_guard (load_object_klass (array), nullptr );
4403
+ Node* non_array = generate_non_array_guard (load_object_klass (array), nullptr , &array );
4397
4404
4398
4405
if (non_array != nullptr ) {
4399
4406
PreserveJVMState pjvms (this );
@@ -5253,12 +5260,13 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
5253
5260
record_for_igvn (result_reg);
5254
5261
5255
5262
Node* obj_klass = load_object_klass (obj);
5256
- Node* array_ctl = generate_array_guard (obj_klass, (RegionNode*)nullptr );
5263
+ Node* array_obj = obj;
5264
+ Node* array_ctl = generate_array_guard (obj_klass, (RegionNode*)nullptr , &array_obj);
5257
5265
if (array_ctl != nullptr ) {
5258
5266
// It's an array.
5259
5267
PreserveJVMState pjvms (this );
5260
5268
set_control (array_ctl);
5261
- Node* obj_length = load_array_length (obj );
5269
+ Node* obj_length = load_array_length (array_obj );
5262
5270
Node* array_size = nullptr ; // Size of the array without object alignment padding.
5263
5271
Node* alloc_obj = new_array (obj_klass, obj_length, 0 , &array_size, /* deoptimize_on_exception=*/ true );
5264
5272
@@ -5272,7 +5280,7 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
5272
5280
set_control (is_obja);
5273
5281
// Generate a direct call to the right arraycopy function(s).
5274
5282
// Clones are always tightly coupled.
5275
- ArrayCopyNode* ac = ArrayCopyNode::make (this , true , obj , intcon (0 ), alloc_obj, intcon (0 ), obj_length, true , false );
5283
+ ArrayCopyNode* ac = ArrayCopyNode::make (this , true , array_obj , intcon (0 ), alloc_obj, intcon (0 ), obj_length, true , false );
5276
5284
ac->set_clone_oop_array ();
5277
5285
Node* n = _gvn.transform (ac);
5278
5286
assert (n == ac, " cannot disappear" );
@@ -5293,7 +5301,7 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
5293
5301
// the object.)
5294
5302
5295
5303
if (!stopped ()) {
5296
- copy_to_clone (obj , alloc_obj, array_size, true );
5304
+ copy_to_clone (array_obj , alloc_obj, array_size, true );
5297
5305
5298
5306
// Present the results of the copy.
5299
5307
result_reg->init_req (_array_path, control ());
@@ -5914,8 +5922,8 @@ bool LibraryCallKit::inline_arraycopy() {
5914
5922
record_for_igvn (slow_region);
5915
5923
5916
5924
// (1) src and dest are arrays.
5917
- generate_non_array_guard (load_object_klass (src), slow_region);
5918
- generate_non_array_guard (load_object_klass (dest), slow_region);
5925
+ generate_non_array_guard (load_object_klass (src), slow_region, &src );
5926
+ generate_non_array_guard (load_object_klass (dest), slow_region, &dest );
5919
5927
5920
5928
// (2) src and dest arrays must have elements of the same BasicType
5921
5929
// done at macro expansion or at Ideal transformation time
@@ -8531,7 +8539,7 @@ bool LibraryCallKit::inline_getObjectSize() {
8531
8539
PhiNode* result_val = new PhiNode (result_reg, TypeLong::LONG);
8532
8540
record_for_igvn (result_reg);
8533
8541
8534
- Node* array_ctl = generate_array_guard (klass_node, nullptr );
8542
+ Node* array_ctl = generate_array_guard (klass_node, nullptr , &obj );
8535
8543
if (array_ctl != nullptr ) {
8536
8544
// Array case: size is round(header + element_size*arraylength).
8537
8545
// Since arraylength is different for every array instance, we have to
0 commit comments