< prev index next >

src/hotspot/share/c1/c1_Canonicalizer.cpp

Print this page

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

631 }
632 
633 void Canonicalizer::do_TypeCast       (TypeCast*        x) {}
634 void Canonicalizer::do_Invoke         (Invoke*          x) {}
635 void Canonicalizer::do_NewInstance    (NewInstance*     x) {}
636 void Canonicalizer::do_NewTypeArray   (NewTypeArray*    x) {}
637 void Canonicalizer::do_NewObjectArray (NewObjectArray*  x) {}
638 void Canonicalizer::do_NewMultiArray  (NewMultiArray*   x) {}
639 void Canonicalizer::do_CheckCast      (CheckCast*       x) {
640   if (x->klass()->is_loaded()) {
641     Value obj = x->obj();
642     ciType* klass = obj->exact_type();
643     if (klass == nullptr) {
644       klass = obj->declared_type();
645     }
646     if (klass != nullptr && klass->is_loaded()) {
647       bool is_interface = klass->is_instance_klass() &&
648                           klass->as_instance_klass()->is_interface();
649       // Interface casts can't be statically optimized away since verifier doesn't
650       // enforce interface types in bytecode.
651       if (!is_interface && klass->is_subtype_of(x->klass())) {

652         set_canonical(obj);
653         return;
654       }
655     }
656     // checkcast of null returns null
657     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
658       set_canonical(obj);
659     }
660   }
661 }
662 void Canonicalizer::do_InstanceOf     (InstanceOf*      x) {
663   if (x->klass()->is_loaded()) {
664     Value obj = x->obj();
665     ciType* exact = obj->exact_type();
666     if (exact != nullptr && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
667       set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
668       return;
669     }
670     // instanceof null returns false
671     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
672       set_constant(0);
673     }
674   }
675 
676 }
677 void Canonicalizer::do_MonitorEnter   (MonitorEnter*    x) {}
678 void Canonicalizer::do_MonitorExit    (MonitorExit*     x) {}
679 void Canonicalizer::do_BlockBegin     (BlockBegin*      x) {}
680 void Canonicalizer::do_Goto           (Goto*            x) {}
681 
682 
683 static bool is_true(jlong x, If::Condition cond, jlong y) {
684   switch (cond) {
685     case If::eql: return x == y;
686     case If::neq: return x != y;
687     case If::lss: return x <  y;
688     case If::leq: return x <= y;
689     case If::gtr: return x >  y;
690     case If::geq: return x >= y;
691     default:

829       } else {
830         low = mid + 1;
831       }
832     }
833     set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
834   }
835 }
836 
837 
838 void Canonicalizer::do_Return         (Return*          x) {}
839 void Canonicalizer::do_Throw          (Throw*           x) {}
840 void Canonicalizer::do_Base           (Base*            x) {}
841 void Canonicalizer::do_OsrEntry       (OsrEntry*        x) {}
842 void Canonicalizer::do_ExceptionObject(ExceptionObject* x) {}
843 void Canonicalizer::do_RoundFP        (RoundFP*         x) {}
844 void Canonicalizer::do_UnsafeGet      (UnsafeGet*       x) {}
845 void Canonicalizer::do_UnsafePut      (UnsafePut*       x) {}
846 void Canonicalizer::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {}
847 void Canonicalizer::do_ProfileCall    (ProfileCall*     x) {}
848 void Canonicalizer::do_ProfileReturnType(ProfileReturnType* x) {}
849 void Canonicalizer::do_ProfileInvoke  (ProfileInvoke*   x) {}
850 void Canonicalizer::do_RuntimeCall    (RuntimeCall*     x) {}

851 void Canonicalizer::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
852 #ifdef ASSERT
853 void Canonicalizer::do_Assert         (Assert*          x) {}
854 #endif
855 void Canonicalizer::do_MemBar         (MemBar*          x) {}

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

631 }
632 
633 void Canonicalizer::do_TypeCast       (TypeCast*        x) {}
634 void Canonicalizer::do_Invoke         (Invoke*          x) {}
635 void Canonicalizer::do_NewInstance    (NewInstance*     x) {}
636 void Canonicalizer::do_NewTypeArray   (NewTypeArray*    x) {}
637 void Canonicalizer::do_NewObjectArray (NewObjectArray*  x) {}
638 void Canonicalizer::do_NewMultiArray  (NewMultiArray*   x) {}
639 void Canonicalizer::do_CheckCast      (CheckCast*       x) {
640   if (x->klass()->is_loaded()) {
641     Value obj = x->obj();
642     ciType* klass = obj->exact_type();
643     if (klass == nullptr) {
644       klass = obj->declared_type();
645     }
646     if (klass != nullptr && klass->is_loaded()) {
647       bool is_interface = klass->is_instance_klass() &&
648                           klass->as_instance_klass()->is_interface();
649       // Interface casts can't be statically optimized away since verifier doesn't
650       // enforce interface types in bytecode.
651       if (!is_interface && klass->is_subtype_of(x->klass()) && (!x->is_null_free() || obj->is_null_free())) {
652         assert(!x->klass()->is_inlinetype() || x->klass() == klass, "Inline klasses can't have subtypes");
653         set_canonical(obj);
654         return;
655       }
656     }
657     // checkcast of null returns null for non null-free klasses
658     if (!x->is_null_free() && obj->is_null_obj()) {
659       set_canonical(obj);
660     }
661   }
662 }
663 void Canonicalizer::do_InstanceOf     (InstanceOf*      x) {
664   if (x->klass()->is_loaded()) {
665     Value obj = x->obj();
666     ciType* exact = obj->exact_type();
667     if (exact != nullptr && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
668       set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
669       return;
670     }
671     // instanceof null returns false
672     if (obj->as_Constant() && obj->is_null_obj()) {
673       set_constant(0);
674     }
675   }
676 
677 }
678 void Canonicalizer::do_MonitorEnter   (MonitorEnter*    x) {}
679 void Canonicalizer::do_MonitorExit    (MonitorExit*     x) {}
680 void Canonicalizer::do_BlockBegin     (BlockBegin*      x) {}
681 void Canonicalizer::do_Goto           (Goto*            x) {}
682 
683 
684 static bool is_true(jlong x, If::Condition cond, jlong y) {
685   switch (cond) {
686     case If::eql: return x == y;
687     case If::neq: return x != y;
688     case If::lss: return x <  y;
689     case If::leq: return x <= y;
690     case If::gtr: return x >  y;
691     case If::geq: return x >= y;
692     default:

830       } else {
831         low = mid + 1;
832       }
833     }
834     set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
835   }
836 }
837 
838 
839 void Canonicalizer::do_Return         (Return*          x) {}
840 void Canonicalizer::do_Throw          (Throw*           x) {}
841 void Canonicalizer::do_Base           (Base*            x) {}
842 void Canonicalizer::do_OsrEntry       (OsrEntry*        x) {}
843 void Canonicalizer::do_ExceptionObject(ExceptionObject* x) {}
844 void Canonicalizer::do_RoundFP        (RoundFP*         x) {}
845 void Canonicalizer::do_UnsafeGet      (UnsafeGet*       x) {}
846 void Canonicalizer::do_UnsafePut      (UnsafePut*       x) {}
847 void Canonicalizer::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {}
848 void Canonicalizer::do_ProfileCall    (ProfileCall*     x) {}
849 void Canonicalizer::do_ProfileReturnType(ProfileReturnType* x) {}
850 void Canonicalizer::do_ProfileInvoke    (ProfileInvoke* x) {}
851 void Canonicalizer::do_ProfileACmpTypes (ProfileACmpTypes* x) {}
852 void Canonicalizer::do_RuntimeCall      (RuntimeCall* x) {}
853 void Canonicalizer::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
854 #ifdef ASSERT
855 void Canonicalizer::do_Assert         (Assert*          x) {}
856 #endif
857 void Canonicalizer::do_MemBar         (MemBar*          x) {}
< prev index next >