src/share/vm/opto/library_call.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/library_call.cpp

Print this page
rev 5462 : 8024069: replace_in_map() should operate on parent maps
Summary: type information gets lost because replace_in_map() doesn't update parent maps
Reviewed-by:
rev 5464 : 8024070: C2 needs some form of type speculation
Summary: record unused type profile information with type system, propagate and use it.
Reviewed-by:
rev 5465 : imported patch speculative-cleanup


3336 
3337   // The mirror will never be null of Reflection.getClassAccessFlags, however
3338   // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
3339   // if it is. See bug 4774291.
3340 
3341   // For Reflection.getClassAccessFlags(), the null check occurs in
3342   // the wrong place; see inline_unsafe_access(), above, for a similar
3343   // situation.
3344   mirror = null_check(mirror);
3345   // If mirror or obj is dead, only null-path is taken.
3346   if (stopped())  return true;
3347 
3348   if (expect_prim)  never_see_null = false;  // expect nulls (meaning prims)
3349 
3350   // Now load the mirror's klass metaobject, and null-check it.
3351   // Side-effects region with the control path if the klass is null.
3352   Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path);
3353   // If kls is null, we have a primitive mirror.
3354   phi->init_req(_prim_path, prim_return_value);
3355   if (stopped()) { set_result(region, phi); return true; }

3356 
3357   Node* p;  // handy temp
3358   Node* null_ctl;
3359 
3360   // Now that we have the non-null klass, we can perform the real query.
3361   // For constant classes, the query will constant-fold in LoadNode::Value.
3362   Node* query_value = top();
3363   switch (id) {
3364   case vmIntrinsics::_isInstance:
3365     // nothing is an instance of a primitive type
3366     query_value = gen_instanceof(obj, kls);
3367     break;
3368 
3369   case vmIntrinsics::_getModifiers:
3370     p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset()));
3371     query_value = make_load(NULL, p, TypeInt::INT, T_INT);
3372     break;
3373 
3374   case vmIntrinsics::_isInterface:
3375     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3376     if (generate_interface_guard(kls, region) != NULL)
3377       // A guard was added.  If the guard is taken, it was an interface.
3378       phi->add_req(intcon(1));
3379     // If we fall through, it's a plain class.
3380     query_value = intcon(0);
3381     break;
3382 
3383   case vmIntrinsics::_isArray:
3384     // (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
3385     if (generate_array_guard(kls, region) != NULL)
3386       // A guard was added.  If the guard is taken, it was an array.


4536 // public static native void java.lang.System.arraycopy(Object src,  int  srcPos,
4537 //                                                      Object dest, int destPos,
4538 //                                                      int length);
4539 bool LibraryCallKit::inline_arraycopy() {
4540   // Get the arguments.
4541   Node* src         = argument(0);  // type: oop
4542   Node* src_offset  = argument(1);  // type: int
4543   Node* dest        = argument(2);  // type: oop
4544   Node* dest_offset = argument(3);  // type: int
4545   Node* length      = argument(4);  // type: int
4546 
4547   // Compile time checks.  If any of these checks cannot be verified at compile time,
4548   // we do not make a fast path for this call.  Instead, we let the call remain as it
4549   // is.  The checks we choose to mandate at compile time are:
4550   //
4551   // (1) src and dest are arrays.
4552   const Type* src_type  = src->Value(&_gvn);
4553   const Type* dest_type = dest->Value(&_gvn);
4554   const TypeAryPtr* top_src  = src_type->isa_aryptr();
4555   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
4556   if (top_src  == NULL || top_src->klass()  == NULL ||
4557       top_dest == NULL || top_dest->klass() == NULL) {






















































4558     // Conservatively insert a memory barrier on all memory slices.
4559     // Do not let writes into the source float below the arraycopy.
4560     insert_mem_bar(Op_MemBarCPUOrder);
4561 
4562     // Call StubRoutines::generic_arraycopy stub.
4563     generate_arraycopy(TypeRawPtr::BOTTOM, T_CONFLICT,
4564                        src, src_offset, dest, dest_offset, length);
4565 
4566     // Do not let reads from the destination float above the arraycopy.
4567     // Since we cannot type the arrays, we don't know which slices
4568     // might be affected.  We could restrict this barrier only to those
4569     // memory slices which pertain to array elements--but don't bother.
4570     if (!InsertMemBarAfterArraycopy)
4571       // (If InsertMemBarAfterArraycopy, there is already one in place.)
4572       insert_mem_bar(Op_MemBarCPUOrder);
4573     return true;
4574   }
4575 
4576   // (2) src and dest arrays must have elements of the same BasicType
4577   // Figure out the size and type of the elements we will be copying.
4578   BasicType src_elem  =  top_src->klass()->as_array_klass()->element_type()->basic_type();
4579   BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type();
4580   if (src_elem  == T_ARRAY)  src_elem  = T_OBJECT;
4581   if (dest_elem == T_ARRAY)  dest_elem = T_OBJECT;
4582 
4583   if (src_elem != dest_elem || dest_elem == T_VOID) {
4584     // The component types are not the same or are not recognized.  Punt.
4585     // (But, avoid the native method wrapper to JVM_ArrayCopy.)
4586     generate_slow_arraycopy(TypePtr::BOTTOM,
4587                             src, src_offset, dest, dest_offset, length,
4588                             /*dest_uninitialized*/false);
4589     return true;

































4590   }
4591 
4592   //---------------------------------------------------------------------------
4593   // We will make a fast path for this call to arraycopy.
4594 
4595   // We have the following tests left to perform:
4596   //
4597   // (3) src and dest must not be null.
4598   // (4) src_offset must not be negative.
4599   // (5) dest_offset must not be negative.
4600   // (6) length must not be negative.
4601   // (7) src_offset + length must not exceed length of src.
4602   // (8) dest_offset + length must not exceed length of dest.
4603   // (9) each element of an oop array must be assignable
4604 
4605   RegionNode* slow_region = new (C) RegionNode(1);
4606   record_for_igvn(slow_region);
4607 
4608   // (3) operands must not be null
4609   // We currently perform our null checks with the null_check routine.




3336 
3337   // The mirror will never be null of Reflection.getClassAccessFlags, however
3338   // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
3339   // if it is. See bug 4774291.
3340 
3341   // For Reflection.getClassAccessFlags(), the null check occurs in
3342   // the wrong place; see inline_unsafe_access(), above, for a similar
3343   // situation.
3344   mirror = null_check(mirror);
3345   // If mirror or obj is dead, only null-path is taken.
3346   if (stopped())  return true;
3347 
3348   if (expect_prim)  never_see_null = false;  // expect nulls (meaning prims)
3349 
3350   // Now load the mirror's klass metaobject, and null-check it.
3351   // Side-effects region with the control path if the klass is null.
3352   Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path);
3353   // If kls is null, we have a primitive mirror.
3354   phi->init_req(_prim_path, prim_return_value);
3355   if (stopped()) { set_result(region, phi); return true; }
3356   bool safe_for_replace = (region->in(_prim_path) == top());
3357 
3358   Node* p;  // handy temp
3359   Node* null_ctl;
3360 
3361   // Now that we have the non-null klass, we can perform the real query.
3362   // For constant classes, the query will constant-fold in LoadNode::Value.
3363   Node* query_value = top();
3364   switch (id) {
3365   case vmIntrinsics::_isInstance:
3366     // nothing is an instance of a primitive type
3367     query_value = gen_instanceof(obj, kls, safe_for_replace);
3368     break;
3369 
3370   case vmIntrinsics::_getModifiers:
3371     p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset()));
3372     query_value = make_load(NULL, p, TypeInt::INT, T_INT);
3373     break;
3374 
3375   case vmIntrinsics::_isInterface:
3376     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3377     if (generate_interface_guard(kls, region) != NULL)
3378       // A guard was added.  If the guard is taken, it was an interface.
3379       phi->add_req(intcon(1));
3380     // If we fall through, it's a plain class.
3381     query_value = intcon(0);
3382     break;
3383 
3384   case vmIntrinsics::_isArray:
3385     // (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
3386     if (generate_array_guard(kls, region) != NULL)
3387       // A guard was added.  If the guard is taken, it was an array.


4537 // public static native void java.lang.System.arraycopy(Object src,  int  srcPos,
4538 //                                                      Object dest, int destPos,
4539 //                                                      int length);
4540 bool LibraryCallKit::inline_arraycopy() {
4541   // Get the arguments.
4542   Node* src         = argument(0);  // type: oop
4543   Node* src_offset  = argument(1);  // type: int
4544   Node* dest        = argument(2);  // type: oop
4545   Node* dest_offset = argument(3);  // type: int
4546   Node* length      = argument(4);  // type: int
4547 
4548   // Compile time checks.  If any of these checks cannot be verified at compile time,
4549   // we do not make a fast path for this call.  Instead, we let the call remain as it
4550   // is.  The checks we choose to mandate at compile time are:
4551   //
4552   // (1) src and dest are arrays.
4553   const Type* src_type  = src->Value(&_gvn);
4554   const Type* dest_type = dest->Value(&_gvn);
4555   const TypeAryPtr* top_src  = src_type->isa_aryptr();
4556   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
4557 
4558   // Do we have the type of src?
4559   bool has_src = (top_src != NULL && top_src->klass() != NULL);
4560   // Do we have the type of dest?
4561   bool has_dest = (top_dest != NULL && top_dest->klass() != NULL);
4562   // Is the type for src from speculation?
4563   bool src_spec = false;
4564   // Is the type for dest from speculation?
4565   bool dest_spec = false;
4566 
4567   if (!has_src || !has_dest) {
4568     // We don't have sufficient type information, let's see if
4569     // speculative types can help. We need to have types for both src
4570     // and dest so that it pays off.
4571 
4572     // Do we already have or could we have type information for src
4573     bool could_have_src = has_src;
4574     // Do we already have or could we have type information for dest
4575     bool could_have_dest = has_dest;
4576     
4577     ciKlass* src_k = NULL;
4578     if (!has_src) {
4579       src_k = src_type->is_oopptr()->speculative_type();
4580       if (src_k != NULL && src_k->is_array_klass()) {
4581         could_have_src = true;
4582       }
4583     }
4584     
4585     ciKlass* dest_k = NULL;
4586     if (!has_dest) {
4587       dest_k = dest_type->speculative_type();
4588       if (dest_k != NULL && dest_k->is_array_klass()) {
4589         could_have_dest = true;
4590       }
4591     }
4592 
4593     if (could_have_src && could_have_dest) {
4594       // This is going to pay off so emit the required guards
4595       if (!has_src) {
4596         src = maybe_cast_profiled_obj(src, src_k);
4597         src_type  = _gvn.type(src);
4598         top_src  = src_type->isa_aryptr();
4599         has_src = (top_src != NULL && top_src->klass() != NULL);
4600         src_spec = true;
4601       }
4602       if (!has_dest) {
4603         dest = maybe_cast_profiled_obj(dest, dest_k);
4604         dest_type  = _gvn.type(dest);
4605         top_dest  = dest_type->isa_aryptr();
4606         has_dest = (top_dest != NULL && top_dest->klass() != NULL);
4607         dest_spec = true;
4608       }
4609     }
4610   }
4611   
4612   if (!has_src || !has_dest) {
4613     // Conservatively insert a memory barrier on all memory slices.
4614     // Do not let writes into the source float below the arraycopy.
4615     insert_mem_bar(Op_MemBarCPUOrder);
4616 
4617     // Call StubRoutines::generic_arraycopy stub.
4618     generate_arraycopy(TypeRawPtr::BOTTOM, T_CONFLICT,
4619                        src, src_offset, dest, dest_offset, length);
4620 
4621     // Do not let reads from the destination float above the arraycopy.
4622     // Since we cannot type the arrays, we don't know which slices
4623     // might be affected.  We could restrict this barrier only to those
4624     // memory slices which pertain to array elements--but don't bother.
4625     if (!InsertMemBarAfterArraycopy)
4626       // (If InsertMemBarAfterArraycopy, there is already one in place.)
4627       insert_mem_bar(Op_MemBarCPUOrder);
4628     return true;
4629   }
4630 
4631   // (2) src and dest arrays must have elements of the same BasicType
4632   // Figure out the size and type of the elements we will be copying.
4633   BasicType src_elem  =  top_src->klass()->as_array_klass()->element_type()->basic_type();
4634   BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type();
4635   if (src_elem  == T_ARRAY)  src_elem  = T_OBJECT;
4636   if (dest_elem == T_ARRAY)  dest_elem = T_OBJECT;
4637 
4638   if (src_elem != dest_elem || dest_elem == T_VOID) {
4639     // The component types are not the same or are not recognized.  Punt.
4640     // (But, avoid the native method wrapper to JVM_ArrayCopy.)
4641     generate_slow_arraycopy(TypePtr::BOTTOM,
4642                             src, src_offset, dest, dest_offset, length,
4643                             /*dest_uninitialized*/false);
4644     return true;
4645   }
4646 
4647   if (src_elem == T_OBJECT) {
4648     // If both arrays are object arrays then having the exact types
4649     // for both will remove the need for a subtype check at runtime
4650     // before the call and may make it possible to pick a faster copy
4651     // routine (without a subtype check on every element)
4652     // Do we have the exact type of src?
4653     bool could_have_src = src_spec;
4654     // Do we have the exact type of dest?
4655     bool could_have_dest = dest_spec;
4656     ciKlass* src_k = top_src->klass(), *dest_k = top_dest->klass();
4657     if (!src_spec) {
4658       src_k = src_type->speculative_type();
4659       if (src_k != NULL && src_k->is_array_klass()) {
4660           could_have_src = true;
4661       }
4662     }
4663     if (!dest_spec) {
4664       dest_k = dest_type->speculative_type();
4665       if (dest_k != NULL && dest_k->is_array_klass()) {
4666         could_have_dest = true;
4667       }
4668     }
4669     if (could_have_src && could_have_dest) {
4670       // If we can have both exact types, emit the missing guards
4671       if (could_have_src && !src_spec) {
4672         src = maybe_cast_profiled_obj(src, src_k);
4673       }
4674       if (could_have_dest && !dest_spec) {
4675         dest = maybe_cast_profiled_obj(dest, dest_k);
4676       }
4677     }
4678   }
4679 
4680   //---------------------------------------------------------------------------
4681   // We will make a fast path for this call to arraycopy.
4682 
4683   // We have the following tests left to perform:
4684   //
4685   // (3) src and dest must not be null.
4686   // (4) src_offset must not be negative.
4687   // (5) dest_offset must not be negative.
4688   // (6) length must not be negative.
4689   // (7) src_offset + length must not exceed length of src.
4690   // (8) dest_offset + length must not exceed length of dest.
4691   // (9) each element of an oop array must be assignable
4692 
4693   RegionNode* slow_region = new (C) RegionNode(1);
4694   record_for_igvn(slow_region);
4695 
4696   // (3) operands must not be null
4697   // We currently perform our null checks with the null_check routine.


src/share/vm/opto/library_call.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File