< 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   Constant*  ct;
 227 
 228   if ((na = x->array()->as_NewArray()) != NULL) {
 229     // New arrays might have the known length.
 230     // Do not use the Constant itself, but create a new Constant
 231     // with same value Otherwise a Constant is live over multiple
 232     // blocks without being registered in a state array.
 233     Constant* length;
 234     if (na->length() != NULL &&
 235         (length = na->length()->as_Constant()) != NULL) {
 236       assert(length->type()->as_IntConstant() != NULL, "array length must be integer");
 237       set_constant(length->type()->as_IntConstant()->value());
 238     }
 239 
 240   } else if ((ct = x->array()->as_Constant()) != NULL) {
 241     // Constant arrays have constant lengths.
 242     set_constant(ct->type()->as_ArrayConstant()->value()->length());
 243 
 244 #ifdef ASSERT
 245   } else {
 246     LoadField* lf = x->array()->as_LoadField();
 247     bool is_static_constant = (lf != NULL) && lf->field()->is_constant() && lf->field()->is_static();
 248     assert(!is_static_constant, "Constant field loads are folded during parsing");
 249 #endif // ASSERT








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


< prev index next >