< prev index next >

src/share/vm/c1/c1_Canonicalizer.cpp

Print this page




 205   Convert* conv = x->value()->as_Convert();
 206   if (conv) {
 207     Value value = NULL;
 208     BasicType type = x->field()->type()->basic_type();
 209     switch (conv->op()) {
 210     case Bytecodes::_i2b: if (type == T_BYTE)  value = conv->value(); break;
 211     case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
 212     case Bytecodes::_i2c: if (type == T_CHAR  || type == T_BYTE)  value = conv->value(); break;
 213     }
 214     // limit this optimization to current block
 215     if (value != NULL && in_current_block(conv)) {
 216       set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(),
 217                                    x->state_before(), x->needs_patching()));
 218       return;
 219     }
 220   }
 221 
 222 }
 223 
 224 void Canonicalizer::do_ArrayLength    (ArrayLength*     x) {
 225   NewArray* array = x->array()->as_NewArray();
 226   if (array != NULL && array->length() != NULL) {
 227     Constant* length = array->length()->as_Constant();
 228     if (length != NULL) {
 229       // do not use the Constant itself, but create a new Constant


 230       // with same value Otherwise a Constant is live over multiple
 231       // blocks without being registered in a state array.



 232       assert(length->type()->as_IntConstant() != NULL, "array length must be integer");
 233       set_constant(length->type()->as_IntConstant()->value());
 234     }
 235   } else {
 236     LoadField* lf = x->array()->as_LoadField();
 237     if (lf != NULL) {


 238       ciField* field = lf->field();
 239       if (field->is_constant() && field->is_static()) {
 240         // final static field
 241         ciObject* c = field->constant_value().as_object();
 242         if (c->is_array()) {
 243           ciArray* array = (ciArray*) c;
 244           set_constant(array->length());
 245         }
 246       }
 247     }



 248   }
 249 }
 250 
 251 void Canonicalizer::do_LoadIndexed    (LoadIndexed*     x) {}
 252 void Canonicalizer::do_StoreIndexed   (StoreIndexed*    x) {
 253   // If a value is going to be stored into a field or array some of
 254   // the conversions emitted by javac are unneeded because the fields
 255   // are packed to their natural size.
 256   Convert* conv = x->value()->as_Convert();
 257   if (conv) {
 258     Value value = NULL;
 259     BasicType type = x->elt_type();
 260     switch (conv->op()) {
 261     case Bytecodes::_i2b: if (type == T_BYTE)  value = conv->value(); break;
 262     case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
 263     case Bytecodes::_i2c: if (type == T_CHAR  || type == T_BYTE) value = conv->value(); break;
 264     }
 265     // limit this optimization to current block
 266     if (value != NULL && in_current_block(conv)) {
 267       set_canonical(new StoreIndexed(x->array(), x->index(), x->length(),




 205   Convert* conv = x->value()->as_Convert();
 206   if (conv) {
 207     Value value = NULL;
 208     BasicType type = x->field()->type()->basic_type();
 209     switch (conv->op()) {
 210     case Bytecodes::_i2b: if (type == T_BYTE)  value = conv->value(); break;
 211     case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
 212     case Bytecodes::_i2c: if (type == T_CHAR  || type == T_BYTE)  value = conv->value(); break;
 213     }
 214     // limit this optimization to current block
 215     if (value != NULL && in_current_block(conv)) {
 216       set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(),
 217                                    x->state_before(), x->needs_patching()));
 218       return;
 219     }
 220   }
 221 
 222 }
 223 
 224 void Canonicalizer::do_ArrayLength    (ArrayLength*     x) {
 225   NewArray*  na;
 226   LoadField* lf;
 227   Constant*  ct;
 228 
 229   if ((na = x->array()->as_NewArray()) != NULL) {
 230     // New arrays might have the known length.
 231     // Do not use the Constant itself, but create a new Constant
 232     // with same value Otherwise a Constant is live over multiple
 233     // blocks without being registered in a state array.
 234     Constant* length;
 235     if (na->length() != NULL &&
 236         (length = na->length()->as_Constant()) != NULL) {
 237       assert(length->type()->as_IntConstant() != NULL, "array length must be integer");
 238       set_constant(length->type()->as_IntConstant()->value());
 239     }
 240 
 241   } else if ((lf = x->array()->as_LoadField()) != NULL) {
 242     // Arrays loaded from static final fields have statically known
 243     // length. Many static final loads can come in Constant form,
 244     // that are handled below.
 245     ciField* field = lf->field();
 246     if (field->is_constant() && field->is_static()) {
 247       // final static field
 248       ciObject* c = field->constant_value().as_object();
 249       if (c->is_array()) {
 250         ciArray* array = (ciArray*) c;
 251         set_constant(array->length());
 252       }
 253     }
 254 
 255   } else if ((ct = x->array()->as_Constant()) != NULL) {
 256     // Constant arrays have constant lengths.
 257     set_constant(ct->type()->as_ArrayConstant()->value()->length());
 258   }
 259 }
 260 
 261 void Canonicalizer::do_LoadIndexed    (LoadIndexed*     x) {}
 262 void Canonicalizer::do_StoreIndexed   (StoreIndexed*    x) {
 263   // If a value is going to be stored into a field or array some of
 264   // the conversions emitted by javac are unneeded because the fields
 265   // are packed to their natural size.
 266   Convert* conv = x->value()->as_Convert();
 267   if (conv) {
 268     Value value = NULL;
 269     BasicType type = x->elt_type();
 270     switch (conv->op()) {
 271     case Bytecodes::_i2b: if (type == T_BYTE)  value = conv->value(); break;
 272     case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
 273     case Bytecodes::_i2c: if (type == T_CHAR  || type == T_BYTE) value = conv->value(); break;
 274     }
 275     // limit this optimization to current block
 276     if (value != NULL && in_current_block(conv)) {
 277       set_canonical(new StoreIndexed(x->array(), x->index(), x->length(),


< prev index next >