< 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   // 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   } else {







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


 336         }
 337       } else if (k1->is_value_array_klass() || k2->is_value_array_klass()) {
 338         ciKlass* elem1 = k1->as_array_klass()->element_klass();
 339         ciKlass* elem2 = k2->as_array_klass()->element_klass();
 340         ciKlass* elem  = type_meet_internal(elem1, elem2, analyzer)->as_klass();
 341         return ciArrayKlass::make(elem);
 342       } else {
 343         return object_klass;
 344       }
 345     } else {
 346       // Must be two plain old instance klasses.
 347       assert(k1->is_instance_klass(), "previous cases handle non-instances");
 348       assert(k2->is_instance_klass(), "previous cases handle non-instances");
 349       ciType* result = k1->least_common_ancestor(k2);
 350       if (never_null1 && never_null2 && result->is_valuetype()) {
 351         // Both value types are never null, mark the result as never null
 352         result = analyzer->mark_as_never_null(result);
 353       }
 354       return result;
 355     }
 356   }
 357 }
 358 
 359 
 360 // ------------------------------------------------------------------
 361 // ciTypeFlow::StateVector::StateVector
 362 //
 363 // Build a new state vector
 364 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
 365   _outer = analyzer;
 366   _stack_size = -1;
 367   _monitor_count = -1;
 368   // Allocate the _types array
 369   int max_cells = analyzer->max_cells();
 370   _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
 371   for (int i=0; i<max_cells; i++) {
 372     _types[i] = top_type();
 373   }
 374   _trap_bci = -1;
 375   _trap_index = 0;
 376   _def_locals.clear();


 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->get_never_null()) {

 633       assert(klass->is_valuetype(), "must be a value type");
 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;


 756   }
 757 }
 758 
 759 // ------------------------------------------------------------------
 760 // ciTypeFlow::StateVector::do_jsr
 761 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
 762   push(ciReturnAddress::make(str->next_bci()));
 763 }
 764 
 765 // ------------------------------------------------------------------
 766 // ciTypeFlow::StateVector::do_ldc
 767 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
 768   ciConstant con = str->get_constant();
 769   BasicType basic_type = con.basic_type();
 770   if (basic_type == T_ILLEGAL) {
 771     // OutOfMemoryError in the CI while loading constant
 772     push_null();
 773     outer()->record_failure("ldc did not link");
 774     return;
 775   }
 776   if (basic_type == T_OBJECT || basic_type == T_OBJECT || basic_type == T_ARRAY) {
 777     ciObject* obj = con.as_object();
 778     if (obj->is_null_object()) {
 779       push_null();
 780     } else {
 781       assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
 782       ciType* type = obj->klass();
 783       if (type->is_valuetype()) {
 784         type = outer()->mark_as_never_null(type);
 785       }
 786       push(type);
 787     }
 788   } else {
 789     push_translate(ciType::make(basic_type));
 790   }
 791 }
 792 
 793 // ------------------------------------------------------------------
 794 // ciTypeFlow::StateVector::do_multianewarray
 795 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
 796   int dimensions = str->get_dimensions();




 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()) {


 337       }
 338     } else if (k1->is_value_array_klass() || k2->is_value_array_klass()) {
 339       ciKlass* elem1 = k1->as_array_klass()->element_klass();
 340       ciKlass* elem2 = k2->as_array_klass()->element_klass();
 341       ciKlass* elem  = type_meet_internal(elem1, elem2, analyzer)->as_klass();
 342       return ciArrayKlass::make(elem);
 343     } else {
 344       return object_klass;
 345     }
 346   } else {
 347     // Must be two plain old instance klasses.
 348     assert(k1->is_instance_klass(), "previous cases handle non-instances");
 349     assert(k2->is_instance_klass(), "previous cases handle non-instances");
 350     ciType* result = k1->least_common_ancestor(k2);
 351     if (never_null1 && never_null2 && result->is_valuetype()) {
 352       // Both value types are never null, mark the result as never null
 353       result = analyzer->mark_as_never_null(result);
 354     }
 355     return result;
 356   }

 357 }
 358 
 359 
 360 // ------------------------------------------------------------------
 361 // ciTypeFlow::StateVector::StateVector
 362 //
 363 // Build a new state vector
 364 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
 365   _outer = analyzer;
 366   _stack_size = -1;
 367   _monitor_count = -1;
 368   // Allocate the _types array
 369   int max_cells = analyzer->max_cells();
 370   _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
 371   for (int i=0; i<max_cells; i++) {
 372     _types[i] = top_type();
 373   }
 374   _trap_bci = -1;
 375   _trap_index = 0;
 376   _def_locals.clear();


 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->get_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;


 757   }
 758 }
 759 
 760 // ------------------------------------------------------------------
 761 // ciTypeFlow::StateVector::do_jsr
 762 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
 763   push(ciReturnAddress::make(str->next_bci()));
 764 }
 765 
 766 // ------------------------------------------------------------------
 767 // ciTypeFlow::StateVector::do_ldc
 768 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
 769   ciConstant con = str->get_constant();
 770   BasicType basic_type = con.basic_type();
 771   if (basic_type == T_ILLEGAL) {
 772     // OutOfMemoryError in the CI while loading constant
 773     push_null();
 774     outer()->record_failure("ldc did not link");
 775     return;
 776   }
 777   if (basic_type == T_OBJECT || basic_type == T_VALUETYPE || basic_type == T_ARRAY) {
 778     ciObject* obj = con.as_object();
 779     if (obj->is_null_object()) {
 780       push_null();
 781     } else {
 782       assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
 783       ciType* type = obj->klass();
 784       if (type->is_valuetype()) {
 785         type = outer()->mark_as_never_null(type);
 786       }
 787       push(type);
 788     }
 789   } else {
 790     push_translate(ciType::make(basic_type));
 791   }
 792 }
 793 
 794 // ------------------------------------------------------------------
 795 // ciTypeFlow::StateVector::do_multianewarray
 796 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
 797   int dimensions = str->get_dimensions();


< prev index next >