< 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.


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



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


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





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


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


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


< prev index next >