252 if (con_type != NULL) {
253 if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
254 con_type = con_type->is_aryptr()->cast_to_autobox_cache(true);
255 }
256 if (stable_dimension > 0) {
257 assert(FoldStableValues, "sanity");
258 assert(!con_type->is_zero_type(), "default value for stable field");
259 con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
260 }
261 }
262 }
263 if (is_narrow_oop) {
264 con_type = con_type->make_narrowoop();
265 }
266 return con_type;
267 }
268 case T_ILLEGAL:
269 // Invalid ciConstant returned due to OutOfMemoryError in the CI
270 assert(Compile::current()->env()->failing(), "otherwise should not see this");
271 return NULL;
272 }
273 // Fall through to failure
274 return NULL;
275 }
276
277 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
278 BasicType conbt = con.basic_type();
279 switch (conbt) {
280 case T_BOOLEAN: conbt = T_BYTE; break;
281 case T_ARRAY: conbt = T_OBJECT; break;
282 }
283 switch (loadbt) {
284 case T_BOOLEAN: loadbt = T_BYTE; break;
285 case T_NARROWOOP: loadbt = T_OBJECT; break;
286 case T_ARRAY: loadbt = T_OBJECT; break;
287 case T_ADDRESS: loadbt = T_OBJECT; break;
288 }
289 if (conbt == loadbt) {
290 if (is_unsigned && conbt == T_BYTE) {
291 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
292 return ciConstant(T_INT, con.as_int() & 0xFF);
293 } else {
294 return con;
295 }
296 }
297 if (conbt == T_SHORT && loadbt == T_CHAR) {
298 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
299 return ciConstant(T_INT, con.as_int() & 0xFFFF);
300 }
301 return ciConstant(); // T_ILLEGAL
302 }
303
304 // Try to constant-fold a stable array element.
305 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
306 BasicType loadbt, bool is_unsigned_load) {
307 // Decode the results of GraphKit::array_element_address.
1031 return _base == Top || _base == Half;
1032 }
1033
1034 //------------------------------empty------------------------------------------
1035 // TRUE if Type is a type with no values, FALSE otherwise.
1036 bool Type::empty(void) const {
1037 switch (_base) {
1038 case DoubleTop:
1039 case FloatTop:
1040 case Top:
1041 return true;
1042
1043 case Half:
1044 case Abio:
1045 case Return_Address:
1046 case Memory:
1047 case Bottom:
1048 case FloatBot:
1049 case DoubleBot:
1050 return false; // never a singleton, therefore never empty
1051 }
1052
1053 ShouldNotReachHere();
1054 return false;
1055 }
1056
1057 //------------------------------dump_stats-------------------------------------
1058 // Dump collected statistics to stderr
1059 #ifndef PRODUCT
1060 void Type::dump_stats() {
1061 tty->print("Types made: %d\n", type_dict()->Size());
1062 }
1063 #endif
1064
1065 //------------------------------typerr-----------------------------------------
1066 void Type::typerr( const Type *t ) const {
1067 #ifndef PRODUCT
1068 tty->print("\nError mixing types: ");
1069 dump();
1070 tty->print(" and ");
1071 t->dump();
1072 tty->print("\n");
1073 #endif
1074 ShouldNotReachHere();
3947 // Print the name of the klass.
3948 klass()->print_name_on(st);
3949
3950 switch( _ptr ) {
3951 case Constant:
3952 // TO DO: Make CI print the hex address of the underlying oop.
3953 if (WizardMode || Verbose) {
3954 const_oop()->print_oop(st);
3955 }
3956 case BotPTR:
3957 if (!WizardMode && !Verbose) {
3958 if( _klass_is_exact ) st->print(":exact");
3959 break;
3960 }
3961 case TopPTR:
3962 case AnyNull:
3963 case NotNull:
3964 st->print(":%s", ptr_msg[_ptr]);
3965 if( _klass_is_exact ) st->print(":exact");
3966 break;
3967 }
3968
3969 if( _offset ) { // Dump offset, if any
3970 if( _offset == OffsetBot ) st->print("+any");
3971 else if( _offset == OffsetTop ) st->print("+unknown");
3972 else st->print("+%d", _offset);
3973 }
3974
3975 st->print(" *");
3976 if (_instance_id == InstanceTop)
3977 st->print(",iid=top");
3978 else if (_instance_id != InstanceBot)
3979 st->print(",iid=%d",_instance_id);
3980
3981 dump_inline_depth(st);
3982 dump_speculative(st);
3983 }
3984 #endif
3985
3986 //------------------------------add_offset-------------------------------------
4063 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4064 }
4065
4066 //-----------------------------narrow_size_type-------------------------------
4067 // Local cache for arrayOopDesc::max_array_length(etype),
4068 // which is kind of slow (and cached elsewhere by other users).
4069 static jint max_array_length_cache[T_CONFLICT+1];
4070 static jint max_array_length(BasicType etype) {
4071 jint& cache = max_array_length_cache[etype];
4072 jint res = cache;
4073 if (res == 0) {
4074 switch (etype) {
4075 case T_NARROWOOP:
4076 etype = T_OBJECT;
4077 break;
4078 case T_NARROWKLASS:
4079 case T_CONFLICT:
4080 case T_ILLEGAL:
4081 case T_VOID:
4082 etype = T_BYTE; // will produce conservatively high value
4083 }
4084 cache = res = arrayOopDesc::max_array_length(etype);
4085 }
4086 return res;
4087 }
4088
4089 // Narrow the given size type to the index range for the given array base type.
4090 // Return NULL if the resulting int type becomes empty.
4091 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4092 jint hi = size->_hi;
4093 jint lo = size->_lo;
4094 jint min_lo = 0;
4095 jint max_hi = max_array_length(elem()->basic_type());
4096 //if (index_not_size) --max_hi; // type of a valid array index, FTR
4097 bool chg = false;
4098 if (lo < min_lo) {
4099 lo = min_lo;
4100 if (size->is_con()) {
4101 hi = lo;
4102 }
4413
4414 //------------------------------dump2------------------------------------------
4415 #ifndef PRODUCT
4416 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4417 _ary->dump2(d,depth,st);
4418 switch( _ptr ) {
4419 case Constant:
4420 const_oop()->print(st);
4421 break;
4422 case BotPTR:
4423 if (!WizardMode && !Verbose) {
4424 if( _klass_is_exact ) st->print(":exact");
4425 break;
4426 }
4427 case TopPTR:
4428 case AnyNull:
4429 case NotNull:
4430 st->print(":%s", ptr_msg[_ptr]);
4431 if( _klass_is_exact ) st->print(":exact");
4432 break;
4433 }
4434
4435 if( _offset != 0 ) {
4436 int header_size = objArrayOopDesc::header_size() * wordSize;
4437 if( _offset == OffsetTop ) st->print("+undefined");
4438 else if( _offset == OffsetBot ) st->print("+any");
4439 else if( _offset < header_size ) st->print("+%d", _offset);
4440 else {
4441 BasicType basic_elem_type = elem()->basic_type();
4442 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4443 int elem_size = type2aelembytes(basic_elem_type);
4444 st->print("[%d]", (_offset - array_base)/elem_size);
4445 }
4446 }
4447 st->print(" *");
4448 if (_instance_id == InstanceTop)
4449 st->print(",iid=top");
4450 else if (_instance_id != InstanceBot)
4451 st->print(",iid=%d",_instance_id);
4452
5178 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5179 switch( _ptr ) {
5180 case Constant:
5181 st->print("precise ");
5182 case NotNull:
5183 {
5184 const char *name = klass()->name()->as_utf8();
5185 if( name ) {
5186 st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5187 } else {
5188 ShouldNotReachHere();
5189 }
5190 }
5191 case BotPTR:
5192 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5193 case TopPTR:
5194 case AnyNull:
5195 st->print(":%s", ptr_msg[_ptr]);
5196 if( _klass_is_exact ) st->print(":exact");
5197 break;
5198 }
5199
5200 if( _offset ) { // Dump offset, if any
5201 if( _offset == OffsetBot ) { st->print("+any"); }
5202 else if( _offset == OffsetTop ) { st->print("+unknown"); }
5203 else { st->print("+%d", _offset); }
5204 }
5205
5206 st->print(" *");
5207 }
5208 #endif
5209
5210
5211
5212 //=============================================================================
5213 // Convenience common pre-built types.
5214
5215 //------------------------------make-------------------------------------------
5216 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5217 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
|
252 if (con_type != NULL) {
253 if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
254 con_type = con_type->is_aryptr()->cast_to_autobox_cache(true);
255 }
256 if (stable_dimension > 0) {
257 assert(FoldStableValues, "sanity");
258 assert(!con_type->is_zero_type(), "default value for stable field");
259 con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
260 }
261 }
262 }
263 if (is_narrow_oop) {
264 con_type = con_type->make_narrowoop();
265 }
266 return con_type;
267 }
268 case T_ILLEGAL:
269 // Invalid ciConstant returned due to OutOfMemoryError in the CI
270 assert(Compile::current()->env()->failing(), "otherwise should not see this");
271 return NULL;
272 default:
273 // Fall through to failure
274 return NULL;
275 }
276 }
277
278 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
279 BasicType conbt = con.basic_type();
280 switch (conbt) {
281 case T_BOOLEAN: conbt = T_BYTE; break;
282 case T_ARRAY: conbt = T_OBJECT; break;
283 default: break;
284 }
285 switch (loadbt) {
286 case T_BOOLEAN: loadbt = T_BYTE; break;
287 case T_NARROWOOP: loadbt = T_OBJECT; break;
288 case T_ARRAY: loadbt = T_OBJECT; break;
289 case T_ADDRESS: loadbt = T_OBJECT; break;
290 default: break;
291 }
292 if (conbt == loadbt) {
293 if (is_unsigned && conbt == T_BYTE) {
294 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
295 return ciConstant(T_INT, con.as_int() & 0xFF);
296 } else {
297 return con;
298 }
299 }
300 if (conbt == T_SHORT && loadbt == T_CHAR) {
301 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
302 return ciConstant(T_INT, con.as_int() & 0xFFFF);
303 }
304 return ciConstant(); // T_ILLEGAL
305 }
306
307 // Try to constant-fold a stable array element.
308 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
309 BasicType loadbt, bool is_unsigned_load) {
310 // Decode the results of GraphKit::array_element_address.
1034 return _base == Top || _base == Half;
1035 }
1036
1037 //------------------------------empty------------------------------------------
1038 // TRUE if Type is a type with no values, FALSE otherwise.
1039 bool Type::empty(void) const {
1040 switch (_base) {
1041 case DoubleTop:
1042 case FloatTop:
1043 case Top:
1044 return true;
1045
1046 case Half:
1047 case Abio:
1048 case Return_Address:
1049 case Memory:
1050 case Bottom:
1051 case FloatBot:
1052 case DoubleBot:
1053 return false; // never a singleton, therefore never empty
1054
1055 default:
1056 ShouldNotReachHere();
1057 return false;
1058 }
1059 }
1060
1061 //------------------------------dump_stats-------------------------------------
1062 // Dump collected statistics to stderr
1063 #ifndef PRODUCT
1064 void Type::dump_stats() {
1065 tty->print("Types made: %d\n", type_dict()->Size());
1066 }
1067 #endif
1068
1069 //------------------------------typerr-----------------------------------------
1070 void Type::typerr( const Type *t ) const {
1071 #ifndef PRODUCT
1072 tty->print("\nError mixing types: ");
1073 dump();
1074 tty->print(" and ");
1075 t->dump();
1076 tty->print("\n");
1077 #endif
1078 ShouldNotReachHere();
3951 // Print the name of the klass.
3952 klass()->print_name_on(st);
3953
3954 switch( _ptr ) {
3955 case Constant:
3956 // TO DO: Make CI print the hex address of the underlying oop.
3957 if (WizardMode || Verbose) {
3958 const_oop()->print_oop(st);
3959 }
3960 case BotPTR:
3961 if (!WizardMode && !Verbose) {
3962 if( _klass_is_exact ) st->print(":exact");
3963 break;
3964 }
3965 case TopPTR:
3966 case AnyNull:
3967 case NotNull:
3968 st->print(":%s", ptr_msg[_ptr]);
3969 if( _klass_is_exact ) st->print(":exact");
3970 break;
3971 default:
3972 break;
3973 }
3974
3975 if( _offset ) { // Dump offset, if any
3976 if( _offset == OffsetBot ) st->print("+any");
3977 else if( _offset == OffsetTop ) st->print("+unknown");
3978 else st->print("+%d", _offset);
3979 }
3980
3981 st->print(" *");
3982 if (_instance_id == InstanceTop)
3983 st->print(",iid=top");
3984 else if (_instance_id != InstanceBot)
3985 st->print(",iid=%d",_instance_id);
3986
3987 dump_inline_depth(st);
3988 dump_speculative(st);
3989 }
3990 #endif
3991
3992 //------------------------------add_offset-------------------------------------
4069 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4070 }
4071
4072 //-----------------------------narrow_size_type-------------------------------
4073 // Local cache for arrayOopDesc::max_array_length(etype),
4074 // which is kind of slow (and cached elsewhere by other users).
4075 static jint max_array_length_cache[T_CONFLICT+1];
4076 static jint max_array_length(BasicType etype) {
4077 jint& cache = max_array_length_cache[etype];
4078 jint res = cache;
4079 if (res == 0) {
4080 switch (etype) {
4081 case T_NARROWOOP:
4082 etype = T_OBJECT;
4083 break;
4084 case T_NARROWKLASS:
4085 case T_CONFLICT:
4086 case T_ILLEGAL:
4087 case T_VOID:
4088 etype = T_BYTE; // will produce conservatively high value
4089 break;
4090 default:
4091 break;
4092 }
4093 cache = res = arrayOopDesc::max_array_length(etype);
4094 }
4095 return res;
4096 }
4097
4098 // Narrow the given size type to the index range for the given array base type.
4099 // Return NULL if the resulting int type becomes empty.
4100 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4101 jint hi = size->_hi;
4102 jint lo = size->_lo;
4103 jint min_lo = 0;
4104 jint max_hi = max_array_length(elem()->basic_type());
4105 //if (index_not_size) --max_hi; // type of a valid array index, FTR
4106 bool chg = false;
4107 if (lo < min_lo) {
4108 lo = min_lo;
4109 if (size->is_con()) {
4110 hi = lo;
4111 }
4422
4423 //------------------------------dump2------------------------------------------
4424 #ifndef PRODUCT
4425 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4426 _ary->dump2(d,depth,st);
4427 switch( _ptr ) {
4428 case Constant:
4429 const_oop()->print(st);
4430 break;
4431 case BotPTR:
4432 if (!WizardMode && !Verbose) {
4433 if( _klass_is_exact ) st->print(":exact");
4434 break;
4435 }
4436 case TopPTR:
4437 case AnyNull:
4438 case NotNull:
4439 st->print(":%s", ptr_msg[_ptr]);
4440 if( _klass_is_exact ) st->print(":exact");
4441 break;
4442 default:
4443 break;
4444 }
4445
4446 if( _offset != 0 ) {
4447 int header_size = objArrayOopDesc::header_size() * wordSize;
4448 if( _offset == OffsetTop ) st->print("+undefined");
4449 else if( _offset == OffsetBot ) st->print("+any");
4450 else if( _offset < header_size ) st->print("+%d", _offset);
4451 else {
4452 BasicType basic_elem_type = elem()->basic_type();
4453 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4454 int elem_size = type2aelembytes(basic_elem_type);
4455 st->print("[%d]", (_offset - array_base)/elem_size);
4456 }
4457 }
4458 st->print(" *");
4459 if (_instance_id == InstanceTop)
4460 st->print(",iid=top");
4461 else if (_instance_id != InstanceBot)
4462 st->print(",iid=%d",_instance_id);
4463
5189 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5190 switch( _ptr ) {
5191 case Constant:
5192 st->print("precise ");
5193 case NotNull:
5194 {
5195 const char *name = klass()->name()->as_utf8();
5196 if( name ) {
5197 st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5198 } else {
5199 ShouldNotReachHere();
5200 }
5201 }
5202 case BotPTR:
5203 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5204 case TopPTR:
5205 case AnyNull:
5206 st->print(":%s", ptr_msg[_ptr]);
5207 if( _klass_is_exact ) st->print(":exact");
5208 break;
5209 default:
5210 break;
5211 }
5212
5213 if( _offset ) { // Dump offset, if any
5214 if( _offset == OffsetBot ) { st->print("+any"); }
5215 else if( _offset == OffsetTop ) { st->print("+unknown"); }
5216 else { st->print("+%d", _offset); }
5217 }
5218
5219 st->print(" *");
5220 }
5221 #endif
5222
5223
5224
5225 //=============================================================================
5226 // Convenience common pre-built types.
5227
5228 //------------------------------make-------------------------------------------
5229 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5230 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
|