< prev index next >

src/hotspot/share/ci/ciTypeFlow.cpp

Print this page




 256 // the program.
 257 
 258 // ------------------------------------------------------------------
 259 // ciTypeFlow::StateVector::type_meet
 260 //
 261 // Meet two types.
 262 //
 263 // The semi-lattice of types use by this analysis are modeled on those
 264 // of the verifier.  The lattice is as follows:
 265 //
 266 //        top_type() >= all non-extremal types >= bottom_type
 267 //                             and
 268 //   Every primitive type is comparable only with itself.  The meet of
 269 //   reference types is determined by their kind: instance class,
 270 //   interface, or array class.  The meet of two types of the same
 271 //   kind is their least common ancestor.  The meet of two types of
 272 //   different kinds is always java.lang.Object.
 273 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
 274   assert(t1 != t2, "checked in caller");
 275 






 276   if (t1->equals(top_type())) {
 277     return t2;
 278   } else if (t2->equals(top_type())) {
 279     return t1;
 280   } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
 281     // Special case null_type.  null_type meet any reference type T
 282     // is T.  null_type meet null_type is null_type.
 283     if (t1->equals(null_type())) {
 284       if (!t2->is_primitive_type() || t2->equals(null_type())) {
 285         return t2;
 286       }
 287     } else if (t2->equals(null_type())) {
 288       if (!t1->is_primitive_type()) {
 289         return t1;
 290       }
 291     }
 292 
 293     // At least one of the two types is a non-top primitive type.
 294     // The other type is not equal to it.  Fall to bottom.
 295     return bottom_type();
 296   }
 297 
 298   // Unwrap the types after gathering nullness information
 299   bool never_null1 = t1->is_never_null();
 300   bool never_null2 = t2->is_never_null();
 301   t1 = t1->unwrap();
 302   t2 = t2->unwrap();
 303 
 304   // Both types are non-top non-primitive types.  That is,
 305   // both types are either instanceKlasses or arrayKlasses.
 306   ciKlass* object_klass = analyzer->env()->Object_klass();
 307   ciKlass* k1 = t1->as_klass();
 308   ciKlass* k2 = t2->as_klass();
 309   if (k1->equals(object_klass) || k2->equals(object_klass)) {
 310     return object_klass;
 311   } else if (!k1->is_loaded() || !k2->is_loaded()) {
 312     // Unloaded classes fall to java.lang.Object at a merge.
 313     return object_klass;
 314   } else if (k1->is_interface() != k2->is_interface()) {
 315     // When an interface meets a non-interface, we get Object;
 316     // This is what the verifier does.
 317     return object_klass;
 318   } else if (k1->is_array_klass() || k2->is_array_klass()) {
 319     // When an array meets a non-array, we get Object.
 320     // When objArray meets typeArray, we also get Object.
 321     // And when typeArray meets different typeArray, we again get Object.
 322     // But when objArray meets objArray, we look carefully at element types.
 323     if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {


 611     } else {
 612       push_object(element_klass);
 613     }
 614   }
 615 }
 616 
 617 
 618 // ------------------------------------------------------------------
 619 // ciTypeFlow::StateVector::do_checkcast
 620 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
 621   bool will_link;
 622   ciKlass* klass = str->get_klass(will_link);
 623   if (!will_link) {
 624     // VM's interpreter will not load 'klass' if object is NULL.
 625     // Type flow after this block may still be needed in two situations:
 626     // 1) C2 uses do_null_assert() and continues compilation for later blocks
 627     // 2) C2 does an OSR compile in a later block (see bug 4778368).
 628     pop_object();
 629     do_null_assert(klass);
 630   } else {
 631     pop_object();
 632     if (str->is_klass_never_null()) {
 633       // Casting to a Q-Type contains a NULL check
 634       assert(klass->is_valuetype(), "must be a value type");
 635       push(outer()->mark_as_never_null(klass));
 636     } else {
 637       push_object(klass);
 638     }
 639   }
 640 }
 641 
 642 // ------------------------------------------------------------------
 643 // ciTypeFlow::StateVector::do_getfield
 644 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
 645   // could add assert here for type of object.
 646   pop_object();
 647   do_getstatic(str);
 648 }
 649 
 650 // ------------------------------------------------------------------
 651 // ciTypeFlow::StateVector::do_getstatic
 652 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
 653   bool will_link;
 654   ciField* field = str->get_field(will_link);




 256 // the program.
 257 
 258 // ------------------------------------------------------------------
 259 // ciTypeFlow::StateVector::type_meet
 260 //
 261 // Meet two types.
 262 //
 263 // The semi-lattice of types use by this analysis are modeled on those
 264 // of the verifier.  The lattice is as follows:
 265 //
 266 //        top_type() >= all non-extremal types >= bottom_type
 267 //                             and
 268 //   Every primitive type is comparable only with itself.  The meet of
 269 //   reference types is determined by their kind: instance class,
 270 //   interface, or array class.  The meet of two types of the same
 271 //   kind is their least common ancestor.  The meet of two types of
 272 //   different kinds is always java.lang.Object.
 273 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
 274   assert(t1 != t2, "checked in caller");
 275 
 276   // Unwrap the types after gathering nullness information
 277   bool never_null1 = t1->is_never_null();
 278   bool never_null2 = t2->is_never_null();
 279   t1 = t1->unwrap();
 280   t2 = t2->unwrap();
 281 
 282   if (t1->equals(top_type())) {
 283     return t2;
 284   } else if (t2->equals(top_type())) {
 285     return t1;
 286   } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
 287     // Special case null_type.  null_type meet any reference type T
 288     // is T.  null_type meet null_type is null_type.
 289     if (t1->equals(null_type())) {
 290       if (!t2->is_primitive_type() || t2->equals(null_type())) {
 291         return t2;
 292       }
 293     } else if (t2->equals(null_type())) {
 294       if (!t1->is_primitive_type()) {
 295         return t1;
 296       }
 297     }
 298 
 299     // At least one of the two types is a non-top primitive type.
 300     // The other type is not equal to it.  Fall to bottom.
 301     return bottom_type();
 302   }
 303 






 304   // Both types are non-top non-primitive types.  That is,
 305   // both types are either instanceKlasses or arrayKlasses.
 306   ciKlass* object_klass = analyzer->env()->Object_klass();
 307   ciKlass* k1 = t1->as_klass();
 308   ciKlass* k2 = t2->as_klass();
 309   if (k1->equals(object_klass) || k2->equals(object_klass)) {
 310     return object_klass;
 311   } else if (!k1->is_loaded() || !k2->is_loaded()) {
 312     // Unloaded classes fall to java.lang.Object at a merge.
 313     return object_klass;
 314   } else if (k1->is_interface() != k2->is_interface()) {
 315     // When an interface meets a non-interface, we get Object;
 316     // This is what the verifier does.
 317     return object_klass;
 318   } else if (k1->is_array_klass() || k2->is_array_klass()) {
 319     // When an array meets a non-array, we get Object.
 320     // When objArray meets typeArray, we also get Object.
 321     // And when typeArray meets different typeArray, we again get Object.
 322     // But when objArray meets objArray, we look carefully at element types.
 323     if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {


 611     } else {
 612       push_object(element_klass);
 613     }
 614   }
 615 }
 616 
 617 
 618 // ------------------------------------------------------------------
 619 // ciTypeFlow::StateVector::do_checkcast
 620 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
 621   bool will_link;
 622   ciKlass* klass = str->get_klass(will_link);
 623   if (!will_link) {
 624     // VM's interpreter will not load 'klass' if object is NULL.
 625     // Type flow after this block may still be needed in two situations:
 626     // 1) C2 uses do_null_assert() and continues compilation for later blocks
 627     // 2) C2 does an OSR compile in a later block (see bug 4778368).
 628     pop_object();
 629     do_null_assert(klass);
 630   } else {
 631     ciType* type = pop_value();
 632     if (klass->is_valuetype() && (str->is_klass_never_null() || type->is_never_null())) {
 633       // Casting to a Q-Type contains a NULL check

 634       push(outer()->mark_as_never_null(klass));
 635     } else {
 636       push_object(klass);
 637     }
 638   }
 639 }
 640 
 641 // ------------------------------------------------------------------
 642 // ciTypeFlow::StateVector::do_getfield
 643 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
 644   // could add assert here for type of object.
 645   pop_object();
 646   do_getstatic(str);
 647 }
 648 
 649 // ------------------------------------------------------------------
 650 // ciTypeFlow::StateVector::do_getstatic
 651 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
 652   bool will_link;
 653   ciField* field = str->get_field(will_link);


< prev index next >