< prev index next >

src/hotspot/share/opto/library_call.cpp

Print this page




3350   // Pull both arguments off the stack.
3351   Node* args[2];                // two java.lang.Class mirrors: superc, subc
3352   args[0] = argument(0);
3353   args[1] = argument(1);
3354   Node* klasses[2];             // corresponding Klasses: superk, subk
3355   klasses[0] = klasses[1] = top();
3356 
3357   enum {
3358     // A full decision tree on {superc is prim, subc is prim}:
3359     _prim_0_path = 1,           // {P,N} => false
3360                                 // {P,P} & superc!=subc => false
3361     _prim_same_path,            // {P,P} & superc==subc => true
3362     _prim_1_path,               // {N,P} => false
3363     _ref_subtype_path,          // {N,N} & subtype check wins => true
3364     _both_ref_path,             // {N,N} & subtype check loses => false
3365     PATH_LIMIT
3366   };
3367 
3368   RegionNode* region = new RegionNode(PATH_LIMIT);
3369   Node*       phi    = new PhiNode(region, TypeInt::BOOL);

3370   record_for_igvn(region);

3371 
3372   const TypePtr* adr_type = TypeRawPtr::BOTTOM;   // memory type of loads
3373   const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
3374   int class_klass_offset = java_lang_Class::klass_offset_in_bytes();
3375 
3376   // First null-check both mirrors and load each mirror's klass metaobject.
3377   int which_arg;
3378   for (which_arg = 0; which_arg <= 1; which_arg++) {
3379     Node* arg = args[which_arg];
3380     arg = null_check(arg);
3381     if (stopped())  break;
3382     args[which_arg] = arg;
3383 
3384     Node* p = basic_plus_adr(arg, class_klass_offset);
3385     Node* kls = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, adr_type, kls_type);
3386     klasses[which_arg] = _gvn.transform(kls);
3387   }
3388 
3389   // Having loaded both klasses, test each for null.
3390   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);


3413   set_control(region->in(_prim_0_path)); // go back to first null check
3414   if (!stopped()) {
3415     // Since superc is primitive, make a guard for the superc==subc case.
3416     Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
3417     Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
3418     generate_guard(bol_eq, region, PROB_FAIR);
3419     if (region->req() == PATH_LIMIT+1) {
3420       // A guard was added.  If the added guard is taken, superc==subc.
3421       region->swap_edges(PATH_LIMIT, _prim_same_path);
3422       region->del_req(PATH_LIMIT);
3423     }
3424     region->set_req(_prim_0_path, control()); // Not equal after all.
3425   }
3426 
3427   // these are the only paths that produce 'true':
3428   phi->set_req(_prim_same_path,   intcon(1));
3429   phi->set_req(_ref_subtype_path, intcon(1));
3430 
3431   // pull together the cases:
3432   assert(region->req() == PATH_LIMIT, "sane region");

3433   for (uint i = 1; i < region->req(); i++) {
3434     Node* ctl = region->in(i);
3435     if (ctl == NULL || ctl == top()) {
3436       region->set_req(i, top());
3437       phi   ->set_req(i, top());
3438     } else if (phi->in(i) == NULL) {
3439       phi->set_req(i, intcon(0)); // all other paths produce 'false'




3440     }
3441   }
3442 
3443   set_control(_gvn.transform(region));
3444   set_result(_gvn.transform(phi));

3445   return true;
3446 }
3447 
3448 //---------------------generate_array_guard_common------------------------
3449 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
3450                                                   bool obj_array, bool not_array) {
3451 
3452   if (stopped()) {
3453     return NULL;
3454   }
3455 
3456   // If obj_array/non_array==false/false:
3457   // Branch around if the given klass is in fact an array (either obj or prim).
3458   // If obj_array/non_array==false/true:
3459   // Branch around if the given klass is not an array klass of any kind.
3460   // If obj_array/non_array==true/true:
3461   // Branch around if the kls is not an oop array (kls is int[], String, etc.)
3462   // If obj_array/non_array==true/false:
3463   // Branch around if the kls is an oop array (Object[] or subtype)
3464   //


3709           set_control(not_subtype_ctrl);
3710           uncommon_trap(Deoptimization::Reason_class_check,
3711                         Deoptimization::Action_make_not_entrant);
3712           assert(stopped(), "Should be stopped");
3713         }
3714         validated = true;
3715       }
3716 
3717       if (!stopped()) {
3718         newcopy = new_array(klass_node, length, 0);  // no arguments to push
3719 
3720         ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, false,
3721                                                 load_object_klass(original), klass_node);
3722         if (!is_copyOfRange) {
3723           ac->set_copyof(validated);
3724         } else {
3725           ac->set_copyofrange(validated);
3726         }
3727         Node* n = _gvn.transform(ac);
3728         if (n == ac) {



3729           ac->connect_outputs(this);
3730         } else {
3731           assert(validated, "shouldn't transform if all arguments not validated");
3732           set_all_memory(n);
3733         }
3734       }
3735     }
3736   } // original reexecute is set back here
3737 
3738   C->set_has_split_ifs(true); // Has chance for split-if optimization
3739   if (!stopped()) {
3740     set_result(newcopy);
3741   }
3742   return true;
3743 }
3744 
3745 
3746 //----------------------generate_virtual_guard---------------------------
3747 // Helper for hashCode and clone.  Peeks inside the vtable to avoid a call.
3748 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,


4309       PreserveJVMState pjvms(this);
4310       set_control(array_ctl);
4311       Node* obj_length = load_array_length(obj);
4312       Node* obj_size  = NULL;
4313       Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size);  // no arguments to push
4314 
4315       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
4316       if (bs->array_copy_requires_gc_barriers(T_OBJECT)) {
4317         // If it is an oop array, it requires very special treatment,
4318         // because gc barriers are required when accessing the array.
4319         Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL);
4320         if (is_obja != NULL) {
4321           PreserveJVMState pjvms2(this);
4322           set_control(is_obja);
4323           // Generate a direct call to the right arraycopy function(s).
4324           Node* alloc = tightly_coupled_allocation(alloc_obj, NULL);
4325           ArrayCopyNode* ac = ArrayCopyNode::make(this, true, obj, intcon(0), alloc_obj, intcon(0), obj_length, alloc != NULL, false);
4326           ac->set_cloneoop();
4327           Node* n = _gvn.transform(ac);
4328           assert(n == ac, "cannot disappear");



4329           ac->connect_outputs(this);
4330 
4331           result_reg->init_req(_objArray_path, control());
4332           result_val->init_req(_objArray_path, alloc_obj);
4333           result_i_o ->set_req(_objArray_path, i_o());
4334           result_mem ->set_req(_objArray_path, reset_memory());
4335         }
4336       }
4337       // Otherwise, there are no barriers to worry about.
4338       // (We can dispense with card marks if we know the allocation
4339       //  comes out of eden (TLAB)...  In fact, ReduceInitialCardMarks
4340       //  causes the non-eden paths to take compensating steps to
4341       //  simulate a fresh allocation, so that no further
4342       //  card marks are required in compiled code to initialize
4343       //  the object.)
4344 
4345       if (!stopped()) {
4346         copy_to_clone(obj, alloc_obj, obj_size, true);
4347 
4348         // Present the results of the copy.


4789     src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
4790   }
4791 
4792   arraycopy_move_allocation_here(alloc, dest, saved_jvms, saved_reexecute_sp, new_idx);
4793 
4794   if (stopped()) {
4795     return true;
4796   }
4797 
4798   ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != NULL, negative_length_guard_generated,
4799                                           // Create LoadRange and LoadKlass nodes for use during macro expansion here
4800                                           // so the compiler has a chance to eliminate them: during macro expansion,
4801                                           // we have to set their control (CastPP nodes are eliminated).
4802                                           load_object_klass(src), load_object_klass(dest),
4803                                           load_array_length(src), load_array_length(dest));
4804 
4805   ac->set_arraycopy(validated);
4806 
4807   Node* n = _gvn.transform(ac);
4808   if (n == ac) {



4809     ac->connect_outputs(this);
4810   } else {
4811     assert(validated, "shouldn't transform if all arguments not validated");
4812     set_all_memory(n);
4813   }
4814   clear_upper_avx();
4815 
4816 
4817   return true;
4818 }
4819 
4820 
4821 // Helper function which determines if an arraycopy immediately follows
4822 // an allocation, with no intervening tests or other escapes for the object.
4823 AllocateArrayNode*
4824 LibraryCallKit::tightly_coupled_allocation(Node* ptr,
4825                                            RegionNode* slow_region) {
4826   if (stopped())             return NULL;  // no fast path
4827   if (C->AliasLevel() == 0)  return NULL;  // no MergeMems around
4828 


4991     // 'y_start' points to y array + scaled ylen
4992 
4993     // Allocate the result array
4994     Node* zlen = _gvn.transform(new AddINode(xlen, ylen));
4995     ciKlass* klass = ciTypeArrayKlass::make(T_INT);
4996     Node* klass_node = makecon(TypeKlassPtr::make(klass));
4997 
4998     IdealKit ideal(this);
4999 
5000 #define __ ideal.
5001      Node* one = __ ConI(1);
5002      Node* zero = __ ConI(0);
5003      IdealVariable need_alloc(ideal), z_alloc(ideal);  __ declarations_done();
5004      __ set(need_alloc, zero);
5005      __ set(z_alloc, z);
5006      __ if_then(z, BoolTest::eq, null()); {
5007        __ increment (need_alloc, one);
5008      } __ else_(); {
5009        // Update graphKit memory and control from IdealKit.
5010        sync_kit(ideal);
5011        Node *cast = new CastPPNode(z, TypePtr::NOTNULL);
5012        cast->init_req(0, control());
5013        _gvn.set_type(cast, cast->bottom_type());
5014        C->record_for_igvn(cast);
5015 
5016        Node* zlen_arg = load_array_length(cast);





5017        // Update IdealKit memory and control from graphKit.
5018        __ sync_kit(this);
5019        __ if_then(zlen_arg, BoolTest::lt, zlen); {
5020          __ increment (need_alloc, one);
5021        } __ end_if();
5022      } __ end_if();
5023 
5024      __ if_then(__ value(need_alloc), BoolTest::ne, zero); {
5025        // Update graphKit memory and control from IdealKit.
5026        sync_kit(ideal);
5027        Node * narr = new_array(klass_node, zlen, 1);
5028        // Update IdealKit memory and control from graphKit.
5029        __ sync_kit(this);
5030        __ set(z_alloc, narr);
5031      } __ end_if();
5032 
5033      sync_kit(ideal);
5034      z = __ value(z_alloc);
5035      // Can't use TypeAryPtr::INTS which uses Bottom offset.
5036      _gvn.set_type(z, TypeOopPtr::make_from_klass(klass));




3350   // Pull both arguments off the stack.
3351   Node* args[2];                // two java.lang.Class mirrors: superc, subc
3352   args[0] = argument(0);
3353   args[1] = argument(1);
3354   Node* klasses[2];             // corresponding Klasses: superk, subk
3355   klasses[0] = klasses[1] = top();
3356 
3357   enum {
3358     // A full decision tree on {superc is prim, subc is prim}:
3359     _prim_0_path = 1,           // {P,N} => false
3360                                 // {P,P} & superc!=subc => false
3361     _prim_same_path,            // {P,P} & superc==subc => true
3362     _prim_1_path,               // {N,P} => false
3363     _ref_subtype_path,          // {N,N} & subtype check wins => true
3364     _both_ref_path,             // {N,N} & subtype check loses => false
3365     PATH_LIMIT
3366   };
3367 
3368   RegionNode* region = new RegionNode(PATH_LIMIT);
3369   Node*       phi    = new PhiNode(region, TypeInt::BOOL);
3370   Node*       mem_phi= new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
3371   record_for_igvn(region);
3372   Node* init_mem = map()->memory();
3373 
3374   const TypePtr* adr_type = TypeRawPtr::BOTTOM;   // memory type of loads
3375   const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
3376   int class_klass_offset = java_lang_Class::klass_offset_in_bytes();
3377 
3378   // First null-check both mirrors and load each mirror's klass metaobject.
3379   int which_arg;
3380   for (which_arg = 0; which_arg <= 1; which_arg++) {
3381     Node* arg = args[which_arg];
3382     arg = null_check(arg);
3383     if (stopped())  break;
3384     args[which_arg] = arg;
3385 
3386     Node* p = basic_plus_adr(arg, class_klass_offset);
3387     Node* kls = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, adr_type, kls_type);
3388     klasses[which_arg] = _gvn.transform(kls);
3389   }
3390 
3391   // Having loaded both klasses, test each for null.
3392   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);


3415   set_control(region->in(_prim_0_path)); // go back to first null check
3416   if (!stopped()) {
3417     // Since superc is primitive, make a guard for the superc==subc case.
3418     Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
3419     Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
3420     generate_guard(bol_eq, region, PROB_FAIR);
3421     if (region->req() == PATH_LIMIT+1) {
3422       // A guard was added.  If the added guard is taken, superc==subc.
3423       region->swap_edges(PATH_LIMIT, _prim_same_path);
3424       region->del_req(PATH_LIMIT);
3425     }
3426     region->set_req(_prim_0_path, control()); // Not equal after all.
3427   }
3428 
3429   // these are the only paths that produce 'true':
3430   phi->set_req(_prim_same_path,   intcon(1));
3431   phi->set_req(_ref_subtype_path, intcon(1));
3432 
3433   // pull together the cases:
3434   assert(region->req() == PATH_LIMIT, "sane region");
3435   Node* cur_mem = reset_memory();
3436   for (uint i = 1; i < region->req(); i++) {
3437     Node* ctl = region->in(i);
3438     if (ctl == NULL || ctl == top()) {
3439       region->set_req(i, top());
3440       phi   ->set_req(i, top());
3441       mem_phi->set_req(i, top());
3442     } else {
3443       if (phi->in(i) == NULL) {
3444         phi->set_req(i, intcon(0)); // all other paths produce 'false'
3445       }
3446       mem_phi->set_req(i, (i == _prim_0_path || i == _prim_same_path) ?  cur_mem : init_mem);
3447     }
3448   }
3449 
3450   set_control(_gvn.transform(region));
3451   set_result(_gvn.transform(phi));
3452   set_all_memory(_gvn.transform(mem_phi));
3453   return true;
3454 }
3455 
3456 //---------------------generate_array_guard_common------------------------
3457 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
3458                                                   bool obj_array, bool not_array) {
3459 
3460   if (stopped()) {
3461     return NULL;
3462   }
3463 
3464   // If obj_array/non_array==false/false:
3465   // Branch around if the given klass is in fact an array (either obj or prim).
3466   // If obj_array/non_array==false/true:
3467   // Branch around if the given klass is not an array klass of any kind.
3468   // If obj_array/non_array==true/true:
3469   // Branch around if the kls is not an oop array (kls is int[], String, etc.)
3470   // If obj_array/non_array==true/false:
3471   // Branch around if the kls is an oop array (Object[] or subtype)
3472   //


3717           set_control(not_subtype_ctrl);
3718           uncommon_trap(Deoptimization::Reason_class_check,
3719                         Deoptimization::Action_make_not_entrant);
3720           assert(stopped(), "Should be stopped");
3721         }
3722         validated = true;
3723       }
3724 
3725       if (!stopped()) {
3726         newcopy = new_array(klass_node, length, 0);  // no arguments to push
3727 
3728         ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, false,
3729                                                 load_object_klass(original), klass_node);
3730         if (!is_copyOfRange) {
3731           ac->set_copyof(validated);
3732         } else {
3733           ac->set_copyofrange(validated);
3734         }
3735         Node* n = _gvn.transform(ac);
3736         if (n == ac) {
3737           if (UseShenandoahGC) {
3738             ac->_adr_type = TypePtr::BOTTOM;
3739           }
3740           ac->connect_outputs(this);
3741         } else {
3742           assert(validated, "shouldn't transform if all arguments not validated");
3743           set_all_memory(n);
3744         }
3745       }
3746     }
3747   } // original reexecute is set back here
3748 
3749   C->set_has_split_ifs(true); // Has chance for split-if optimization
3750   if (!stopped()) {
3751     set_result(newcopy);
3752   }
3753   return true;
3754 }
3755 
3756 
3757 //----------------------generate_virtual_guard---------------------------
3758 // Helper for hashCode and clone.  Peeks inside the vtable to avoid a call.
3759 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,


4320       PreserveJVMState pjvms(this);
4321       set_control(array_ctl);
4322       Node* obj_length = load_array_length(obj);
4323       Node* obj_size  = NULL;
4324       Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size);  // no arguments to push
4325 
4326       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
4327       if (bs->array_copy_requires_gc_barriers(T_OBJECT)) {
4328         // If it is an oop array, it requires very special treatment,
4329         // because gc barriers are required when accessing the array.
4330         Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL);
4331         if (is_obja != NULL) {
4332           PreserveJVMState pjvms2(this);
4333           set_control(is_obja);
4334           // Generate a direct call to the right arraycopy function(s).
4335           Node* alloc = tightly_coupled_allocation(alloc_obj, NULL);
4336           ArrayCopyNode* ac = ArrayCopyNode::make(this, true, obj, intcon(0), alloc_obj, intcon(0), obj_length, alloc != NULL, false);
4337           ac->set_cloneoop();
4338           Node* n = _gvn.transform(ac);
4339           assert(n == ac, "cannot disappear");
4340           if (UseShenandoahGC) {
4341             ac->_adr_type = TypePtr::BOTTOM;
4342           }
4343           ac->connect_outputs(this);
4344 
4345           result_reg->init_req(_objArray_path, control());
4346           result_val->init_req(_objArray_path, alloc_obj);
4347           result_i_o ->set_req(_objArray_path, i_o());
4348           result_mem ->set_req(_objArray_path, reset_memory());
4349         }
4350       }
4351       // Otherwise, there are no barriers to worry about.
4352       // (We can dispense with card marks if we know the allocation
4353       //  comes out of eden (TLAB)...  In fact, ReduceInitialCardMarks
4354       //  causes the non-eden paths to take compensating steps to
4355       //  simulate a fresh allocation, so that no further
4356       //  card marks are required in compiled code to initialize
4357       //  the object.)
4358 
4359       if (!stopped()) {
4360         copy_to_clone(obj, alloc_obj, obj_size, true);
4361 
4362         // Present the results of the copy.


4803     src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
4804   }
4805 
4806   arraycopy_move_allocation_here(alloc, dest, saved_jvms, saved_reexecute_sp, new_idx);
4807 
4808   if (stopped()) {
4809     return true;
4810   }
4811 
4812   ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != NULL, negative_length_guard_generated,
4813                                           // Create LoadRange and LoadKlass nodes for use during macro expansion here
4814                                           // so the compiler has a chance to eliminate them: during macro expansion,
4815                                           // we have to set their control (CastPP nodes are eliminated).
4816                                           load_object_klass(src), load_object_klass(dest),
4817                                           load_array_length(src), load_array_length(dest));
4818 
4819   ac->set_arraycopy(validated);
4820 
4821   Node* n = _gvn.transform(ac);
4822   if (n == ac) {
4823     if (UseShenandoahGC) {
4824       ac->_adr_type = TypePtr::BOTTOM;
4825     }
4826     ac->connect_outputs(this);
4827   } else {
4828     assert(validated, "shouldn't transform if all arguments not validated");
4829     set_all_memory(n);
4830   }
4831   clear_upper_avx();
4832 
4833 
4834   return true;
4835 }
4836 
4837 
4838 // Helper function which determines if an arraycopy immediately follows
4839 // an allocation, with no intervening tests or other escapes for the object.
4840 AllocateArrayNode*
4841 LibraryCallKit::tightly_coupled_allocation(Node* ptr,
4842                                            RegionNode* slow_region) {
4843   if (stopped())             return NULL;  // no fast path
4844   if (C->AliasLevel() == 0)  return NULL;  // no MergeMems around
4845 


5008     // 'y_start' points to y array + scaled ylen
5009 
5010     // Allocate the result array
5011     Node* zlen = _gvn.transform(new AddINode(xlen, ylen));
5012     ciKlass* klass = ciTypeArrayKlass::make(T_INT);
5013     Node* klass_node = makecon(TypeKlassPtr::make(klass));
5014 
5015     IdealKit ideal(this);
5016 
5017 #define __ ideal.
5018      Node* one = __ ConI(1);
5019      Node* zero = __ ConI(0);
5020      IdealVariable need_alloc(ideal), z_alloc(ideal);  __ declarations_done();
5021      __ set(need_alloc, zero);
5022      __ set(z_alloc, z);
5023      __ if_then(z, BoolTest::eq, null()); {
5024        __ increment (need_alloc, one);
5025      } __ else_(); {
5026        // Update graphKit memory and control from IdealKit.
5027        sync_kit(ideal);
5028        Node* zlen_arg = NULL;
5029        if (UseShenandoahGC) {
5030          Node *cast = new CastPPNode(z, TypePtr::NOTNULL);
5031          cast->init_req(0, control());
5032          _gvn.set_type(cast, cast->bottom_type());
5033          C->record_for_igvn(cast);
5034 
5035          zlen_arg = load_array_length(cast);
5036        } else {
5037          zlen_arg = load_array_length(z);
5038        }
5039        // Update IdealKit memory and control from graphKit.
5040        __ sync_kit(this);
5041        __ if_then(zlen_arg, BoolTest::lt, zlen); {
5042          __ increment (need_alloc, one);
5043        } __ end_if();
5044      } __ end_if();
5045 
5046      __ if_then(__ value(need_alloc), BoolTest::ne, zero); {
5047        // Update graphKit memory and control from IdealKit.
5048        sync_kit(ideal);
5049        Node * narr = new_array(klass_node, zlen, 1);
5050        // Update IdealKit memory and control from graphKit.
5051        __ sync_kit(this);
5052        __ set(z_alloc, narr);
5053      } __ end_if();
5054 
5055      sync_kit(ideal);
5056      z = __ value(z_alloc);
5057      // Can't use TypeAryPtr::INTS which uses Bottom offset.
5058      _gvn.set_type(z, TypeOopPtr::make_from_klass(klass));


< prev index next >