< prev index next >

src/hotspot/share/opto/library_call.cpp

Print this page

4669     // and skip a call to MH.linkTo*/invokeBasic adapter, additional information
4670     // about the method being invoked should be attached to the call site to
4671     // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C).
4672     slow_call->set_override_symbolic_info(true);
4673   }
4674   set_arguments_for_java_call(slow_call);
4675   set_edges_for_java_call(slow_call);
4676   return slow_call;
4677 }
4678 
4679 
4680 /**
4681  * Build special case code for calls to hashCode on an object. This call may
4682  * be virtual (invokevirtual) or bound (invokespecial). For each case we generate
4683  * slightly different code.
4684  */
4685 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
4686   assert(is_static == callee()->is_static(), "correct intrinsic selection");
4687   assert(!(is_virtual && is_static), "either virtual, special, or static");
4688 
4689   enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT };
4690 
4691   RegionNode* result_reg = new RegionNode(PATH_LIMIT);
4692   PhiNode*    result_val = new PhiNode(result_reg, TypeInt::INT);
4693   PhiNode*    result_io  = new PhiNode(result_reg, Type::ABIO);
4694   PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
4695   Node* obj = nullptr;
4696   if (!is_static) {
4697     // Check for hashing null object
4698     obj = null_check_receiver();
4699     if (stopped())  return true;        // unconditionally null
4700     result_reg->init_req(_null_path, top());
4701     result_val->init_req(_null_path, top());
4702   } else {
4703     // Do a null check, and return zero if null.
4704     // System.identityHashCode(null) == 0
4705     obj = argument(0);
4706     Node* null_ctl = top();
4707     obj = null_check_oop(obj, &null_ctl);
4708     result_reg->init_req(_null_path, null_ctl);
4709     result_val->init_req(_null_path, _gvn.intcon(0));

4717     return true;
4718   }
4719 
4720   // We only go to the fast case code if we pass a number of guards.  The
4721   // paths which do not pass are accumulated in the slow_region.
4722   RegionNode* slow_region = new RegionNode(1);
4723   record_for_igvn(slow_region);
4724 
4725   // If this is a virtual call, we generate a funny guard.  We pull out
4726   // the vtable entry corresponding to hashCode() from the target object.
4727   // If the target method which we are calling happens to be the native
4728   // Object hashCode() method, we pass the guard.  We do not need this
4729   // guard for non-virtual calls -- the caller is known to be the native
4730   // Object hashCode().
4731   if (is_virtual) {
4732     // After null check, get the object's klass.
4733     Node* obj_klass = load_object_klass(obj);
4734     generate_virtual_guard(obj_klass, slow_region);
4735   }
4736 
4737   // Get the header out of the object, use LoadMarkNode when available
4738   Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
4739   // The control of the load must be null. Otherwise, the load can move before
4740   // the null check after castPP removal.
4741   Node* no_ctrl = nullptr;
4742   Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);




























4743 
4744   if (!UseObjectMonitorTable) {
4745     // Test the header to see if it is safe to read w.r.t. locking.
4746     Node *lock_mask      = _gvn.MakeConX(markWord::lock_mask_in_place);
4747     Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask));
4748     if (LockingMode == LM_LIGHTWEIGHT) {
4749       Node *monitor_val   = _gvn.MakeConX(markWord::monitor_value);
4750       Node *chk_monitor   = _gvn.transform(new CmpXNode(lmasked_header, monitor_val));
4751       Node *test_monitor  = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq));











4752 
4753       generate_slow_guard(test_monitor, slow_region);
4754     } else {
4755       Node *unlocked_val      = _gvn.MakeConX(markWord::unlocked_value);
4756       Node *chk_unlocked      = _gvn.transform(new CmpXNode(lmasked_header, unlocked_val));
4757       Node *test_not_unlocked = _gvn.transform(new BoolNode(chk_unlocked, BoolTest::ne));

















4758 
4759       generate_slow_guard(test_not_unlocked, slow_region);













































































4760     }
4761   }
4762 
4763   // Get the hash value and check to see that it has been properly assigned.
4764   // We depend on hash_mask being at most 32 bits and avoid the use of
4765   // hash_mask_in_place because it could be larger than 32 bits in a 64-bit
4766   // vm: see markWord.hpp.
4767   Node *hash_mask      = _gvn.intcon(markWord::hash_mask);
4768   Node *hash_shift     = _gvn.intcon(markWord::hash_shift);
4769   Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift));
4770   // This hack lets the hash bits live anywhere in the mark object now, as long
4771   // as the shift drops the relevant bits into the low 32 bits.  Note that
4772   // Java spec says that HashCode is an int so there's no point in capturing
4773   // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
4774   hshifted_header      = ConvX2I(hshifted_header);
4775   Node *hash_val       = _gvn.transform(new AndINode(hshifted_header, hash_mask));
4776 
4777   Node *no_hash_val    = _gvn.intcon(markWord::no_hash);
4778   Node *chk_assigned   = _gvn.transform(new CmpINode( hash_val, no_hash_val));
4779   Node *test_assigned  = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq));
4780 
4781   generate_slow_guard(test_assigned, slow_region);









4782 
4783   Node* init_mem = reset_memory();
4784   // fill in the rest of the null path:
4785   result_io ->init_req(_null_path, i_o());
4786   result_mem->init_req(_null_path, init_mem);
4787 
4788   result_val->init_req(_fast_path, hash_val);
4789   result_reg->init_req(_fast_path, control());
4790   result_io ->init_req(_fast_path, i_o());
4791   result_mem->init_req(_fast_path, init_mem);
4792 





4793   // Generate code for the slow case.  We make a call to hashCode().

4794   set_control(_gvn.transform(slow_region));
4795   if (!stopped()) {
4796     // No need for PreserveJVMState, because we're using up the present state.
4797     set_all_memory(init_mem);
4798     vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode;
4799     CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static, false);
4800     Node* slow_result = set_results_for_java_call(slow_call);
4801     // this->control() comes from set_results_for_java_call
4802     result_reg->init_req(_slow_path, control());
4803     result_val->init_req(_slow_path, slow_result);
4804     result_io  ->set_req(_slow_path, i_o());
4805     result_mem ->set_req(_slow_path, reset_memory());
4806   }
4807 
4808   // Return the combined state.
4809   set_i_o(        _gvn.transform(result_io)  );
4810   set_all_memory( _gvn.transform(result_mem));
4811 
4812   set_result(result_reg, result_val);
4813   return true;

4669     // and skip a call to MH.linkTo*/invokeBasic adapter, additional information
4670     // about the method being invoked should be attached to the call site to
4671     // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C).
4672     slow_call->set_override_symbolic_info(true);
4673   }
4674   set_arguments_for_java_call(slow_call);
4675   set_edges_for_java_call(slow_call);
4676   return slow_call;
4677 }
4678 
4679 
4680 /**
4681  * Build special case code for calls to hashCode on an object. This call may
4682  * be virtual (invokevirtual) or bound (invokespecial). For each case we generate
4683  * slightly different code.
4684  */
4685 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
4686   assert(is_static == callee()->is_static(), "correct intrinsic selection");
4687   assert(!(is_virtual && is_static), "either virtual, special, or static");
4688 
4689   enum { _slow_path = 1, _null_path, _fast_path, _fast_path2, PATH_LIMIT };
4690 
4691   RegionNode* result_reg = new RegionNode(PATH_LIMIT);
4692   PhiNode*    result_val = new PhiNode(result_reg, TypeInt::INT);
4693   PhiNode*    result_io  = new PhiNode(result_reg, Type::ABIO);
4694   PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
4695   Node* obj = nullptr;
4696   if (!is_static) {
4697     // Check for hashing null object
4698     obj = null_check_receiver();
4699     if (stopped())  return true;        // unconditionally null
4700     result_reg->init_req(_null_path, top());
4701     result_val->init_req(_null_path, top());
4702   } else {
4703     // Do a null check, and return zero if null.
4704     // System.identityHashCode(null) == 0
4705     obj = argument(0);
4706     Node* null_ctl = top();
4707     obj = null_check_oop(obj, &null_ctl);
4708     result_reg->init_req(_null_path, null_ctl);
4709     result_val->init_req(_null_path, _gvn.intcon(0));

4717     return true;
4718   }
4719 
4720   // We only go to the fast case code if we pass a number of guards.  The
4721   // paths which do not pass are accumulated in the slow_region.
4722   RegionNode* slow_region = new RegionNode(1);
4723   record_for_igvn(slow_region);
4724 
4725   // If this is a virtual call, we generate a funny guard.  We pull out
4726   // the vtable entry corresponding to hashCode() from the target object.
4727   // If the target method which we are calling happens to be the native
4728   // Object hashCode() method, we pass the guard.  We do not need this
4729   // guard for non-virtual calls -- the caller is known to be the native
4730   // Object hashCode().
4731   if (is_virtual) {
4732     // After null check, get the object's klass.
4733     Node* obj_klass = load_object_klass(obj);
4734     generate_virtual_guard(obj_klass, slow_region);
4735   }
4736 
4737   if (UseCompactObjectHeaders) {
4738     // Get the header out of the object.
4739     Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
4740     // The control of the load must be null. Otherwise, the load can move before
4741     // the null check after castPP removal.
4742     Node* no_ctrl = nullptr;
4743     Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
4744 
4745     // Test the header to see if the object is in hashed or copied state.
4746     Node* hashctrl_mask  = _gvn.MakeConX(markWord::hashctrl_mask_in_place);
4747     Node* masked_header  = _gvn.transform(new AndXNode(header, hashctrl_mask));
4748 
4749     // Take slow-path when the object has not been hashed.
4750     Node* not_hashed_val = _gvn.MakeConX(0);
4751     Node* chk_hashed     = _gvn.transform(new CmpXNode(masked_header, not_hashed_val));
4752     Node* test_hashed    = _gvn.transform(new BoolNode(chk_hashed, BoolTest::eq));
4753 
4754     generate_slow_guard(test_hashed, slow_region);
4755 
4756     // Test whether the object is hashed or hashed&copied.
4757     Node* hashed_copied = _gvn.MakeConX(markWord::hashctrl_expanded_mask_in_place | markWord::hashctrl_hashed_mask_in_place);
4758     Node* chk_copied    = _gvn.transform(new CmpXNode(masked_header, hashed_copied));
4759     // If true, then object has been hashed&copied, otherwise it's only hashed.
4760     Node* test_copied   = _gvn.transform(new BoolNode(chk_copied, BoolTest::eq));
4761     IfNode* if_copied   = create_and_map_if(control(), test_copied, PROB_FAIR, COUNT_UNKNOWN);
4762     Node* if_true = _gvn.transform(new IfTrueNode(if_copied));
4763     Node* if_false = _gvn.transform(new IfFalseNode(if_copied));
4764 
4765     // Hashed&Copied path: read hash-code out of the object.
4766     set_control(if_true);
4767     // result_val->del_req(_fast_path2);
4768     // result_reg->del_req(_fast_path2);
4769     // result_io->del_req(_fast_path2);
4770     // result_mem->del_req(_fast_path2);
4771 
4772     Node* obj_klass = load_object_klass(obj);
4773     Node* hash_addr;
4774     const TypeKlassPtr* klass_t = _gvn.type(obj_klass)->isa_klassptr();
4775     bool load_offset_runtime = true;
4776 
4777     if (klass_t != nullptr) {
4778       if (klass_t->klass_is_exact()  && klass_t->isa_instklassptr()) {
4779         ciInstanceKlass* ciKlass = reinterpret_cast<ciInstanceKlass*>(klass_t->is_instklassptr()->exact_klass());
4780         if (!ciKlass->is_mirror_instance_klass() && !ciKlass->is_reference_instance_klass()) {
4781           // We know the InstanceKlass, load hash_offset from there at compile-time.
4782           int hash_offset = ciKlass->hash_offset_in_bytes();
4783           hash_addr = basic_plus_adr(obj, hash_offset);
4784           Node* loaded_hash = make_load(control(), hash_addr, TypeInt::INT, T_INT, MemNode::unordered);
4785           result_val->init_req(_fast_path2, loaded_hash);
4786           result_reg->init_req(_fast_path2, control());
4787           load_offset_runtime = false;
4788         }
4789       }
4790     }
4791 
4792     //tty->print_cr("Load hash-offset at runtime: %s", BOOL_TO_STR(load_offset_runtime));
4793 
4794     if (load_offset_runtime) {
4795       // We don't know if it is an array or an exact type, figure it out at run-time.
4796       // If not an ordinary instance, then we need to take slow-path.
4797       Node* kind_addr = basic_plus_adr(obj_klass, Klass::kind_offset_in_bytes());
4798       Node* kind = make_load(control(), kind_addr, TypeInt::INT, T_INT, MemNode::unordered);
4799       Node* instance_val = _gvn.intcon(Klass::InstanceKlassKind);
4800       Node* chk_inst     = _gvn.transform(new CmpINode(kind, instance_val));
4801       Node* test_inst    = _gvn.transform(new BoolNode(chk_inst, BoolTest::ne));
4802       generate_slow_guard(test_inst, slow_region);
4803 
4804       // Otherwise it's an instance and we can read the hash_offset from the InstanceKlass.
4805       Node* hash_offset_addr = basic_plus_adr(obj_klass, InstanceKlass::hash_offset_offset_in_bytes());
4806       Node* hash_offset = make_load(control(), hash_offset_addr, TypeInt::INT, T_INT, MemNode::unordered);
4807       // hash_offset->dump();
4808       Node* hash_addr = basic_plus_adr(obj, ConvI2X(hash_offset));
4809       Compile::current()->set_has_unsafe_access(true);
4810       Node* loaded_hash = make_load(control(), hash_addr, TypeInt::INT, T_INT, MemNode::unordered);
4811       result_val->init_req(_fast_path2, loaded_hash);
4812       result_reg->init_req(_fast_path2, control());
4813     }
4814 
4815     // Hashed-only path: recompute hash-code from object address.
4816     set_control(if_false);
4817     // Our constants.
4818     Node* M = _gvn.intcon(0x337954D5);
4819     Node* A = _gvn.intcon(0xAAAAAAAA);
4820     // Split object address into lo and hi 32 bits.
4821     Node* obj_addr = _gvn.transform(new CastP2XNode(nullptr, obj));
4822     Node* x = _gvn.transform(new ConvL2INode(obj_addr));
4823     Node* upper_addr = _gvn.transform(new URShiftLNode(obj_addr, _gvn.intcon(32)));
4824     Node* y = _gvn.transform(new ConvL2INode(upper_addr));
4825 
4826     Node* H0 = _gvn.transform(new XorINode(x, y));
4827     Node* L0 = _gvn.transform(new XorINode(x, A));
4828 
4829     // Full multiplication of two 32 bit values L0 and M into a hi/lo result in two 32 bit values V0 and U0.
4830     Node* L0_64 = _gvn.transform(new ConvI2LNode(L0));
4831     L0_64 = _gvn.transform(new AndLNode(L0_64, _gvn.longcon(0xFFFFFFFF)));
4832     Node* M_64 = _gvn.transform(new ConvI2LNode(M));
4833     // M_64 = _gvn.transform(new AndLNode(M_64, _gvn.longcon(0xFFFFFFFF)));
4834     Node* prod64 = _gvn.transform(new MulLNode(L0_64, M_64));
4835     Node* V0 = _gvn.transform(new ConvL2INode(prod64));
4836     Node* prod_upper = _gvn.transform(new URShiftLNode(prod64, _gvn.intcon(32)));
4837     Node* U0 = _gvn.transform(new ConvL2INode(prod_upper));
4838 
4839     Node* Q0 = _gvn.transform(new MulINode(H0, M));
4840     Node* L1 = _gvn.transform(new XorINode(Q0, U0));
4841 
4842     // Full multiplication of two 32 bit values L1 and M into a hi/lo result in two 32 bit values V1 and U1.
4843     Node* L1_64 = _gvn.transform(new ConvI2LNode(L1));
4844     L1_64 = _gvn.transform(new AndLNode(L1_64, _gvn.longcon(0xFFFFFFFF)));
4845     prod64 = _gvn.transform(new MulLNode(L1_64, M_64));
4846     Node* V1 = _gvn.transform(new ConvL2INode(prod64));
4847     prod_upper = _gvn.transform(new URShiftLNode(prod64, _gvn.intcon(32)));
4848     Node* U1 = _gvn.transform(new ConvL2INode(prod_upper));
4849 
4850     Node* P1 = _gvn.transform(new XorINode(V0, M));
4851 
4852     // Right rotate P1 by distance L1.
4853     Node* distance = _gvn.transform(new AndINode(L1, _gvn.intcon(32 - 1)));
4854     Node* inverse_distance = _gvn.transform(new SubINode(_gvn.intcon(32), distance));
4855     Node* ror_part1 = _gvn.transform(new URShiftINode(P1, distance));
4856     Node* ror_part2 = _gvn.transform(new LShiftINode(P1, inverse_distance));
4857     Node* Q1 = _gvn.transform(new OrINode(ror_part1, ror_part2));
4858 
4859     Node* L2 = _gvn.transform(new XorINode(Q1, U1));
4860     Node* hash = _gvn.transform(new XorINode(V1, L2));
4861     Node* hash_truncated = _gvn.transform(new AndINode(hash, _gvn.intcon(markWord::hash_mask)));
4862 
4863     // TODO: We could generate a fast case here under the following conditions:
4864     // - The hashctrl is set to hash_is_copied (see markWord::hash_is_copied())
4865     // - The type of the object is known
4866     // Then we can load the identity hashcode from the int field at Klass::hash_offset_in_bytes() of the object.
4867     result_val->init_req(_fast_path, hash_truncated);
4868   } else {
4869     // Get the header out of the object, use LoadMarkNode when available
4870     Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
4871     // The control of the load must be null. Otherwise, the load can move before
4872     // the null check after castPP removal.
4873     Node* no_ctrl = nullptr;
4874     Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
4875 
4876     if (!UseObjectMonitorTable) {
4877       // Test the header to see if it is safe to read w.r.t. locking.
4878       Node *lock_mask      = _gvn.MakeConX(markWord::lock_mask_in_place);
4879       Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask));
4880       if (LockingMode == LM_LIGHTWEIGHT) {
4881         Node *monitor_val   = _gvn.MakeConX(markWord::monitor_value);
4882         Node *chk_monitor   = _gvn.transform(new CmpXNode(lmasked_header, monitor_val));
4883         Node *test_monitor  = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq));
4884 
4885         generate_slow_guard(test_monitor, slow_region);
4886       } else {
4887         Node *unlocked_val      = _gvn.MakeConX(markWord::unlocked_value);
4888         Node *chk_unlocked      = _gvn.transform(new CmpXNode(lmasked_header, unlocked_val));
4889         Node *test_not_unlocked = _gvn.transform(new BoolNode(chk_unlocked, BoolTest::ne));
4890 
4891         generate_slow_guard(test_not_unlocked, slow_region);
4892       }
4893     }

4894 
4895     // Get the hash value and check to see that it has been properly assigned.
4896     // We depend on hash_mask being at most 32 bits and avoid the use of
4897     // hash_mask_in_place because it could be larger than 32 bits in a 64-bit
4898     // vm: see markWord.hpp.
4899     Node *hash_mask      = _gvn.intcon(markWord::hash_mask);
4900     Node *hash_shift     = _gvn.intcon(markWord::hash_shift);
4901     Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift));
4902     // This hack lets the hash bits live anywhere in the mark object now, as long
4903     // as the shift drops the relevant bits into the low 32 bits.  Note that
4904     // Java spec says that HashCode is an int so there's no point in capturing
4905     // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
4906     hshifted_header      = ConvX2I(hshifted_header);
4907     Node *hash_val       = _gvn.transform(new AndINode(hshifted_header, hash_mask));
4908 
4909     Node *no_hash_val    = _gvn.intcon(markWord::no_hash);
4910     Node *chk_assigned   = _gvn.transform(new CmpINode( hash_val, no_hash_val));
4911     Node *test_assigned  = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq));
4912 
4913     generate_slow_guard(test_assigned, slow_region);
4914 
4915     result_val->init_req(_fast_path, hash_val);
4916 
4917     // _fast_path2 is not used here.
4918     result_val->del_req(_fast_path2);
4919     result_reg->del_req(_fast_path2);
4920     result_io->del_req(_fast_path2);
4921     result_mem->del_req(_fast_path2);
4922   }
4923 
4924   Node* init_mem = reset_memory();
4925   // fill in the rest of the null path:
4926   result_io ->init_req(_null_path, i_o());
4927   result_mem->init_req(_null_path, init_mem);
4928 

4929   result_reg->init_req(_fast_path, control());
4930   result_io ->init_req(_fast_path, i_o());
4931   result_mem->init_req(_fast_path, init_mem);
4932 
4933   if (UseCompactObjectHeaders) {
4934     result_io->init_req(_fast_path2, i_o());
4935     result_mem->init_req(_fast_path2, init_mem);
4936   }
4937 
4938   // Generate code for the slow case.  We make a call to hashCode().
4939   assert(slow_region != nullptr, "must have slow_region");
4940   set_control(_gvn.transform(slow_region));
4941   if (!stopped()) {
4942     // No need for PreserveJVMState, because we're using up the present state.
4943     set_all_memory(init_mem);
4944     vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode;
4945     CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static, false);
4946     Node* slow_result = set_results_for_java_call(slow_call);
4947     // this->control() comes from set_results_for_java_call
4948     result_reg->init_req(_slow_path, control());
4949     result_val->init_req(_slow_path, slow_result);
4950     result_io  ->set_req(_slow_path, i_o());
4951     result_mem ->set_req(_slow_path, reset_memory());
4952   }
4953 
4954   // Return the combined state.
4955   set_i_o(        _gvn.transform(result_io)  );
4956   set_all_memory( _gvn.transform(result_mem));
4957 
4958   set_result(result_reg, result_val);
4959   return true;
< prev index next >