< prev index next >

src/hotspot/share/opto/subtypenode.cpp

Print this page

 29 #include "opto/phaseX.hpp"
 30 #include "opto/rootnode.hpp"
 31 #include "opto/subnode.hpp"
 32 #include "opto/subtypenode.hpp"
 33 
 34 const Type* SubTypeCheckNode::sub(const Type* sub_t, const Type* super_t) const {
 35   const TypeKlassPtr* superk = super_t->isa_klassptr();
 36   assert(sub_t != Type::TOP && !TypePtr::NULL_PTR->higher_equal(sub_t), "should be not null");
 37   const TypeKlassPtr* subk = sub_t->isa_klassptr() ? sub_t->is_klassptr() : sub_t->is_oopptr()->as_klass_type();
 38 
 39   // Oop can't be a subtype of abstract type that has no subclass.
 40   if (sub_t->isa_oopptr() && superk->isa_instklassptr() && superk->klass_is_exact()) {
 41     ciKlass* superklass = superk->exact_klass();
 42     if (!superklass->is_interface() && superklass->is_abstract() &&
 43         !superklass->as_instance_klass()->has_subklass()) {
 44       Compile::current()->dependencies()->assert_leaf_type(superklass);
 45       return TypeInt::CC_GT;
 46     }
 47   }
 48 
 49   if (subk != nullptr) {
 50     switch (Compile::current()->static_subtype_check(superk, subk, false)) {
 51       case Compile::SSC_always_false:
 52         return TypeInt::CC_GT;
 53       case Compile::SSC_always_true:
 54         return TypeInt::CC_EQ;
 55       case Compile::SSC_easy_test:
 56       case Compile::SSC_full_test:
 57         break;
 58       default:
 59         ShouldNotReachHere();







 60     }
 61   }
 62 












 63   return bottom_type();
 64 }
 65 
 66 Node *SubTypeCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
 67   Node* obj_or_subklass = in(ObjOrSubKlass);
 68   Node* superklass = in(SuperKlass);
 69 
 70   if (obj_or_subklass == nullptr ||
 71       superklass == nullptr) {
 72     return nullptr;
 73   }
 74 
 75   const Type* sub_t = phase->type(obj_or_subklass);
 76   const Type* super_t = phase->type(superklass);
 77 
 78   if (!super_t->isa_klassptr() ||
 79       (!sub_t->isa_klassptr() && !sub_t->isa_oopptr())) {
 80     return nullptr;
 81   }
 82 

170     if (obj_or_subklass->bottom_type() == Type::TOP) {
171       // The bottom type of obj_or_subklass is TOP, despite its recorded type
172       // being an OOP or a klass pointer. This can happen for example in
173       // transient scenarios where obj_or_subklass is a projection of the TOP
174       // node. In such cases, skip verification to avoid violating the contract
175       // of LoadKlassNode::make(). This does not weaken the effect of verify(),
176       // as SubTypeCheck nodes with TOP obj_or_subklass inputs are dead anyway.
177       return true;
178     }
179     const Type* cached_t = Value(phase); // cache the type to validate consistency
180     switch (C->static_subtype_check(superk, subk)) {
181       case Compile::SSC_easy_test: {
182         return verify_helper(phase, load_klass(phase), cached_t);
183       }
184       case Compile::SSC_full_test: {
185         Node* p1 = phase->transform(new AddPNode(superklass, superklass, phase->MakeConX(in_bytes(Klass::super_check_offset_offset()))));
186         Node* chk_off = phase->transform(new LoadINode(nullptr, C->immutable_memory(), p1, phase->type(p1)->is_ptr(), TypeInt::INT, MemNode::unordered));
187         record_for_cleanup(chk_off, phase);
188 
189         int cacheoff_con = in_bytes(Klass::secondary_super_cache_offset());
190         bool might_be_cache = (phase->find_int_con(chk_off, cacheoff_con) == cacheoff_con);

191         if (!might_be_cache) {
192           Node* subklass = load_klass(phase);
193           Node* chk_off_X = chk_off;
194 #ifdef _LP64
195           chk_off_X = phase->transform(new ConvI2LNode(chk_off_X));
196 #endif
197           Node* p2 = phase->transform(new AddPNode(subklass, subklass, chk_off_X));
198           Node* nkls = phase->transform(LoadKlassNode::make(*phase, C->immutable_memory(), p2, phase->type(p2)->is_ptr(), TypeInstKlassPtr::OBJECT_OR_NULL));
199 
200           return verify_helper(phase, nkls, cached_t);
201         }
202         break;
203       }
204       case Compile::SSC_always_false:
205       case Compile::SSC_always_true:
206       default: {
207         break; // nothing to do
208       }
209     }
210   }

226   return subklass;
227 }
228 #endif
229 
230 uint SubTypeCheckNode::size_of() const {
231   return sizeof(*this);
232 }
233 
234 uint SubTypeCheckNode::hash() const {
235   return NO_HASH;
236 }
237 
238 #ifndef PRODUCT
239 void SubTypeCheckNode::dump_spec(outputStream* st) const {
240   if (_method != nullptr) {
241     st->print(" profiled at:");
242     _method->print_short_name(st);
243     st->print(":%d", _bci);
244   }
245 }
246 #endif

 29 #include "opto/phaseX.hpp"
 30 #include "opto/rootnode.hpp"
 31 #include "opto/subnode.hpp"
 32 #include "opto/subtypenode.hpp"
 33 
 34 const Type* SubTypeCheckNode::sub(const Type* sub_t, const Type* super_t) const {
 35   const TypeKlassPtr* superk = super_t->isa_klassptr();
 36   assert(sub_t != Type::TOP && !TypePtr::NULL_PTR->higher_equal(sub_t), "should be not null");
 37   const TypeKlassPtr* subk = sub_t->isa_klassptr() ? sub_t->is_klassptr() : sub_t->is_oopptr()->as_klass_type();
 38 
 39   // Oop can't be a subtype of abstract type that has no subclass.
 40   if (sub_t->isa_oopptr() && superk->isa_instklassptr() && superk->klass_is_exact()) {
 41     ciKlass* superklass = superk->exact_klass();
 42     if (!superklass->is_interface() && superklass->is_abstract() &&
 43         !superklass->as_instance_klass()->has_subklass()) {
 44       Compile::current()->dependencies()->assert_leaf_type(superklass);
 45       return TypeInt::CC_GT;
 46     }
 47   }
 48 
 49   // FIXME: shouldn't this be encoded in helper methods of the type system (maybe_java_subtype_of() etc.?)
 50   // Similar to logic in CmpPNode::sub()
 51   bool unrelated_classes = false;
 52   // Handle inline type arrays
 53   if (subk->flat_in_array() && superk->not_flat_in_array_inexact()) {
 54     // The subtype is in flat arrays and the supertype is not in flat arrays and no subklass can be. Must be unrelated.
 55     unrelated_classes = true;
 56   } else if (subk->is_not_flat() && superk->is_flat()) {
 57     // The subtype is a non-flat array and the supertype is a flat array. Must be unrelated.
 58     unrelated_classes = true;
 59   } else if (subk->is_not_null_free() && superk->is_null_free()) {
 60     // The subtype is a nullable array and the supertype is null-free array. Must be unrelated.
 61     unrelated_classes = true;
 62   }
 63   if (unrelated_classes) {
 64     TypePtr::PTR jp = sub_t->is_ptr()->join_ptr(super_t->is_ptr()->_ptr);
 65     if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
 66       return TypeInt::CC_GT;
 67     }
 68   }
 69 
 70   switch (Compile::current()->static_subtype_check(superk, subk, false)) {
 71     case Compile::SSC_always_false:
 72       return TypeInt::CC_GT;
 73     case Compile::SSC_always_true:
 74       return TypeInt::CC_EQ;
 75     case Compile::SSC_easy_test:
 76     case Compile::SSC_full_test:
 77       break;
 78     default:
 79       ShouldNotReachHere();
 80   }
 81 
 82   return bottom_type();
 83 }
 84 
 85 Node *SubTypeCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
 86   Node* obj_or_subklass = in(ObjOrSubKlass);
 87   Node* superklass = in(SuperKlass);
 88 
 89   if (obj_or_subklass == nullptr ||
 90       superklass == nullptr) {
 91     return nullptr;
 92   }
 93 
 94   const Type* sub_t = phase->type(obj_or_subklass);
 95   const Type* super_t = phase->type(superklass);
 96 
 97   if (!super_t->isa_klassptr() ||
 98       (!sub_t->isa_klassptr() && !sub_t->isa_oopptr())) {
 99     return nullptr;
100   }
101 

189     if (obj_or_subklass->bottom_type() == Type::TOP) {
190       // The bottom type of obj_or_subklass is TOP, despite its recorded type
191       // being an OOP or a klass pointer. This can happen for example in
192       // transient scenarios where obj_or_subklass is a projection of the TOP
193       // node. In such cases, skip verification to avoid violating the contract
194       // of LoadKlassNode::make(). This does not weaken the effect of verify(),
195       // as SubTypeCheck nodes with TOP obj_or_subklass inputs are dead anyway.
196       return true;
197     }
198     const Type* cached_t = Value(phase); // cache the type to validate consistency
199     switch (C->static_subtype_check(superk, subk)) {
200       case Compile::SSC_easy_test: {
201         return verify_helper(phase, load_klass(phase), cached_t);
202       }
203       case Compile::SSC_full_test: {
204         Node* p1 = phase->transform(new AddPNode(superklass, superklass, phase->MakeConX(in_bytes(Klass::super_check_offset_offset()))));
205         Node* chk_off = phase->transform(new LoadINode(nullptr, C->immutable_memory(), p1, phase->type(p1)->is_ptr(), TypeInt::INT, MemNode::unordered));
206         record_for_cleanup(chk_off, phase);
207 
208         int cacheoff_con = in_bytes(Klass::secondary_super_cache_offset());
209         // TODO 8366668 Re-enable. This breaks TestArrays.java with -XX:+StressReflectiveCode
210         bool might_be_cache = true; // (phase->find_int_con(chk_off, cacheoff_con) == cacheoff_con);
211         if (!might_be_cache) {
212           Node* subklass = load_klass(phase);
213           Node* chk_off_X = chk_off;
214 #ifdef _LP64
215           chk_off_X = phase->transform(new ConvI2LNode(chk_off_X));
216 #endif
217           Node* p2 = phase->transform(new AddPNode(subklass, subklass, chk_off_X));
218           Node* nkls = phase->transform(LoadKlassNode::make(*phase, C->immutable_memory(), p2, phase->type(p2)->is_ptr(), TypeInstKlassPtr::OBJECT_OR_NULL));
219 
220           return verify_helper(phase, nkls, cached_t);
221         }
222         break;
223       }
224       case Compile::SSC_always_false:
225       case Compile::SSC_always_true:
226       default: {
227         break; // nothing to do
228       }
229     }
230   }

246   return subklass;
247 }
248 #endif
249 
250 uint SubTypeCheckNode::size_of() const {
251   return sizeof(*this);
252 }
253 
254 uint SubTypeCheckNode::hash() const {
255   return NO_HASH;
256 }
257 
258 #ifndef PRODUCT
259 void SubTypeCheckNode::dump_spec(outputStream* st) const {
260   if (_method != nullptr) {
261     st->print(" profiled at:");
262     _method->print_short_name(st);
263     st->print(":%d", _bci);
264   }
265 }
266 #endif
< prev index next >