< prev index next >

src/hotspot/share/c1/c1_Canonicalizer.cpp

Print this page

264     ciField* field = lf->field();
265     if (field->is_static_constant()) {
266       // Constant field loads are usually folded during parsing.
267       // But it doesn't happen with PatchALot, ScavengeRootsInCode < 2, or when
268       // holder class is being initialized during parsing (for static fields).
269       ciObject* c = field->constant_value().as_object();
270       if (!c->is_null_object()) {
271         set_constant(c->as_array()->length());
272       }
273     }
274   }
275 }
276 
277 void Canonicalizer::do_LoadIndexed    (LoadIndexed*     x) {
278   StableArrayConstant* array = x->array()->type()->as_StableArrayConstant();
279   IntConstant* index = x->index()->type()->as_IntConstant();
280 
281   assert(array == nullptr || FoldStableValues, "not enabled");
282 
283   // Constant fold loads from stable arrays.
284   if (!x->mismatched() && array != nullptr && index != nullptr) {
285     jint idx = index->value();
286     if (idx < 0 || idx >= array->value()->length()) {
287       // Leave the load as is. The range check will handle it.
288       return;
289     }
290 
291     ciConstant field_val = array->value()->element_value(idx);
292     if (!field_val.is_null_or_zero()) {
293       jint dimension = array->dimension();
294       assert(dimension <= array->value()->array_type()->dimension(), "inconsistent info");
295       ValueType* value = nullptr;
296       if (dimension > 1) {
297         // Preserve information about the dimension for the element.
298         assert(field_val.as_object()->is_array(), "not an array");
299         value = new StableArrayConstant(field_val.as_object()->as_array(), dimension - 1);
300       } else {
301         assert(dimension == 1, "sanity");
302         value = as_ValueType(field_val);
303       }
304       set_canonical(new Constant(value));

659 }
660 
661 void Canonicalizer::do_TypeCast       (TypeCast*        x) {}
662 void Canonicalizer::do_Invoke         (Invoke*          x) {}
663 void Canonicalizer::do_NewInstance    (NewInstance*     x) {}
664 void Canonicalizer::do_NewTypeArray   (NewTypeArray*    x) {}
665 void Canonicalizer::do_NewObjectArray (NewObjectArray*  x) {}
666 void Canonicalizer::do_NewMultiArray  (NewMultiArray*   x) {}
667 void Canonicalizer::do_CheckCast      (CheckCast*       x) {
668   if (x->klass()->is_loaded()) {
669     Value obj = x->obj();
670     ciType* klass = obj->exact_type();
671     if (klass == nullptr) {
672       klass = obj->declared_type();
673     }
674     if (klass != nullptr && klass->is_loaded()) {
675       bool is_interface = klass->is_instance_klass() &&
676                           klass->as_instance_klass()->is_interface();
677       // Interface casts can't be statically optimized away since verifier doesn't
678       // enforce interface types in bytecode.
679       if (!is_interface && klass->is_subtype_of(x->klass())) {

680         set_canonical(obj);
681         return;
682       }
683     }
684     // checkcast of null returns null
685     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
686       set_canonical(obj);
687     }
688   }
689 }
690 void Canonicalizer::do_InstanceOf     (InstanceOf*      x) {
691   if (x->klass()->is_loaded()) {
692     Value obj = x->obj();
693     ciType* exact = obj->exact_type();
694     if (exact != nullptr && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
695       set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
696       return;
697     }
698     // instanceof null returns false
699     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
700       set_constant(0);
701     }
702   }
703 
704 }
705 void Canonicalizer::do_MonitorEnter   (MonitorEnter*    x) {}
706 void Canonicalizer::do_MonitorExit    (MonitorExit*     x) {}
707 void Canonicalizer::do_BlockBegin     (BlockBegin*      x) {}
708 void Canonicalizer::do_Goto           (Goto*            x) {}
709 
710 
711 static bool is_true(jlong x, If::Condition cond, jlong y) {
712   switch (cond) {
713     case If::eql: return x == y;
714     case If::neq: return x != y;
715     case If::lss: return x <  y;
716     case If::leq: return x <= y;
717     case If::gtr: return x >  y;
718     case If::geq: return x >= y;
719     default:

857       } else {
858         low = mid + 1;
859       }
860     }
861     set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
862   }
863 }
864 
865 
866 void Canonicalizer::do_Return         (Return*          x) {}
867 void Canonicalizer::do_Throw          (Throw*           x) {}
868 void Canonicalizer::do_Base           (Base*            x) {}
869 void Canonicalizer::do_OsrEntry       (OsrEntry*        x) {}
870 void Canonicalizer::do_ExceptionObject(ExceptionObject* x) {}
871 void Canonicalizer::do_RoundFP        (RoundFP*         x) {}
872 void Canonicalizer::do_UnsafeGet      (UnsafeGet*       x) {}
873 void Canonicalizer::do_UnsafePut      (UnsafePut*       x) {}
874 void Canonicalizer::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {}
875 void Canonicalizer::do_ProfileCall    (ProfileCall*     x) {}
876 void Canonicalizer::do_ProfileReturnType(ProfileReturnType* x) {}
877 void Canonicalizer::do_ProfileInvoke  (ProfileInvoke*   x) {}
878 void Canonicalizer::do_RuntimeCall    (RuntimeCall*     x) {}

879 void Canonicalizer::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
880 #ifdef ASSERT
881 void Canonicalizer::do_Assert         (Assert*          x) {}
882 #endif
883 void Canonicalizer::do_MemBar         (MemBar*          x) {}

264     ciField* field = lf->field();
265     if (field->is_static_constant()) {
266       // Constant field loads are usually folded during parsing.
267       // But it doesn't happen with PatchALot, ScavengeRootsInCode < 2, or when
268       // holder class is being initialized during parsing (for static fields).
269       ciObject* c = field->constant_value().as_object();
270       if (!c->is_null_object()) {
271         set_constant(c->as_array()->length());
272       }
273     }
274   }
275 }
276 
277 void Canonicalizer::do_LoadIndexed    (LoadIndexed*     x) {
278   StableArrayConstant* array = x->array()->type()->as_StableArrayConstant();
279   IntConstant* index = x->index()->type()->as_IntConstant();
280 
281   assert(array == nullptr || FoldStableValues, "not enabled");
282 
283   // Constant fold loads from stable arrays.
284   if (!x->should_profile() && !x->mismatched() && array != nullptr && index != nullptr) {
285     jint idx = index->value();
286     if (idx < 0 || idx >= array->value()->length()) {
287       // Leave the load as is. The range check will handle it.
288       return;
289     }
290 
291     ciConstant field_val = array->value()->element_value(idx);
292     if (!field_val.is_null_or_zero()) {
293       jint dimension = array->dimension();
294       assert(dimension <= array->value()->array_type()->dimension(), "inconsistent info");
295       ValueType* value = nullptr;
296       if (dimension > 1) {
297         // Preserve information about the dimension for the element.
298         assert(field_val.as_object()->is_array(), "not an array");
299         value = new StableArrayConstant(field_val.as_object()->as_array(), dimension - 1);
300       } else {
301         assert(dimension == 1, "sanity");
302         value = as_ValueType(field_val);
303       }
304       set_canonical(new Constant(value));

659 }
660 
661 void Canonicalizer::do_TypeCast       (TypeCast*        x) {}
662 void Canonicalizer::do_Invoke         (Invoke*          x) {}
663 void Canonicalizer::do_NewInstance    (NewInstance*     x) {}
664 void Canonicalizer::do_NewTypeArray   (NewTypeArray*    x) {}
665 void Canonicalizer::do_NewObjectArray (NewObjectArray*  x) {}
666 void Canonicalizer::do_NewMultiArray  (NewMultiArray*   x) {}
667 void Canonicalizer::do_CheckCast      (CheckCast*       x) {
668   if (x->klass()->is_loaded()) {
669     Value obj = x->obj();
670     ciType* klass = obj->exact_type();
671     if (klass == nullptr) {
672       klass = obj->declared_type();
673     }
674     if (klass != nullptr && klass->is_loaded()) {
675       bool is_interface = klass->is_instance_klass() &&
676                           klass->as_instance_klass()->is_interface();
677       // Interface casts can't be statically optimized away since verifier doesn't
678       // enforce interface types in bytecode.
679       if (!is_interface && klass->is_subtype_of(x->klass()) && (!x->is_null_free() || obj->is_null_free())) {
680         assert(!x->klass()->is_inlinetype() || x->klass() == klass, "Inline klasses can't have subtypes");
681         set_canonical(obj);
682         return;
683       }
684     }
685     // checkcast of null returns null for non null-free klasses
686     if (!x->is_null_free() && obj->is_null_obj()) {
687       set_canonical(obj);
688     }
689   }
690 }
691 void Canonicalizer::do_InstanceOf     (InstanceOf*      x) {
692   if (x->klass()->is_loaded()) {
693     Value obj = x->obj();
694     ciType* exact = obj->exact_type();
695     if (exact != nullptr && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
696       set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
697       return;
698     }
699     // instanceof null returns false
700     if (obj->as_Constant() && obj->is_null_obj()) {
701       set_constant(0);
702     }
703   }
704 
705 }
706 void Canonicalizer::do_MonitorEnter   (MonitorEnter*    x) {}
707 void Canonicalizer::do_MonitorExit    (MonitorExit*     x) {}
708 void Canonicalizer::do_BlockBegin     (BlockBegin*      x) {}
709 void Canonicalizer::do_Goto           (Goto*            x) {}
710 
711 
712 static bool is_true(jlong x, If::Condition cond, jlong y) {
713   switch (cond) {
714     case If::eql: return x == y;
715     case If::neq: return x != y;
716     case If::lss: return x <  y;
717     case If::leq: return x <= y;
718     case If::gtr: return x >  y;
719     case If::geq: return x >= y;
720     default:

858       } else {
859         low = mid + 1;
860       }
861     }
862     set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
863   }
864 }
865 
866 
867 void Canonicalizer::do_Return         (Return*          x) {}
868 void Canonicalizer::do_Throw          (Throw*           x) {}
869 void Canonicalizer::do_Base           (Base*            x) {}
870 void Canonicalizer::do_OsrEntry       (OsrEntry*        x) {}
871 void Canonicalizer::do_ExceptionObject(ExceptionObject* x) {}
872 void Canonicalizer::do_RoundFP        (RoundFP*         x) {}
873 void Canonicalizer::do_UnsafeGet      (UnsafeGet*       x) {}
874 void Canonicalizer::do_UnsafePut      (UnsafePut*       x) {}
875 void Canonicalizer::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {}
876 void Canonicalizer::do_ProfileCall    (ProfileCall*     x) {}
877 void Canonicalizer::do_ProfileReturnType(ProfileReturnType* x) {}
878 void Canonicalizer::do_ProfileInvoke    (ProfileInvoke* x) {}
879 void Canonicalizer::do_ProfileACmpTypes (ProfileACmpTypes* x) {}
880 void Canonicalizer::do_RuntimeCall      (RuntimeCall* x) {}
881 void Canonicalizer::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
882 #ifdef ASSERT
883 void Canonicalizer::do_Assert         (Assert*          x) {}
884 #endif
885 void Canonicalizer::do_MemBar         (MemBar*          x) {}
< prev index next >