< prev index next >

src/share/vm/c1/c1_Canonicalizer.cpp

Print this page




 470 
 471     InstanceConstant* c = x->argument_at(0)->type()->as_InstanceConstant();
 472     if (c != NULL && !c->value()->is_null_object()) {
 473       // ciInstance::java_mirror_type() returns non-NULL only for Java mirrors
 474       ciType* t = c->value()->as_instance()->java_mirror_type();
 475       if (t->is_klass()) {
 476         // substitute cls.isInstance(obj) of a constant Class into
 477         // an InstantOf instruction
 478         InstanceOf* i = new InstanceOf(t->as_klass(), x->argument_at(1), x->state_before());
 479         set_canonical(i);
 480         // and try to canonicalize even further
 481         do_InstanceOf(i);
 482       } else {
 483         assert(t->is_primitive_type(), "should be a primitive type");
 484         // cls.isInstance(obj) always returns false for primitive classes
 485         set_constant(0);
 486       }
 487     }
 488     break;
 489   }











 490   }
 491 }
 492 
 493 void Canonicalizer::do_Convert        (Convert*         x) {
 494   if (x->value()->type()->is_constant()) {
 495     switch (x->op()) {
 496     case Bytecodes::_i2b:  set_constant((int)((x->value()->type()->as_IntConstant()->value() << 24) >> 24)); break;
 497     case Bytecodes::_i2s:  set_constant((int)((x->value()->type()->as_IntConstant()->value() << 16) >> 16)); break;
 498     case Bytecodes::_i2c:  set_constant((int)(x->value()->type()->as_IntConstant()->value() & ((1<<16)-1))); break;
 499     case Bytecodes::_i2l:  set_constant((jlong)(x->value()->type()->as_IntConstant()->value()));             break;
 500     case Bytecodes::_i2f:  set_constant((float)(x->value()->type()->as_IntConstant()->value()));             break;
 501     case Bytecodes::_i2d:  set_constant((double)(x->value()->type()->as_IntConstant()->value()));            break;
 502     case Bytecodes::_l2i:  set_constant((int)(x->value()->type()->as_LongConstant()->value()));              break;
 503     case Bytecodes::_l2f:  set_constant(SharedRuntime::l2f(x->value()->type()->as_LongConstant()->value())); break;
 504     case Bytecodes::_l2d:  set_constant(SharedRuntime::l2d(x->value()->type()->as_LongConstant()->value())); break;
 505     case Bytecodes::_f2d:  set_constant((double)(x->value()->type()->as_FloatConstant()->value()));          break;
 506     case Bytecodes::_f2i:  set_constant(SharedRuntime::f2i(x->value()->type()->as_FloatConstant()->value())); break;
 507     case Bytecodes::_f2l:  set_constant(SharedRuntime::f2l(x->value()->type()->as_FloatConstant()->value())); break;
 508     case Bytecodes::_d2f:  set_constant((float)(x->value()->type()->as_DoubleConstant()->value()));          break;
 509     case Bytecodes::_d2i:  set_constant(SharedRuntime::d2i(x->value()->type()->as_DoubleConstant()->value())); break;




 470 
 471     InstanceConstant* c = x->argument_at(0)->type()->as_InstanceConstant();
 472     if (c != NULL && !c->value()->is_null_object()) {
 473       // ciInstance::java_mirror_type() returns non-NULL only for Java mirrors
 474       ciType* t = c->value()->as_instance()->java_mirror_type();
 475       if (t->is_klass()) {
 476         // substitute cls.isInstance(obj) of a constant Class into
 477         // an InstantOf instruction
 478         InstanceOf* i = new InstanceOf(t->as_klass(), x->argument_at(1), x->state_before());
 479         set_canonical(i);
 480         // and try to canonicalize even further
 481         do_InstanceOf(i);
 482       } else {
 483         assert(t->is_primitive_type(), "should be a primitive type");
 484         // cls.isInstance(obj) always returns false for primitive classes
 485         set_constant(0);
 486       }
 487     }
 488     break;
 489   }
 490   case vmIntrinsics::_isPrimitive        : {
 491     assert(x->number_of_arguments() == 1, "wrong type");
 492 
 493     // Class.isPrimitive is known on constant classes:
 494     InstanceConstant* c = x->argument_at(0)->type()->as_InstanceConstant();
 495     if (c != NULL && !c->value()->is_null_object()) {
 496       ciType* t = c->value()->as_instance()->java_mirror_type();
 497       set_constant(t->is_klass() ? 0 : 1);
 498     }
 499     break;
 500   }
 501   }
 502 }
 503 
 504 void Canonicalizer::do_Convert        (Convert*         x) {
 505   if (x->value()->type()->is_constant()) {
 506     switch (x->op()) {
 507     case Bytecodes::_i2b:  set_constant((int)((x->value()->type()->as_IntConstant()->value() << 24) >> 24)); break;
 508     case Bytecodes::_i2s:  set_constant((int)((x->value()->type()->as_IntConstant()->value() << 16) >> 16)); break;
 509     case Bytecodes::_i2c:  set_constant((int)(x->value()->type()->as_IntConstant()->value() & ((1<<16)-1))); break;
 510     case Bytecodes::_i2l:  set_constant((jlong)(x->value()->type()->as_IntConstant()->value()));             break;
 511     case Bytecodes::_i2f:  set_constant((float)(x->value()->type()->as_IntConstant()->value()));             break;
 512     case Bytecodes::_i2d:  set_constant((double)(x->value()->type()->as_IntConstant()->value()));            break;
 513     case Bytecodes::_l2i:  set_constant((int)(x->value()->type()->as_LongConstant()->value()));              break;
 514     case Bytecodes::_l2f:  set_constant(SharedRuntime::l2f(x->value()->type()->as_LongConstant()->value())); break;
 515     case Bytecodes::_l2d:  set_constant(SharedRuntime::l2d(x->value()->type()->as_LongConstant()->value())); break;
 516     case Bytecodes::_f2d:  set_constant((double)(x->value()->type()->as_FloatConstant()->value()));          break;
 517     case Bytecodes::_f2i:  set_constant(SharedRuntime::f2i(x->value()->type()->as_FloatConstant()->value())); break;
 518     case Bytecodes::_f2l:  set_constant(SharedRuntime::f2l(x->value()->type()->as_FloatConstant()->value())); break;
 519     case Bytecodes::_d2f:  set_constant((float)(x->value()->type()->as_DoubleConstant()->value()));          break;
 520     case Bytecodes::_d2i:  set_constant(SharedRuntime::d2i(x->value()->type()->as_DoubleConstant()->value())); break;


< prev index next >