use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class BC2IR method generateFrom.
/**
* Generate instructions for a basic block.
* May discover other basic blocks that need to be generated along the way.
*
* @param fromIndex bytecode index to start from
*/
private void generateFrom(int fromIndex) {
if (DBG_BB || DBG_SELECTED) {
db("generating code into " + currentBBLE + " with runoff " + runoff);
}
currentBBLE.setGenerated();
endOfBasicBlock = fallThrough = false;
lastInstr = null;
bcodes.reset(fromIndex);
while (true) {
// Must keep currentBBLE.high up-to-date in case we try to jump into
// the middle of the block we're currently generating. Simply updating
// high once endsBasicBlock is true doesn't enable us to catch this case.
currentBBLE.high = instrIndex = bcodes.index();
int code = bcodes.nextInstruction();
if (DBG_BCPARSE) {
db("parsing " + instrIndex + " " + code + " : 0x" + Integer.toHexString(code) + " " + JBC_name(code));
}
Instruction s = null;
lastOsrBarrier = null;
switch(code) {
case JBC_nop:
break;
case JBC_aconst_null:
push(new NullConstantOperand());
break;
case JBC_iconst_m1:
case JBC_iconst_0:
case JBC_iconst_1:
case JBC_iconst_2:
case JBC_iconst_3:
case JBC_iconst_4:
case JBC_iconst_5:
push(new IntConstantOperand(code - JBC_iconst_0));
break;
case JBC_lconst_0:
case JBC_lconst_1:
pushDual(new LongConstantOperand(code - JBC_lconst_0));
break;
case JBC_fconst_0:
push(new FloatConstantOperand(0.f));
break;
case JBC_fconst_1:
push(new FloatConstantOperand(1.f));
break;
case JBC_fconst_2:
push(new FloatConstantOperand(2.f));
break;
case JBC_dconst_0:
pushDual(new DoubleConstantOperand(0.));
break;
case JBC_dconst_1:
pushDual(new DoubleConstantOperand(1.));
break;
case JBC_bipush:
push(new IntConstantOperand(bcodes.getByteValue()));
break;
case JBC_sipush:
push(new IntConstantOperand(bcodes.getShortValue()));
break;
case JBC_ldc:
push(getConstantOperand(bcodes.getConstantIndex()));
break;
case JBC_ldc_w:
push(getConstantOperand(bcodes.getWideConstantIndex()));
break;
case JBC_ldc2_w:
pushDual(getConstantOperand(bcodes.getWideConstantIndex()));
break;
case JBC_iload:
s = do_iload(bcodes.getLocalNumber());
break;
case JBC_lload:
s = do_lload(bcodes.getLocalNumber());
break;
case JBC_fload:
s = do_fload(bcodes.getLocalNumber());
break;
case JBC_dload:
s = do_dload(bcodes.getLocalNumber());
break;
case JBC_aload:
s = do_aload(bcodes.getLocalNumber());
break;
case JBC_iload_0:
case JBC_iload_1:
case JBC_iload_2:
case JBC_iload_3:
s = do_iload(code - JBC_iload_0);
break;
case JBC_lload_0:
case JBC_lload_1:
case JBC_lload_2:
case JBC_lload_3:
s = do_lload(code - JBC_lload_0);
break;
case JBC_fload_0:
case JBC_fload_1:
case JBC_fload_2:
case JBC_fload_3:
s = do_fload(code - JBC_fload_0);
break;
case JBC_dload_0:
case JBC_dload_1:
case JBC_dload_2:
case JBC_dload_3:
s = do_dload(code - JBC_dload_0);
break;
case JBC_aload_0:
case JBC_aload_1:
case JBC_aload_2:
case JBC_aload_3:
s = do_aload(code - JBC_aload_0);
break;
case JBC_iaload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.IntArray);
}
s = _aloadHelper(INT_ALOAD, ref, index, TypeReference.Int);
}
break;
case JBC_laload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.LongArray);
}
s = _aloadHelper(LONG_ALOAD, ref, index, TypeReference.Long);
}
break;
case JBC_faload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.FloatArray);
}
s = _aloadHelper(FLOAT_ALOAD, ref, index, TypeReference.Float);
}
break;
case JBC_daload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.DoubleArray);
}
s = _aloadHelper(DOUBLE_ALOAD, ref, index, TypeReference.Double);
}
break;
case JBC_aaload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
TypeReference type = getRefTypeOf(ref).getArrayElementType();
if (VM.VerifyAssertions)
opt_assert(type.isReferenceType());
s = _aloadHelper(REF_ALOAD, ref, index, type);
}
break;
case JBC_baload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
TypeReference type = getArrayTypeOf(ref);
if (VM.VerifyAssertions) {
opt_assert(type == TypeReference.ByteArray || type == TypeReference.BooleanArray);
}
if (type == TypeReference.ByteArray) {
s = _aloadHelper(BYTE_ALOAD, ref, index, TypeReference.Byte);
} else {
s = _aloadHelper(UBYTE_ALOAD, ref, index, TypeReference.Boolean);
}
}
break;
case JBC_caload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.CharArray);
}
s = _aloadHelper(USHORT_ALOAD, ref, index, TypeReference.Char);
}
break;
case JBC_saload:
{
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.ShortArray);
}
s = _aloadHelper(SHORT_ALOAD, ref, index, TypeReference.Short);
}
break;
case JBC_istore:
s = do_store(bcodes.getLocalNumber(), popInt());
break;
case JBC_lstore:
s = do_store(bcodes.getLocalNumber(), popLong());
break;
case JBC_fstore:
s = do_store(bcodes.getLocalNumber(), popFloat());
break;
case JBC_dstore:
s = do_store(bcodes.getLocalNumber(), popDouble());
break;
case JBC_astore:
s = do_astore(bcodes.getLocalNumber());
break;
case JBC_istore_0:
case JBC_istore_1:
case JBC_istore_2:
case JBC_istore_3:
s = do_store(code - JBC_istore_0, popInt());
break;
case JBC_lstore_0:
case JBC_lstore_1:
case JBC_lstore_2:
case JBC_lstore_3:
s = do_store(code - JBC_lstore_0, popLong());
break;
case JBC_fstore_0:
case JBC_fstore_1:
case JBC_fstore_2:
case JBC_fstore_3:
s = do_store(code - JBC_fstore_0, popFloat());
break;
case JBC_dstore_0:
case JBC_dstore_1:
case JBC_dstore_2:
case JBC_dstore_3:
s = do_store(code - JBC_dstore_0, popDouble());
break;
case JBC_astore_0:
case JBC_astore_1:
case JBC_astore_2:
case JBC_astore_3:
s = do_astore(code - JBC_astore_0);
break;
case JBC_iastore:
{
Operand val = popInt();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.IntArray);
}
s = AStore.create(INT_ASTORE, val, ref, index, new LocationOperand(TypeReference.Int), getCurrentGuard());
}
break;
case JBC_lastore:
{
Operand val = popLong();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.LongArray);
}
s = AStore.create(LONG_ASTORE, val, ref, index, new LocationOperand(TypeReference.Long), getCurrentGuard());
}
break;
case JBC_fastore:
{
Operand val = popFloat();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.FloatArray);
}
s = AStore.create(FLOAT_ASTORE, val, ref, index, new LocationOperand(TypeReference.Float), getCurrentGuard());
}
break;
case JBC_dastore:
{
Operand val = popDouble();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.DoubleArray);
}
s = AStore.create(DOUBLE_ASTORE, val, ref, index, new LocationOperand(TypeReference.Double), getCurrentGuard());
}
break;
case JBC_aastore:
{
Operand val = pop();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
TypeReference type = getRefTypeOf(ref).getArrayElementType();
if (VM.VerifyAssertions)
opt_assert(type.isReferenceType());
if (do_CheckStore(ref, val, type)) {
break;
}
s = AStore.create(REF_ASTORE, val, ref, index, new LocationOperand(type), getCurrentGuard());
}
break;
case JBC_bastore:
{
Operand val = popInt();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
TypeReference type = getArrayTypeOf(ref);
if (VM.VerifyAssertions) {
opt_assert(type == TypeReference.ByteArray || type == TypeReference.BooleanArray);
}
if (type == TypeReference.ByteArray) {
type = TypeReference.Byte;
} else {
type = TypeReference.Boolean;
}
s = AStore.create(BYTE_ASTORE, val, ref, index, new LocationOperand(type), getCurrentGuard());
}
break;
case JBC_castore:
{
Operand val = popInt();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.CharArray);
}
s = AStore.create(SHORT_ASTORE, val, ref, index, new LocationOperand(TypeReference.Char), getCurrentGuard());
}
break;
case JBC_sastore:
{
Operand val = popInt();
Operand index = popInt();
Operand ref = pop();
clearCurrentGuard();
if (do_NullCheck(ref) || do_BoundsCheck(ref, index)) {
break;
}
if (VM.VerifyAssertions) {
assertIsType(ref, TypeReference.ShortArray);
}
s = AStore.create(SHORT_ASTORE, val, ref, index, new LocationOperand(TypeReference.Short), getCurrentGuard());
}
break;
case JBC_pop:
stack.pop();
break;
case JBC_pop2:
stack.pop2();
break;
case JBC_dup:
{
Operand op1 = stack.pop();
stack.push(op1);
s = pushCopy(op1);
}
break;
case JBC_dup_x1:
{
Operand op1 = stack.pop();
Operand op2 = stack.pop();
stack.push(op1);
stack.push(op2);
s = pushCopy(op1);
}
break;
case JBC_dup_x2:
{
Operand op1 = stack.pop();
Operand op2 = stack.pop();
Operand op3 = stack.pop();
stack.push(op1);
stack.push(op3);
stack.push(op2);
s = pushCopy(op1);
}
break;
case JBC_dup2:
{
Operand op1 = stack.pop();
Operand op2 = stack.pop();
stack.push(op2);
stack.push(op1);
s = pushCopy(op2);
if (s != null) {
appendInstruction(s);
s = null;
}
s = pushCopy(op1);
}
break;
case JBC_dup2_x1:
{
Operand op1 = stack.pop();
Operand op2 = stack.pop();
Operand op3 = stack.pop();
stack.push(op2);
stack.push(op1);
stack.push(op3);
s = pushCopy(op2);
if (s != null) {
appendInstruction(s);
s = null;
}
s = pushCopy(op1);
}
break;
case JBC_dup2_x2:
{
Operand op1 = stack.pop();
Operand op2 = stack.pop();
Operand op3 = stack.pop();
Operand op4 = stack.pop();
stack.push(op2);
stack.push(op1);
stack.push(op4);
stack.push(op3);
s = pushCopy(op2);
if (s != null) {
appendInstruction(s);
s = null;
}
s = pushCopy(op1);
}
break;
case JBC_swap:
{
stack.swap();
}
break;
case JBC_iadd:
{
Operand op2 = popInt();
Operand op1 = popInt();
s = _binaryHelper(INT_ADD, op1, op2, TypeReference.Int);
}
break;
case JBC_ladd:
{
Operand op2 = popLong();
Operand op1 = popLong();
s = _binaryDualHelper(LONG_ADD, op1, op2, TypeReference.Long);
}
break;
case JBC_fadd:
{
Operand op2 = popFloat();
Operand op1 = popFloat();
s = _binaryHelper(FLOAT_ADD, op1, op2, TypeReference.Float);
}
break;
case JBC_dadd:
{
Operand op2 = popDouble();
Operand op1 = popDouble();
s = _binaryDualHelper(DOUBLE_ADD, op1, op2, TypeReference.Double);
}
break;
case JBC_isub:
{
Operand op2 = popInt();
Operand op1 = popInt();
s = _binaryHelper(INT_SUB, op1, op2, TypeReference.Int);
}
break;
case JBC_lsub:
{
Operand op2 = popLong();
Operand op1 = popLong();
s = _binaryDualHelper(LONG_SUB, op1, op2, TypeReference.Long);
}
break;
case JBC_fsub:
{
Operand op2 = popFloat();
Operand op1 = popFloat();
s = _binaryHelper(FLOAT_SUB, op1, op2, TypeReference.Float);
}
break;
case JBC_dsub:
{
Operand op2 = popDouble();
Operand op1 = popDouble();
s = _binaryDualHelper(DOUBLE_SUB, op1, op2, TypeReference.Double);
}
break;
case JBC_imul:
{
Operand op2 = popInt();
Operand op1 = popInt();
s = _binaryHelper(INT_MUL, op1, op2, TypeReference.Int);
}
break;
case JBC_lmul:
{
Operand op2 = popLong();
Operand op1 = popLong();
s = _binaryDualHelper(LONG_MUL, op1, op2, TypeReference.Long);
}
break;
case JBC_fmul:
{
Operand op2 = popFloat();
Operand op1 = popFloat();
s = _binaryHelper(FLOAT_MUL, op1, op2, TypeReference.Float);
}
break;
case JBC_dmul:
{
Operand op2 = popDouble();
Operand op1 = popDouble();
s = _binaryDualHelper(DOUBLE_MUL, op1, op2, TypeReference.Double);
}
break;
case JBC_idiv:
{
clearCurrentGuard();
Operand op2 = popInt();
Operand op1 = popInt();
if (do_IntZeroCheck(op2)) {
break;
}
s = _guardedBinaryHelper(INT_DIV, op1, op2, getCurrentGuard(), TypeReference.Int);
}
break;
case JBC_ldiv:
{
clearCurrentGuard();
Operand op2 = popLong();
Operand op1 = popLong();
if (do_LongZeroCheck(op2)) {
break;
}
s = _guardedBinaryDualHelper(LONG_DIV, op1, op2, getCurrentGuard(), TypeReference.Long);
}
break;
case JBC_fdiv:
{
Operand op2 = popFloat();
Operand op1 = popFloat();
s = _binaryHelper(FLOAT_DIV, op1, op2, TypeReference.Float);
}
break;
case JBC_ddiv:
{
Operand op2 = popDouble();
Operand op1 = popDouble();
s = _binaryDualHelper(DOUBLE_DIV, op1, op2, TypeReference.Double);
}
break;
case JBC_irem:
{
clearCurrentGuard();
Operand op2 = popInt();
Operand op1 = popInt();
if (do_IntZeroCheck(op2)) {
break;
}
s = _guardedBinaryHelper(INT_REM, op1, op2, getCurrentGuard(), TypeReference.Int);
}
break;
case JBC_lrem:
{
clearCurrentGuard();
Operand op2 = popLong();
Operand op1 = popLong();
if (do_LongZeroCheck(op2)) {
break;
}
s = _guardedBinaryDualHelper(LONG_REM, op1, op2, getCurrentGuard(), TypeReference.Long);
}
break;
case JBC_frem:
{
Operand op2 = popFloat();
Operand op1 = popFloat();
s = _binaryHelper(FLOAT_REM, op1, op2, TypeReference.Float);
}
break;
case JBC_drem:
{
Operand op2 = popDouble();
Operand op1 = popDouble();
s = _binaryDualHelper(DOUBLE_REM, op1, op2, TypeReference.Double);
}
break;
case JBC_ineg:
s = _unaryHelper(INT_NEG, popInt(), TypeReference.Int);
break;
case JBC_lneg:
s = _unaryDualHelper(LONG_NEG, popLong(), TypeReference.Long);
break;
case JBC_fneg:
s = _unaryHelper(FLOAT_NEG, popFloat(), TypeReference.Float);
break;
case JBC_dneg:
s = _unaryDualHelper(DOUBLE_NEG, popDouble(), TypeReference.Double);
break;
case JBC_ishl:
{
Operand op2 = popShiftInt(false);
Operand op1 = popInt();
s = _binaryHelper(INT_SHL, op1, op2, TypeReference.Int);
}
break;
case JBC_lshl:
{
Operand op2 = popShiftInt(true);
Operand op1 = popLong();
s = _binaryDualHelper(LONG_SHL, op1, op2, TypeReference.Long);
}
break;
case JBC_ishr:
{
Operand op2 = popShiftInt(false);
Operand op1 = popInt();
s = _binaryHelper(INT_SHR, op1, op2, TypeReference.Int);
}
break;
case JBC_lshr:
{
Operand op2 = popShiftInt(true);
Operand op1 = popLong();
s = _binaryDualHelper(LONG_SHR, op1, op2, TypeReference.Long);
}
break;
case JBC_iushr:
{
Operand op2 = popShiftInt(false);
Operand op1 = popInt();
s = _binaryHelper(INT_USHR, op1, op2, TypeReference.Int);
}
break;
case JBC_lushr:
{
Operand op2 = popShiftInt(true);
Operand op1 = popLong();
s = _binaryDualHelper(LONG_USHR, op1, op2, TypeReference.Long);
}
break;
case JBC_iand:
{
Operand op2 = popInt();
Operand op1 = popInt();
s = _binaryHelper(INT_AND, op1, op2, TypeReference.Int);
}
break;
case JBC_land:
{
Operand op2 = popLong();
Operand op1 = popLong();
s = _binaryDualHelper(LONG_AND, op1, op2, TypeReference.Long);
}
break;
case JBC_ior:
{
Operand op2 = popInt();
Operand op1 = popInt();
s = _binaryHelper(INT_OR, op1, op2, TypeReference.Int);
}
break;
case JBC_lor:
{
Operand op2 = popLong();
Operand op1 = popLong();
s = _binaryDualHelper(LONG_OR, op1, op2, TypeReference.Long);
}
break;
case JBC_ixor:
{
Operand op2 = popInt();
Operand op1 = popInt();
s = _binaryHelper(INT_XOR, op1, op2, TypeReference.Int);
}
break;
case JBC_lxor:
{
Operand op2 = popLong();
Operand op1 = popLong();
s = _binaryDualHelper(LONG_XOR, op1, op2, TypeReference.Long);
}
break;
case JBC_iinc:
{
int index = bcodes.getLocalNumber();
s = do_iinc(index, bcodes.getIncrement());
}
break;
case JBC_i2l:
s = _unaryDualHelper(INT_2LONG, popInt(), TypeReference.Long);
break;
case JBC_i2f:
s = _unaryHelper(INT_2FLOAT, popInt(), TypeReference.Float);
break;
case JBC_i2d:
s = _unaryDualHelper(INT_2DOUBLE, popInt(), TypeReference.Double);
break;
case JBC_l2i:
s = _unaryHelper(LONG_2INT, popLong(), TypeReference.Int);
break;
case JBC_l2f:
s = _unaryHelper(LONG_2FLOAT, popLong(), TypeReference.Float);
break;
case JBC_l2d:
s = _unaryDualHelper(LONG_2DOUBLE, popLong(), TypeReference.Double);
break;
case JBC_f2i:
s = _unaryHelper(FLOAT_2INT, popFloat(), TypeReference.Int);
break;
case JBC_f2l:
s = _unaryDualHelper(FLOAT_2LONG, popFloat(), TypeReference.Long);
break;
case JBC_f2d:
s = _unaryDualHelper(FLOAT_2DOUBLE, popFloat(), TypeReference.Double);
break;
case JBC_d2i:
s = _unaryHelper(DOUBLE_2INT, popDouble(), TypeReference.Int);
break;
case JBC_d2l:
s = _unaryDualHelper(DOUBLE_2LONG, popDouble(), TypeReference.Long);
break;
case JBC_d2f:
s = _unaryHelper(DOUBLE_2FLOAT, popDouble(), TypeReference.Float);
break;
case JBC_int2byte:
s = _unaryHelper(INT_2BYTE, popInt(), TypeReference.Byte);
break;
case JBC_int2char:
s = _unaryHelper(INT_2USHORT, popInt(), TypeReference.Char);
break;
case JBC_int2short:
s = _unaryHelper(INT_2SHORT, popInt(), TypeReference.Short);
break;
case JBC_lcmp:
{
Operand op2 = popLong();
Operand op1 = popLong();
s = _binaryHelper(LONG_CMP, op1, op2, TypeReference.Int);
}
break;
case JBC_fcmpl:
{
Operand op2 = popFloat();
Operand op1 = popFloat();
s = _binaryHelper(FLOAT_CMPL, op1, op2, TypeReference.Int);
}
break;
case JBC_fcmpg:
{
Operand op2 = popFloat();
Operand op1 = popFloat();
s = _binaryHelper(FLOAT_CMPG, op1, op2, TypeReference.Int);
}
break;
case JBC_dcmpl:
{
Operand op2 = popDouble();
Operand op1 = popDouble();
s = _binaryHelper(DOUBLE_CMPL, op1, op2, TypeReference.Int);
}
break;
case JBC_dcmpg:
{
Operand op2 = popDouble();
Operand op1 = popDouble();
s = _binaryHelper(DOUBLE_CMPG, op1, op2, TypeReference.Int);
}
break;
case JBC_ifeq:
s = _intIfHelper(ConditionOperand.EQUAL());
break;
case JBC_ifne:
s = _intIfHelper(ConditionOperand.NOT_EQUAL());
break;
case JBC_iflt:
s = _intIfHelper(ConditionOperand.LESS());
break;
case JBC_ifge:
s = _intIfHelper(ConditionOperand.GREATER_EQUAL());
break;
case JBC_ifgt:
s = _intIfHelper(ConditionOperand.GREATER());
break;
case JBC_ifle:
s = _intIfHelper(ConditionOperand.LESS_EQUAL());
break;
case JBC_if_icmpeq:
s = _intIfCmpHelper(ConditionOperand.EQUAL());
break;
case JBC_if_icmpne:
s = _intIfCmpHelper(ConditionOperand.NOT_EQUAL());
break;
case JBC_if_icmplt:
s = _intIfCmpHelper(ConditionOperand.LESS());
break;
case JBC_if_icmpge:
s = _intIfCmpHelper(ConditionOperand.GREATER_EQUAL());
break;
case JBC_if_icmpgt:
s = _intIfCmpHelper(ConditionOperand.GREATER());
break;
case JBC_if_icmple:
s = _intIfCmpHelper(ConditionOperand.LESS_EQUAL());
break;
case JBC_if_acmpeq:
s = _refIfCmpHelper(ConditionOperand.EQUAL());
break;
case JBC_if_acmpne:
s = _refIfCmpHelper(ConditionOperand.NOT_EQUAL());
break;
case JBC_goto:
{
int offset = bcodes.getBranchOffset();
if (offset != 3) {
// skip generating frivolous goto's
s = _gotoHelper(offset);
}
}
break;
case JBC_jsr:
s = _jsrHelper(bcodes.getBranchOffset());
break;
case JBC_ret:
s = _retHelper(bcodes.getLocalNumber());
break;
case JBC_tableswitch:
{
bcodes.alignSwitch();
Operand op0 = popInt();
int defaultoff = bcodes.getDefaultSwitchOffset();
int low = bcodes.getLowSwitchValue();
int high = bcodes.getHighSwitchValue();
int number = high - low + 1;
if (CF_TABLESWITCH && op0 instanceof IntConstantOperand) {
int v1 = ((IntConstantOperand) op0).value;
int match = bcodes.computeTableSwitchOffset(v1, low, high);
int offset = match == 0 ? defaultoff : match;
bcodes.skipTableSwitchOffsets(number);
if (DBG_CF) {
db("changed tableswitch to goto because index (" + v1 + ") is constant");
}
s = _gotoHelper(offset);
break;
}
s = TableSwitch.create(TABLESWITCH, op0, null, null, new IntConstantOperand(low), new IntConstantOperand(high), generateTarget(defaultoff), null, number * 2);
for (int i = 0; i < number; ++i) {
TableSwitch.setTarget(s, i, generateTarget(bcodes.getTableSwitchOffset(i)));
}
bcodes.skipTableSwitchOffsets(number);
// Set branch probabilities
SwitchBranchProfile sp = gc.getSwitchProfile(instrIndex - bciAdjustment);
if (sp == null) {
// number targets + default
float approxProb = 1.0f / (number + 1);
TableSwitch.setDefaultBranchProfile(s, new BranchProfileOperand(approxProb));
for (int i = 0; i < number; ++i) {
TableSwitch.setBranchProfile(s, i, new BranchProfileOperand(approxProb));
}
} else {
TableSwitch.setDefaultBranchProfile(s, new BranchProfileOperand(sp.getDefaultProbability()));
for (int i = 0; i < number; ++i) {
TableSwitch.setBranchProfile(s, i, new BranchProfileOperand(sp.getCaseProbability(i)));
}
}
}
break;
case JBC_lookupswitch:
{
bcodes.alignSwitch();
Operand op0 = popInt();
int defaultoff = bcodes.getDefaultSwitchOffset();
int numpairs = bcodes.getSwitchLength();
if (numpairs == 0) {
s = _gotoHelper(defaultoff);
break;
}
if (CF_LOOKUPSWITCH && op0 instanceof IntConstantOperand) {
int v1 = ((IntConstantOperand) op0).value;
int match = bcodes.computeLookupSwitchOffset(v1, numpairs);
int offset = match == 0 ? defaultoff : match;
bcodes.skipLookupSwitchPairs(numpairs);
if (DBG_CF) {
db("changed lookupswitch to goto because index (" + v1 + ") is constant");
}
s = _gotoHelper(offset);
break;
}
// Construct switch
s = LookupSwitch.create(LOOKUPSWITCH, op0, null, null, generateTarget(defaultoff), null, numpairs * 3);
for (int i = 0; i < numpairs; ++i) {
LookupSwitch.setMatch(s, i, new IntConstantOperand(bcodes.getLookupSwitchValue(i)));
LookupSwitch.setTarget(s, i, generateTarget(bcodes.getLookupSwitchOffset(i)));
}
bcodes.skipLookupSwitchPairs(numpairs);
// Set branch probabilities
SwitchBranchProfile sp = gc.getSwitchProfile(instrIndex - bciAdjustment);
if (sp == null) {
// num targets + default
float approxProb = 1.0f / (numpairs + 1);
LookupSwitch.setDefaultBranchProfile(s, new BranchProfileOperand(approxProb));
for (int i = 0; i < numpairs; ++i) {
LookupSwitch.setBranchProfile(s, i, new BranchProfileOperand(approxProb));
}
} else {
LookupSwitch.setDefaultBranchProfile(s, new BranchProfileOperand(sp.getDefaultProbability()));
for (int i = 0; i < numpairs; ++i) {
LookupSwitch.setBranchProfile(s, i, new BranchProfileOperand(sp.getCaseProbability(i)));
}
}
}
break;
case JBC_ireturn:
_returnHelper(INT_MOVE, popInt());
break;
case JBC_lreturn:
_returnHelper(LONG_MOVE, popLong());
break;
case JBC_freturn:
_returnHelper(FLOAT_MOVE, popFloat());
break;
case JBC_dreturn:
_returnHelper(DOUBLE_MOVE, popDouble());
break;
case JBC_areturn:
{
Operand op0 = popRef();
if (VM.VerifyAssertions && !op0.isDefinitelyNull()) {
TypeReference retType = op0.getType();
assertIsAssignable(gc.getMethod().getReturnType(), retType);
}
_returnHelper(REF_MOVE, op0);
}
break;
case JBC_return:
_returnHelper(null, null);
break;
case JBC_getstatic:
{
// field resolution
FieldReference ref = bcodes.getFieldReference();
boolean unresolved = ref.needsDynamicLink(bcodes.getMethod());
LocationOperand fieldOp = makeStaticFieldRef(ref);
Operand offsetOp;
TypeReference fieldType = ref.getFieldContentsType();
RegisterOperand t = gc.getTemps().makeTemp(fieldType);
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), fieldOp.copy()));
offsetOp = offsetrop;
rectifyStateWithErrorHandler();
} else {
RVMField field = ref.peekResolvedField();
offsetOp = new AddressConstantOperand(field.getOffset());
// use results of field analysis to refine type of result
RVMType ft = fieldType.peekType();
if (ft != null && ft.isClassType()) {
TypeReference concreteType = FieldAnalysis.getConcreteType(field);
if (concreteType != null) {
if (concreteType == fieldType) {
t.setDeclaredType();
t.setPreciseType();
} else {
fieldType = concreteType;
t.setPreciseType(concreteType);
}
}
}
// time.
if (gc.getOptions().SIMPLIFY_CHASE_FINAL_FIELDS && field.isFinal()) {
RVMClass declaringClass = field.getDeclaringClass();
boolean initializedClassAtRuntime = VM.runningVM & declaringClass.isInitialized();
boolean fieldFromRVMInternalClassInBootImage = declaringClass.isInBootImage() && declaringClass.getDescriptor().isRVMDescriptor();
// We cannot assume that non-public fields from the host JVM's class library are present in
// the class library used by Jikes RVM: only public fields are part of the API.
boolean publicFieldInBootImage = declaringClass.isInBootImage() && field.isPublic();
if (initializedClassAtRuntime || fieldFromRVMInternalClassInBootImage || publicFieldInBootImage) {
try {
ConstantOperand rhs = StaticFieldReader.getStaticFieldValue(field);
// VM.sysWriteln("Replaced getstatic of " + field + " with " + rhs);
push(rhs, fieldType);
break;
} catch (NoSuchFieldException e) {
if (VM.runningVM) {
throw new Error("Unexpected exception", e);
} else {
// Field not found during bootstrap due to chasing a field
// only valid in the bootstrap JVM.
// Although we try to avoid most cases where this could happen, we cannot
// avoid all. For example, a NoSuchFieldException can occur when we're trying
// to optimize a public field from Jikes RVM's class library that's not present
// in the host JVM's class library (example: a field from an internal
// helper class).
}
}
}
} else if (field.isRuntimeFinal()) {
if (VM.VerifyAssertions)
opt_assert(fieldType.isBooleanType());
boolean rhsBool = field.getRuntimeFinalValue();
push(new IntConstantOperand(rhsBool ? 1 : 0));
break;
}
}
s = GetStatic.create(GETSTATIC, t, offsetOp, fieldOp);
if (fieldOp.mayBeVolatile()) {
appendInstruction(s);
s = Empty.create(READ_CEILING);
}
push(t.copyD2U(), fieldType);
}
break;
case JBC_putstatic:
{
// field resolution
FieldReference ref = bcodes.getFieldReference();
boolean unresolved = ref.needsDynamicLink(bcodes.getMethod());
LocationOperand fieldOp = makeStaticFieldRef(ref);
Operand offsetOp;
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), fieldOp.copy()));
offsetOp = offsetrop;
rectifyStateWithErrorHandler();
} else {
RVMField field = ref.peekResolvedField();
offsetOp = new AddressConstantOperand(field.getOffset());
}
TypeReference fieldType = ref.getFieldContentsType();
Operand r = pop(fieldType);
if (fieldOp.mayBeVolatile()) {
appendInstruction(Empty.create(WRITE_FLOOR));
}
s = PutStatic.create(PUTSTATIC, r, offsetOp, fieldOp);
if (fieldOp.mayBeVolatile()) {
appendInstruction(s);
s = Empty.create(FENCE);
}
}
break;
case JBC_getfield:
{
// field resolution
FieldReference ref = bcodes.getFieldReference();
boolean unresolved = ref.needsDynamicLink(bcodes.getMethod());
LocationOperand fieldOp = makeInstanceFieldRef(ref);
Operand offsetOp;
TypeReference fieldType = ref.getFieldContentsType();
RVMField field = null;
RegisterOperand t = gc.getTemps().makeTemp(fieldType);
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), fieldOp.copy()));
offsetOp = offsetrop;
rectifyStateWithErrorHandler();
} else {
field = ref.peekResolvedField();
offsetOp = new AddressConstantOperand(field.getOffset());
// use results of field analysis to refine type.
RVMType ft = fieldType.peekType();
if (ft != null && ft.isClassType()) {
TypeReference concreteType = FieldAnalysis.getConcreteType(field);
if (concreteType != null) {
if (concreteType == fieldType) {
t.setDeclaredType();
t.setPreciseType();
} else {
fieldType = concreteType;
t.setType(concreteType);
t.setPreciseType();
}
}
}
}
Operand op1 = pop();
clearCurrentGuard();
if (do_NullCheck(op1)) {
break;
}
// NB avoid String fields
if (op1.isConstant() && field.isFinal()) {
try {
ConstantOperand rhs = StaticFieldReader.getFieldValueAsConstant(field, op1.asObjectConstant().value);
push(rhs, fieldType);
break;
} catch (NoSuchFieldException e) {
if (VM.runningVM) {
// this is unexpected
throw new Error("Unexpected exception", e);
} else {
// Field not found during bootstrap due to chasing a field
// only valid in the bootstrap JVM
}
}
}
s = GetField.create(GETFIELD, t, op1, offsetOp, fieldOp, getCurrentGuard());
if (fieldOp.mayBeVolatile()) {
appendInstruction(s);
s = Empty.create(READ_CEILING);
}
push(t.copyD2U(), fieldType);
}
break;
case JBC_putfield:
{
// field resolution
FieldReference ref = bcodes.getFieldReference();
boolean unresolved = ref.needsDynamicLink(bcodes.getMethod());
LocationOperand fieldOp = makeInstanceFieldRef(ref);
TypeReference fieldType = ref.getFieldContentsType();
Operand offsetOp;
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), fieldOp.copy()));
offsetOp = offsetrop;
rectifyStateWithErrorHandler();
} else {
RVMField field = ref.peekResolvedField();
offsetOp = new AddressConstantOperand(field.getOffset());
}
Operand val = pop(fieldType);
Operand obj = popRef();
clearCurrentGuard();
if (do_NullCheck(obj)) {
break;
}
if (fieldOp.mayBeVolatile()) {
appendInstruction(Empty.create(WRITE_FLOOR));
}
s = PutField.create(PUTFIELD, val, obj, offsetOp, fieldOp, getCurrentGuard());
if (fieldOp.mayBeVolatile()) {
appendInstruction(s);
s = Empty.create(FENCE);
}
}
break;
case JBC_invokevirtual:
{
MethodReference ref = bcodes.getMethodReference();
// If it is, generate the inline code and we are done.
if (ref.isMagic()) {
boolean generated = GenerateMagic.generateMagic(this, gc, ref);
// all done.
if (generated)
break;
}
/* just create an osr barrier right before _callHelper
* changes the states of locals and stacks.
*/
if (this.osrGuardedInline) {
lastOsrBarrier = _createOsrBarrier();
}
if (ref.isMiranda()) {
// An invokevirtual that is really an invokeinterface.
s = _callHelper(ref, MethodOperand.INTERFACE(ref, null));
if (s == null)
break;
Operand receiver = Call.getParam(s, 0);
RVMClass receiverType = (RVMClass) receiver.getType().peekType();
// null check on this parameter of call
clearCurrentGuard();
if (do_NullCheck(receiver)) {
// call will always raise null pointer exception
s = null;
break;
}
Call.setGuard(s, getCurrentGuard());
// Attempt to resolve the interface call to a particular virtual method.
// This is independent of whether or not the static type of the receiver is
// known to implement the interface and it is not that case that being able
// to prove one implies the other.
RVMMethod vmeth = null;
if (receiverType != null && receiverType.isInitialized() && !receiverType.isInterface()) {
vmeth = ClassLoaderProxy.lookupMethod(receiverType, ref);
}
if (vmeth != null) {
MethodReference vmethRef = vmeth.getMemberRef().asMethodReference();
MethodOperand mop = MethodOperand.VIRTUAL(vmethRef, vmeth);
if (receiver.isConstant() || (receiver.isRegister() && receiver.asRegister().isPreciseType())) {
mop.refine(vmeth, true);
}
Call.setMethod(s, mop);
boolean unresolved = vmethRef.needsDynamicLink(bcodes.getMethod());
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), Call.getMethod(s).copy()));
Call.setAddress(s, offsetrop);
rectifyStateWithErrorHandler();
} else {
Call.setAddress(s, new AddressConstantOperand(vmeth.getOffset()));
}
// Attempt to inline virtualized call.
if (maybeInlineMethod(shouldInline(s, receiver.isConstant() || (receiver.isRegister() && receiver.asRegister().isExtant()), instrIndex - bciAdjustment), s)) {
return;
}
}
} else {
// A normal invokevirtual. Create call instruction.
boolean unresolved = ref.needsDynamicLink(bcodes.getMethod());
RVMMethod target = ref.peekResolvedMethod();
MethodOperand methOp = MethodOperand.VIRTUAL(ref, target);
s = _callHelper(ref, methOp);
if (s == null)
break;
// Must be done before null_check!
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), Call.getMethod(s).copy()));
Call.setAddress(s, offsetrop);
rectifyStateWithErrorHandler();
} else {
if (VM.VerifyAssertions)
opt_assert(target != null);
Call.setAddress(s, new AddressConstantOperand(target.getOffset()));
}
// null check receiver
Operand receiver = Call.getParam(s, 0);
clearCurrentGuard();
if (do_NullCheck(receiver)) {
// call will always raise null pointer exception
s = null;
break;
}
Call.setGuard(s, getCurrentGuard());
// Use compile time type of receiver to try reduce the number
// of targets.
// If we succeed, we'll update meth and s's method operand.
boolean isExtant = false;
boolean isPreciseType = false;
TypeReference tr = null;
if (receiver.isRegister()) {
RegisterOperand rop = receiver.asRegister();
isExtant = rop.isExtant();
isPreciseType = rop.isPreciseType();
tr = rop.getType();
} else {
isExtant = true;
isPreciseType = true;
tr = receiver.getType();
}
RVMType type = tr.peekType();
if (type != null && type.isResolved()) {
if (type.isClassType()) {
RVMMethod vmeth = target;
if (target == null || type != target.getDeclaringClass()) {
vmeth = ClassLoaderProxy.lookupMethod(type.asClass(), ref);
}
if (vmeth != null) {
methOp.refine(vmeth, isPreciseType || type.asClass().isFinal());
}
} else {
// Array: will always be calling the method defined in java.lang.Object
if (VM.VerifyAssertions)
opt_assert(target != null, "Huh? Target method must already be resolved if receiver is array");
methOp.refine(target, true);
}
}
// Consider inlining it.
if (maybeInlineMethod(shouldInline(s, isExtant, instrIndex - bciAdjustment), s)) {
return;
}
}
// noninlined CALL must be treated as potential throw of anything
rectifyStateWithExceptionHandlers();
}
break;
case JBC_invokespecial:
{
MethodReference ref = bcodes.getMethodReference();
RVMMethod target = ref.resolveInvokeSpecial();
/* just create an osr barrier right before _callHelper
* changes the states of locals and stacks.
*/
if (this.osrGuardedInline) {
lastOsrBarrier = _createOsrBarrier();
}
s = _callHelper(ref, MethodOperand.SPECIAL(ref, target));
if (s == null)
break;
// NOTE: different definition of unresolved due to semantics of invokespecial.
if (target == null) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), Call.getMethod(s).copy()));
Call.setAddress(s, offsetrop);
rectifyStateWithErrorHandler();
} else {
Call.setAddress(s, new AddressConstantOperand(target.getOffset()));
}
// null check receiver
Operand receiver = Call.getParam(s, 0);
clearCurrentGuard();
if (do_NullCheck(receiver)) {
// call will always raise null pointer exception
s = null;
break;
}
Call.setGuard(s, getCurrentGuard());
// Consider inlining it.
if (maybeInlineMethod(shouldInline(s, false, instrIndex - bciAdjustment), s)) {
return;
}
// noninlined CALL must be treated as potential throw of anything
rectifyStateWithExceptionHandlers();
}
break;
case JBC_invokestatic:
{
MethodReference ref = bcodes.getMethodReference();
// If it is, generate the inline code and we are done.
if (ref.isMagic()) {
boolean generated = GenerateMagic.generateMagic(this, gc, ref);
if (generated)
break;
}
// A non-magical invokestatic. Create call instruction.
boolean unresolved = ref.needsDynamicLink(bcodes.getMethod());
RVMMethod target = ref.peekResolvedMethod();
/* just create an osr barrier right before _callHelper
* changes the states of locals and stacks.
*/
if (this.osrGuardedInline) {
lastOsrBarrier = _createOsrBarrier();
}
s = _callHelper(ref, MethodOperand.STATIC(ref, target));
if (s == null)
break;
if (Call.conforms(s)) {
MethodOperand methOp = Call.getMethod(s);
if (methOp.getTarget() == target) {
// Handle possibility of dynamic linking.
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), Call.getMethod(s).copy()));
Call.setAddress(s, offsetrop);
rectifyStateWithErrorHandler();
} else {
Call.setAddress(s, new AddressConstantOperand(target.getOffset()));
}
// Consider inlining it.
if (maybeInlineMethod(shouldInline(s, false, instrIndex - bciAdjustment), s)) {
return;
}
}
}
// noninlined CALL must be treated as potential throw of anything
rectifyStateWithExceptionHandlers();
}
break;
case JBC_invokeinterface:
{
MethodReference ref = bcodes.getMethodReference();
bcodes.alignInvokeInterface();
RVMMethod resolvedMethod = null;
resolvedMethod = ref.peekInterfaceMethod();
/* just create an osr barrier right before _callHelper
* changes the states of locals and stacks.
*/
if (this.osrGuardedInline) {
lastOsrBarrier = _createOsrBarrier();
}
s = _callHelper(ref, MethodOperand.INTERFACE(ref, resolvedMethod));
if (s == null)
break;
Operand receiver = Call.getParam(s, 0);
RVMClass receiverType = (RVMClass) receiver.getType().peekType();
boolean requiresImplementsTest = VM.BuildForIMTInterfaceInvocation;
// that it is not needed.
if (requiresImplementsTest && resolvedMethod == null) {
// Sigh. Can't even resolve the reference to figure out what interface
// method we are trying to call. Therefore we must make generate a call
// to an out-of-line typechecking routine to handle it at runtime.
RVMMethod target = Entrypoints.unresolvedInvokeinterfaceImplementsTestMethod;
Instruction callCheck = Call.create2(CALL, null, new AddressConstantOperand(target.getOffset()), MethodOperand.STATIC(target), new IntConstantOperand(ref.getId()), receiver.copy());
if (gc.getOptions().H2L_NO_CALLEE_EXCEPTIONS) {
callCheck.markAsNonPEI();
}
appendInstruction(callCheck);
callCheck.setBytecodeIndex(RUNTIME_SERVICES_BCI);
// the above call subsumes the test
requiresImplementsTest = false;
// Can raise incompatible class change error.
rectifyStateWithErrorHandler();
}
// null check on this parameter of call. Must be done after dynamic linking!
clearCurrentGuard();
if (do_NullCheck(receiver)) {
// call will always raise null pointer exception
s = null;
break;
}
Call.setGuard(s, getCurrentGuard());
if (requiresImplementsTest) {
// We know what interface method the program wants to invoke.
// Attempt to avoid inserting the type check by seeing if the
// known static type of the receiver implements the desired interface.
RVMType interfaceType = resolvedMethod.getDeclaringClass();
if (receiverType != null && receiverType.isResolved() && !receiverType.isInterface()) {
byte doesImplement = ClassLoaderProxy.includesType(interfaceType.getTypeRef(), receiverType.getTypeRef());
requiresImplementsTest = doesImplement != YES;
}
}
// Attempt to resolve the interface call to a particular virtual method.
// This is independent of whether or not the static type of the receiver is
// known to implement the interface and it is not that case that being able
// to prove one implies the other.
RVMMethod vmeth = null;
if (receiverType != null && receiverType.isInitialized() && !receiverType.isInterface()) {
vmeth = ClassLoaderProxy.lookupMethod(receiverType, ref);
}
if (vmeth != null) {
MethodReference vmethRef = vmeth.getMemberRef().asMethodReference();
// Note that at this point requiresImplementsTest => resolvedMethod != null
if (requiresImplementsTest) {
RegisterOperand checkedReceiver = gc.getTemps().makeTemp(receiver);
appendInstruction(TypeCheck.create(MUST_IMPLEMENT_INTERFACE, checkedReceiver, receiver.copy(), makeTypeOperand(resolvedMethod.getDeclaringClass()), getCurrentGuard()));
checkedReceiver.refine(resolvedMethod.getDeclaringClass().getTypeRef());
Call.setParam(s, 0, checkedReceiver.copyRO());
receiver = checkedReceiver;
// Can raise incompatible class change error.
rectifyStateWithErrorHandler();
}
MethodOperand mop = MethodOperand.VIRTUAL(vmethRef, vmeth);
if (receiver.isConstant() || receiver.asRegister().isPreciseType()) {
mop.refine(vmeth, true);
}
Call.setMethod(s, mop);
boolean unresolved = vmethRef.needsDynamicLink(bcodes.getMethod());
if (unresolved) {
RegisterOperand offsetrop = gc.getTemps().makeTempOffset();
appendInstruction(Unary.create(RESOLVE_MEMBER, offsetrop.copyRO(), Call.getMethod(s).copy()));
Call.setAddress(s, offsetrop);
rectifyStateWithErrorHandler();
} else {
Call.setAddress(s, new AddressConstantOperand(vmeth.getOffset()));
}
// Attempt to inline virtualized call.
if (maybeInlineMethod(shouldInline(s, receiver.isConstant() || receiver.asRegister().isExtant(), instrIndex - bciAdjustment), s)) {
return;
}
} else {
// inline code will include DTC to ensure receiver implements the interface.
if (resolvedMethod != null && maybeInlineMethod(shouldInline(s, false, instrIndex - bciAdjustment), s)) {
return;
} else {
if (requiresImplementsTest) {
RegisterOperand checkedReceiver = gc.getTemps().makeTemp(receiver);
appendInstruction(TypeCheck.create(MUST_IMPLEMENT_INTERFACE, checkedReceiver, receiver.copy(), makeTypeOperand(resolvedMethod.getDeclaringClass()), getCurrentGuard()));
checkedReceiver.refine(resolvedMethod.getDeclaringClass().getTypeRef());
Call.setParam(s, 0, checkedReceiver.copyRO());
// don't have to rectify with error handlers; rectify call below subsumes.
}
}
}
// CALL must be treated as potential throw of anything
rectifyStateWithExceptionHandlers();
}
break;
case JBC_invokedynamic:
OptimizingCompilerException.UNREACHABLE();
break;
case JBC_new:
{
TypeReference klass = bcodes.getTypeReference();
RegisterOperand t = gc.getTemps().makeTemp(klass);
t.setPreciseType();
markGuardlessNonNull(t);
Operator operator;
TypeOperand klassOp;
RVMClass klassType = (RVMClass) klass.peekType();
if (klassType != null && (klassType.isInitialized() || klassType.isInBootImage())) {
klassOp = makeTypeOperand(klassType);
operator = NEW;
t.setExtant();
} else {
operator = NEW_UNRESOLVED;
klassOp = makeTypeOperand(klass);
}
s = New.create(operator, t, klassOp);
push(t.copyD2U());
rectifyStateWithErrorHandler();
}
break;
case JBC_newarray:
{
RVMType array = bcodes.getPrimitiveArrayType();
TypeOperand arrayOp = makeTypeOperand(array);
RegisterOperand t = gc.getTemps().makeTemp(array.getTypeRef());
t.setPreciseType();
t.setExtant();
markGuardlessNonNull(t);
s = NewArray.create(NEWARRAY, t, arrayOp, popInt());
push(t.copyD2U());
rectifyStateWithExceptionHandler(TypeReference.JavaLangNegativeArraySizeException);
}
break;
case JBC_anewarray:
{
TypeReference elementTypeRef = bcodes.getTypeReference();
s = generateAnewarray(null, elementTypeRef);
}
break;
case JBC_arraylength:
{
Operand op1 = pop();
clearCurrentGuard();
if (do_NullCheck(op1)) {
break;
}
if (VM.VerifyAssertions) {
opt_assert(getArrayTypeOf(op1).isArrayType());
}
RegisterOperand t = gc.getTemps().makeTempInt();
s = GuardedUnary.create(ARRAYLENGTH, t, op1, getCurrentGuard());
push(t.copyD2U());
}
break;
case JBC_athrow:
{
Operand op0 = pop();
clearCurrentGuard();
if (do_NullCheck(op0)) {
break;
}
TypeReference type = getRefTypeOf(op0);
if (VM.VerifyAssertions)
assertIsAssignable(TypeReference.JavaLangThrowable, type);
if (!gc.getMethod().isInterruptible()) {
// prevent code motion in or out of uninterruptible code sequence
appendInstruction(Empty.create(UNINT_END));
}
endOfBasicBlock = true;
BasicBlock definiteTarget = rectifyStateWithExceptionHandler(type, true);
if (definiteTarget != null) {
appendInstruction(CacheOp.create(SET_CAUGHT_EXCEPTION, op0));
s = Goto.create(GOTO, definiteTarget.makeJumpTarget());
definiteTarget.setExceptionHandlerWithNormalIn();
} else {
s = Athrow.create(ATHROW, op0);
}
}
break;
case JBC_checkcast:
{
TypeReference typeRef = bcodes.getTypeReference();
boolean classLoading = couldCauseClassLoading(typeRef);
Operand op2 = pop();
if (typeRef.isWordLikeType()) {
op2 = op2.copy();
if (op2 instanceof RegisterOperand) {
((RegisterOperand) op2).setType(typeRef);
}
push(op2);
if (DBG_CF)
db("skipped gen of checkcast to word type " + typeRef);
break;
}
if (VM.VerifyAssertions)
opt_assert(op2.isRef());
if (CF_CHECKCAST && !classLoading) {
if (op2.isDefinitelyNull()) {
push(op2);
if (DBG_CF)
db("skipped gen of null checkcast");
break;
}
// non-null, null case above
TypeReference type = getRefTypeOf(op2);
byte typeTestResult = ClassLoaderProxy.includesType(typeRef, type);
if (typeTestResult == YES) {
push(op2);
if (DBG_CF) {
db("skipped gen of checkcast of " + op2 + " from " + typeRef + " to " + type);
}
break;
}
if (typeTestResult == NO) {
if (isNonNull(op2)) {
// Definite class cast exception
endOfBasicBlock = true;
appendInstruction(Trap.create(TRAP, gc.getTemps().makeTempValidation(), TrapCodeOperand.CheckCast()));
rectifyStateWithExceptionHandler(TypeReference.JavaLangClassCastException);
if (DBG_CF)
db("Converted checkcast into unconditional trap");
break;
} else {
// At runtime either it is null and the checkcast succeeds or it is non-null
// and a class cast exception is raised
RegisterOperand refinedOp2 = gc.getTemps().makeTemp(op2);
s = TypeCheck.create(CHECKCAST, refinedOp2, op2.copy(), makeTypeOperand(typeRef.peekType()));
refinedOp2.refine(TypeReference.NULL_TYPE);
push(refinedOp2.copyRO());
rectifyStateWithExceptionHandler(TypeReference.JavaLangClassCastException);
if (DBG_CF)
db("Narrowed type downstream of checkcast to NULL");
break;
}
}
}
RegisterOperand refinedOp2 = gc.getTemps().makeTemp(op2);
if (classLoading) {
s = TypeCheck.create(CHECKCAST_UNRESOLVED, refinedOp2, op2.copy(), makeTypeOperand(typeRef));
} else {
TypeOperand typeOp = makeTypeOperand(typeRef.peekType());
if (isNonNull(op2)) {
s = TypeCheck.create(CHECKCAST_NOTNULL, refinedOp2, op2.copy(), typeOp, copyGuardFromOperand(op2));
} else {
s = TypeCheck.create(CHECKCAST, refinedOp2, op2.copy(), typeOp);
}
}
refinedOp2.refine(typeRef);
push(refinedOp2.copyRO());
rectifyStateWithExceptionHandler(TypeReference.JavaLangClassCastException);
if (classLoading)
rectifyStateWithErrorHandler();
}
break;
case JBC_instanceof:
{
TypeReference typeRef = bcodes.getTypeReference();
boolean classLoading = couldCauseClassLoading(typeRef);
Operand op2 = pop();
if (VM.VerifyAssertions)
opt_assert(op2.isRef());
if (CF_INSTANCEOF && !classLoading) {
if (op2.isDefinitelyNull()) {
push(new IntConstantOperand(0));
if (DBG_CF)
db("skipped gen of null instanceof");
break;
}
// non-null
TypeReference type = getRefTypeOf(op2);
int answer = ClassLoaderProxy.includesType(typeRef, type);
if (answer == YES && isNonNull(op2)) {
push(new IntConstantOperand(1));
if (DBG_CF) {
db(op2 + " instanceof " + typeRef + " is always true ");
}
break;
} else if (answer == NO) {
if (DBG_CF) {
db(op2 + " instanceof " + typeRef + " is always false ");
}
push(new IntConstantOperand(0));
break;
}
}
RegisterOperand t = gc.getTemps().makeTempInt();
if (classLoading) {
s = InstanceOf.create(INSTANCEOF_UNRESOLVED, t, makeTypeOperand(typeRef), op2);
} else {
TypeOperand typeOp = makeTypeOperand(typeRef.peekType());
if (isNonNull(op2)) {
s = InstanceOf.create(INSTANCEOF_NOTNULL, t, typeOp, op2, copyGuardFromOperand(op2));
} else {
s = InstanceOf.create(INSTANCEOF, t, typeOp, op2);
}
}
push(t.copyD2U());
if (classLoading)
rectifyStateWithErrorHandler();
}
break;
case JBC_monitorenter:
{
Operand op0 = pop();
clearCurrentGuard();
if (do_NullCheck(op0)) {
break;
}
if (VM.VerifyAssertions)
opt_assert(op0.isRef());
s = MonitorOp.create(MONITORENTER, op0, getCurrentGuard());
}
break;
case JBC_monitorexit:
{
Operand op0 = pop();
clearCurrentGuard();
if (do_NullCheck(op0)) {
break;
}
s = MonitorOp.create(MONITOREXIT, op0, getCurrentGuard());
rectifyStateWithExceptionHandler(TypeReference.JavaLangIllegalMonitorStateException);
}
break;
case JBC_wide:
{
int widecode = bcodes.getWideOpcode();
int index = bcodes.getWideLocalNumber();
switch(widecode) {
case JBC_iload:
s = do_iload(index);
break;
case JBC_lload:
s = do_lload(index);
break;
case JBC_fload:
s = do_fload(index);
break;
case JBC_dload:
s = do_dload(index);
break;
case JBC_aload:
s = do_aload(index);
break;
case JBC_istore:
s = do_store(index, popInt());
break;
case JBC_lstore:
s = do_store(index, popLong());
break;
case JBC_fstore:
s = do_store(index, popFloat());
break;
case JBC_dstore:
s = do_store(index, popDouble());
break;
case JBC_astore:
s = do_astore(index);
break;
case JBC_iinc:
s = do_iinc(index, bcodes.getWideIncrement());
break;
case JBC_ret:
s = _retHelper(index);
break;
default:
OptimizingCompilerException.UNREACHABLE();
break;
}
}
break;
case JBC_multianewarray:
{
TypeReference arrayType = bcodes.getTypeReference();
int dimensions = bcodes.getArrayDimension();
if (dimensions == 1) {
s = generateAnewarray(arrayType, null);
} else {
TypeOperand typeOp = makeTypeOperand(arrayType);
RegisterOperand result = gc.getTemps().makeTemp(arrayType);
markGuardlessNonNull(result);
result.setPreciseType();
TypeReference innermostElementTypeRef = arrayType.getInnermostElementType();
RVMType innermostElementType = innermostElementTypeRef.peekType();
if (innermostElementType != null && (innermostElementType.isInitialized() || innermostElementType.isInBootImage())) {
result.setExtant();
}
s = Multianewarray.create(NEWOBJMULTIARRAY, result, typeOp, dimensions);
for (int i = 0; i < dimensions; i++) {
Multianewarray.setDimension(s, dimensions - i - 1, popInt());
}
push(result.copyD2U());
rectifyStateWithErrorHandler();
rectifyStateWithExceptionHandler(TypeReference.JavaLangNegativeArraySizeException);
}
}
break;
case JBC_ifnull:
s = _refIfNullHelper(ConditionOperand.EQUAL());
break;
case JBC_ifnonnull:
s = _refIfNullHelper(ConditionOperand.NOT_EQUAL());
break;
case JBC_goto_w:
{
int offset = bcodes.getWideBranchOffset();
if (offset != 5) {
// skip generating frivolous goto's
s = _gotoHelper(offset);
}
}
break;
case JBC_jsr_w:
s = _jsrHelper(bcodes.getWideBranchOffset());
break;
case JBC_impdep1:
{
if (VM.BuildForAdaptiveSystem) {
int pseudo_opcode = bcodes.nextPseudoInstruction();
switch(pseudo_opcode) {
case PSEUDO_LoadIntConst:
{
int value = bcodes.readIntConst();
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("PSEUDO_LoadIntConst " + value);
}
push(new IntConstantOperand(value));
// used for PSEUDO_InvokeStatic to recover the type info
param1 = param2;
param2 = value;
break;
}
case PSEUDO_LoadLongConst:
{
long value = bcodes.readLongConst();
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("PSEUDO_LoadLongConst " + value);
}
pushDual(new LongConstantOperand(value));
break;
}
case PSEUDO_LoadWordConst:
{
Address a = (VM.BuildFor32Addr) ? Address.fromIntSignExtend(bcodes.readIntConst()) : Address.fromLong(bcodes.readLongConst());
push(new AddressConstantOperand(a));
if (VM.TraceOnStackReplacement) {
VM.sysWrite("PSEUDO_LoadWordConst 0x");
}
VM.sysWrite(a);
VM.sysWriteln();
break;
}
case PSEUDO_LoadFloatConst:
{
int ibits = bcodes.readIntConst();
float value = Float.intBitsToFloat(ibits);
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("PSEUDO_LoadFloatConst " + value);
}
push(new FloatConstantOperand(value, Offset.zero()));
break;
}
case PSEUDO_LoadDoubleConst:
{
long lbits = bcodes.readLongConst();
double value = Magic.longBitsAsDouble(lbits);
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("PSEUDO_LoadDoubleConst " + lbits);
}
pushDual(new DoubleConstantOperand(value, Offset.zero()));
break;
}
case PSEUDO_LoadRetAddrConst:
{
int value = bcodes.readIntConst();
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("PSEUDO_LoadRetAddrConst " + value);
}
push(new ReturnAddressOperand(value));
break;
}
case PSEUDO_InvokeStatic:
{
/* pseudo invoke static for getRefAt and cleanRefAt, both must be resolved already */
int targetidx = bcodes.readIntConst();
RVMMethod meth = InvokeStatic.targetMethod(targetidx);
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("PSEUDO_Invoke " + meth);
VM.sysWriteln();
}
s = _callHelper(meth.getMemberRef().asMethodReference(), MethodOperand.STATIC(meth));
if (s == null)
break;
Call.setAddress(s, new AddressConstantOperand(meth.getOffset()));
/* try to set the type of return register */
if (targetidx == GETREFAT) {
Object realObj = ObjectHolder.getRefAt(param1, param2);
if (VM.VerifyAssertions)
opt_assert(realObj != null);
TypeReference klass = Magic.getObjectType(realObj).getTypeRef();
RegisterOperand op0 = gc.getTemps().makeTemp(klass);
Call.setResult(s, op0);
// pop the old one and push the new return type.
pop();
push(op0.copyD2U(), klass);
}
// CALL must be treated as potential throw of anything
rectifyStateWithExceptionHandlers();
break;
}
case PSEUDO_InvokeCompiledMethod:
{
int cmid = bcodes.readIntConst();
// skip it
int origBCIdx = bcodes.readIntConst();
CompiledMethod cm = CompiledMethods.getCompiledMethod(cmid);
RVMMethod meth = cm.getMethod();
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("PSEUDO_InvokeCompiledMethod " + meth);
VM.sysWriteln();
}
/* the bcIndex should be adjusted to the original */
s = _callHelper(meth.getMemberRef().asMethodReference(), MethodOperand.COMPILED(meth, cm.getOsrJTOCoffset()));
if (s == null)
break;
// adjust the bcindex of s to the original bytecode's index
// it should be able to give the correct exception handling
s.adjustBytecodeIndex(bciAdjustment);
rectifyStateWithExceptionHandlers();
break;
}
case PSEUDO_ParamInitEnd:
{
break;
}
default:
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("OSR Error, no such pseudo opcode : " + pseudo_opcode);
}
OptimizingCompilerException.UNREACHABLE();
break;
}
break;
} else {
OptimizingCompilerException.UNREACHABLE();
}
}
default:
OptimizingCompilerException.UNREACHABLE();
break;
}
if (s != null && !currentBBLE.isSelfRegen()) {
appendInstruction(s);
}
// check runoff
if (VM.VerifyAssertions)
opt_assert(bcodes.index() <= runoff);
if (!endOfBasicBlock && bcodes.index() == runoff) {
if (DBG_BB || DBG_SELECTED) {
db("runoff occurred! current basic block: " + currentBBLE + ", runoff = " + runoff);
}
endOfBasicBlock = fallThrough = true;
}
if (endOfBasicBlock) {
if (currentBBLE.isSelfRegen()) {
// This block ended in a goto that jumped into the middle of it.
// Through away all out edges from this block, they're out of date
// because we're going to have to regenerate this block.
currentBBLE.block.deleteOut();
if (DBG_CFG || DBG_SELECTED) {
db("Deleted all out edges of " + currentBBLE.block);
}
return;
}
if (fallThrough) {
if (VM.VerifyAssertions)
opt_assert(bcodes.index() < bcodes.length());
// Get/Create fallthrough BBLE and record it as
// currentBBLE's fallThrough.
currentBBLE.fallThrough = getOrCreateBlock(bcodes.index());
currentBBLE.block.insertOut(currentBBLE.fallThrough.block);
}
return;
}
}
}
use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class TestMagicAttemptPrepareLong method performTask.
void performTask() {
int errors = 0;
RVMField internalLongField = null;
try {
Field longField = LongField.class.getField("longAccessedViaMagic");
Class<?> jikesRVMSupportClass = Class.forName("java.lang.reflect.JikesRVMSupport");
Method m = jikesRVMSupportClass.getMethod("getFieldOf", Class.forName("java.lang.reflect.Field"));
internalLongField = (RVMField) m.invoke(null, longField);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
Offset fieldOffset = internalLongField.getOffset();
for (int i = 0; i < 10000000; i++) {
long tl = Magic.prepareLong(lf, fieldOffset);
Magic.attemptLong(lf, fieldOffset, tl, l);
int n0 = (int) tl;
int n1 = (int) (tl >> 32);
if (n0 != n1)
errors++;
vi = n;
}
tsay(errors + " errors found");
}
use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class LoadElimination method getCandidates.
/**
* Do a quick pass over the IR, and return types that are candidates
* for redundant load elimination.<p>
*
* Algorithm: return those types T where
* <ul>
* <li>there's a load L(i) of type T
* <li>there's another load or store M(j) of type T, M!=L and V(i) == V(j)
* </ul>
* <p>
* The result contains objects of type RVMField and TypeReference, whose
* narrowest common ancestor is Object.
*
* @param ir the governing IR
*
* @return the types that are candidates for redundant load elimination
*/
@SuppressWarnings("unchecked")
public static HashSet<Object> getCandidates(IR ir) {
GlobalValueNumberState valueNumbers = ir.HIRInfo.valueNumbers;
// which types have we seen loads for?
HashSet<Object> seenLoad = new HashSet<Object>(10);
// which static fields have we seen stores for?
HashSet<RVMField> seenStore = new HashSet<RVMField>(10);
HashSet<Object> resultSet = new HashSet<Object>(10);
HashSet<FieldReference> forbidden = new HashSet<FieldReference>(10);
// for each type T, indices(T) gives the set of value number (pairs)
// that identify the indices seen in memory accesses to type T.
HashMap indices = new HashMap(10);
for (Enumeration be = ir.getBasicBlocks(); be.hasMoreElements(); ) {
BasicBlock bb = (BasicBlock) be.nextElement();
if (!ir.options.FREQ_FOCUS_EFFORT || !bb.getInfrequent()) {
for (Enumeration<Instruction> e = bb.forwardInstrEnumerator(); e.hasMoreElements(); ) {
Instruction s = e.nextElement();
switch(s.getOpcode()) {
case GETFIELD_opcode:
{
Operand ref = GetField.getRef(s);
FieldReference fr = GetField.getLocation(s).getFieldRef();
RVMField f = fr.peekResolvedField();
if (f == null) {
forbidden.add(fr);
} else {
HashSet<Integer> numbers = findOrCreateIndexSet(indices, f);
int v = valueNumbers.getValueNumber(ref);
Integer V = v;
if (numbers.contains(V)) {
resultSet.add(f);
} else {
numbers.add(V);
}
seenLoad.add(f);
}
}
break;
case PUTFIELD_opcode:
{
Operand ref = PutField.getRef(s);
FieldReference fr = PutField.getLocation(s).getFieldRef();
RVMField f = fr.peekResolvedField();
if (f == null) {
forbidden.add(fr);
} else {
HashSet<Integer> numbers = findOrCreateIndexSet(indices, f);
int v = valueNumbers.getValueNumber(ref);
Integer V = v;
if (numbers.contains(V)) {
if (seenLoad.contains(f)) {
resultSet.add(f);
}
} else {
numbers.add(V);
}
}
}
break;
case GETSTATIC_opcode:
{
FieldReference fr = GetStatic.getLocation(s).getFieldRef();
RVMField f = fr.peekResolvedField();
if (f == null) {
forbidden.add(fr);
} else {
if (seenLoad.contains(f) || seenStore.contains(f)) {
resultSet.add(f);
}
seenLoad.add(f);
}
}
break;
case PUTSTATIC_opcode:
{
FieldReference fr = PutStatic.getLocation(s).getFieldRef();
RVMField f = fr.peekResolvedField();
if (f == null) {
forbidden.add(fr);
} else {
if (seenLoad.contains(f)) {
resultSet.add(f);
}
seenStore.add(f);
}
}
break;
case INT_ALOAD_opcode:
case LONG_ALOAD_opcode:
case FLOAT_ALOAD_opcode:
case DOUBLE_ALOAD_opcode:
case REF_ALOAD_opcode:
case BYTE_ALOAD_opcode:
case UBYTE_ALOAD_opcode:
case USHORT_ALOAD_opcode:
case SHORT_ALOAD_opcode:
{
Operand ref = ALoad.getArray(s);
TypeReference type = ref.getType();
if (type.isArrayType()) {
if (!type.getArrayElementType().isPrimitiveType()) {
type = TypeReference.JavaLangObjectArray;
}
}
Operand index = ALoad.getIndex(s);
HashSet<ValueNumberPair> numbers = findOrCreateIndexSet(indices, type);
int v1 = valueNumbers.getValueNumber(ref);
int v2 = valueNumbers.getValueNumber(index);
ValueNumberPair V = new ValueNumberPair(v1, v2);
if (numbers.contains(V)) {
resultSet.add(type);
} else {
numbers.add(V);
}
seenLoad.add(type);
}
break;
case INT_ASTORE_opcode:
case LONG_ASTORE_opcode:
case FLOAT_ASTORE_opcode:
case DOUBLE_ASTORE_opcode:
case REF_ASTORE_opcode:
case BYTE_ASTORE_opcode:
case SHORT_ASTORE_opcode:
{
Operand ref = AStore.getArray(s);
TypeReference type = ref.getType();
if (type.isArrayType()) {
if (!type.getArrayElementType().isPrimitiveType()) {
type = TypeReference.JavaLangObjectArray;
}
}
Operand index = AStore.getIndex(s);
HashSet<ValueNumberPair> numbers = findOrCreateIndexSet(indices, type);
int v1 = valueNumbers.getValueNumber(ref);
int v2 = valueNumbers.getValueNumber(index);
ValueNumberPair V = new ValueNumberPair(v1, v2);
if (numbers.contains(V)) {
if (seenLoad.contains(type)) {
resultSet.add(type);
}
} else {
numbers.add(V);
}
}
break;
default:
break;
}
}
}
}
// remove all fields that it might refer to from the resultSet.
for (final FieldReference fieldReference : forbidden) {
for (Iterator i2 = resultSet.iterator(); i2.hasNext(); ) {
Object it = i2.next();
if (it instanceof RVMField) {
final RVMField field = (RVMField) it;
if (!fieldReference.definitelyDifferent(field.getMemberRef().asFieldReference())) {
i2.remove();
}
}
}
}
return resultSet;
}
use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class BootImageWriter method copyClassToBootImage.
/**
* Write an object instantiating a class to the boot image
* @param scalarImageAddress address already allocated for object
* @param jdkObject object to write
* @param jdkType java.lang.Class of object
* @param rvmScalarType RVM class loader version of type
* @param allocOnly allocate the object only?
* @param overwriteAddress
* @param parentObject
* @param untraced
* @return
* @throws IllegalAccessException
*/
private static Address copyClassToBootImage(Address scalarImageAddress, Object jdkObject, Class<?> jdkType, RVMClass rvmScalarType, boolean allocOnly, Address overwriteAddress, Object parentObject, boolean untraced) throws IllegalAccessException {
if (verbosity.isAtLeast(DETAILED)) {
if (depth == DEPTH_CUTOFF)
say(SPACES.substring(0, depth + 1), "TOO DEEP: cutting off");
else if (depth < DEPTH_CUTOFF) {
String tab = SPACES.substring(0, depth + 1);
if (depth == 0 && jtocCount >= 0)
tab = tab + "jtoc #" + String.valueOf(jtocCount) + " ";
int scalarSize = rvmScalarType.getInstanceSize();
say(tab, "Copying object ", jdkType.getName(), " size=", String.valueOf(scalarSize), (scalarSize >= LARGE_SCALAR_SIZE) ? " large object!!!" : "");
}
}
// copy object fields from host jdk address space into image
// recurse on values that are references
RVMField[] rvmFields = rvmScalarType.getInstanceFields();
for (int i = 0; i < rvmFields.length; ++i) {
RVMField rvmField = rvmFields[i];
TypeReference rvmFieldType = rvmField.getType();
Address rvmFieldAddress = scalarImageAddress.plus(rvmField.getOffset());
String rvmFieldName = rvmField.getName().toString();
Field jdkFieldAcc = getJdkFieldAccessor(jdkType, i, INSTANCE_FIELD);
boolean untracedField = rvmField.isUntraced() || untraced;
if (jdkFieldAcc == null) {
// Field not found via reflection
if (!copyKnownInstanceField(jdkObject, rvmFieldName, rvmFieldType, rvmFieldAddress)) {
// Field wasn't a known Classpath field so write null
if (verbosity.isAtLeast(DETAILED))
traceContext.push(rvmFieldType.toString(), jdkType.getName(), rvmFieldName);
if (verbosity.isAtLeast(DETAILED))
traceContext.traceFieldNotInHostJdk();
if (verbosity.isAtLeast(DETAILED))
traceContext.pop();
if (rvmFieldType.isPrimitiveType()) {
switch(rvmField.getType().getMemoryBytes()) {
case 1:
bootImage.setByte(rvmFieldAddress, 0);
break;
case 2:
bootImage.setHalfWord(rvmFieldAddress, 0);
break;
case 4:
bootImage.setFullWord(rvmFieldAddress, 0);
break;
case 8:
bootImage.setDoubleWord(rvmFieldAddress, 0L);
break;
default:
fail("unexpected field type: " + rvmFieldType);
break;
}
} else {
bootImage.setNullAddressWord(rvmFieldAddress, !untracedField, !untracedField, false);
}
}
continue;
}
if (rvmFieldType.isPrimitiveType()) {
// field is logical or numeric type
if (rvmFieldType.isBooleanType()) {
bootImage.setByte(rvmFieldAddress, jdkFieldAcc.getBoolean(jdkObject) ? 1 : 0);
} else if (rvmFieldType.isByteType()) {
bootImage.setByte(rvmFieldAddress, jdkFieldAcc.getByte(jdkObject));
} else if (rvmFieldType.isCharType()) {
bootImage.setHalfWord(rvmFieldAddress, jdkFieldAcc.getChar(jdkObject));
} else if (rvmFieldType.isShortType()) {
bootImage.setHalfWord(rvmFieldAddress, jdkFieldAcc.getShort(jdkObject));
} else if (rvmFieldType.isIntType()) {
try {
bootImage.setFullWord(rvmFieldAddress, jdkFieldAcc.getInt(jdkObject));
} catch (IllegalArgumentException ex) {
// TODO: Harmony - clean this up
if (jdkObject instanceof java.util.WeakHashMap && rvmFieldName.equals("loadFactor")) {
// the field load factor field in Sun/Classpath is a float but
// in Harmony it has been "optimized" to an int
bootImage.setFullWord(rvmFieldAddress, 7500);
} else if (jdkObject instanceof java.lang.ref.ReferenceQueue && rvmFieldName.equals("head")) {
// Conflicting types between Harmony and Sun
bootImage.setFullWord(rvmFieldAddress, 0);
} else {
System.out.println("type " + rvmScalarType + ", field " + rvmField);
throw ex;
}
}
} else if (rvmFieldType.isLongType()) {
bootImage.setDoubleWord(rvmFieldAddress, jdkFieldAcc.getLong(jdkObject));
} else if (rvmFieldType.isFloatType()) {
float f = jdkFieldAcc.getFloat(jdkObject);
bootImage.setFullWord(rvmFieldAddress, Float.floatToIntBits(f));
} else if (rvmFieldType.isDoubleType()) {
double d = jdkFieldAcc.getDouble(jdkObject);
bootImage.setDoubleWord(rvmFieldAddress, Double.doubleToLongBits(d));
} else if (rvmFieldType.equals(TypeReference.Address) || rvmFieldType.equals(TypeReference.Word) || rvmFieldType.equals(TypeReference.Extent) || rvmFieldType.equals(TypeReference.Offset)) {
Object o = jdkFieldAcc.get(jdkObject);
String msg = " instance field " + rvmField.toString();
boolean warn = rvmFieldType.equals(TypeReference.Address);
bootImage.setAddressWord(rvmFieldAddress, getWordValue(o, msg, warn), false, false);
} else {
fail("unexpected primitive field type: " + rvmFieldType);
}
} else {
// field is reference type
Object value = jdkFieldAcc.get(jdkObject);
if (!allocOnly) {
Class<?> jdkClass = jdkFieldAcc.getDeclaringClass();
if (verbosity.isAtLeast(DETAILED)) {
String typeName = (value == null) ? "(unknown: value was null)" : value.getClass().getName();
traceContext.push(typeName, jdkClass.getName(), jdkFieldAcc.getName());
}
copyReferenceFieldToBootImage(rvmFieldAddress, value, jdkObject, !untracedField, !(untracedField || rvmField.isFinal()), rvmFieldName, rvmFieldType);
if (verbosity.isAtLeast(DETAILED)) {
traceContext.pop();
}
}
}
}
return scalarImageAddress;
}
use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class BootImageWriter method createBootImageObjects.
/**
* Create (in host JDK address space) the RVM objects that will be
* needed at run time to execute enough of the virtual machine
* to dynamically load and compile the remainder of itself.<p>
*
* Side effects:
* <ul>
* <li>RVM objects are created in host JDK address space
* <li>Statics is populated
* <li>"bootImageTypes" dictionary is populated with name/type pairs
* </ul>
*
* @param typeNames names of RVM classes whose static fields will contain
* the objects comprising the virtual machine bootimage
*/
public static void createBootImageObjects(Vector<String> typeNames, String bootImageTypeNamesFile) throws IllegalAccessException {
Callbacks.notifyBootImage(typeNames.elements());
long startTime = 0;
long stopTime = 0;
//
if (verbosity.isAtLeast(SUMMARY))
say("loading");
if (profile)
startTime = System.currentTimeMillis();
for (String typeName : typeNames) {
//
if (verbosity.isAtLeast(TYPE_NAMES))
say("typeName:", typeName);
//
// create corresponding rvm type
//
RVMType type;
try {
TypeReference tRef = TypeReference.findOrCreate(typeName);
type = tRef.resolve();
} catch (NoClassDefFoundError ncdf) {
ncdf.printStackTrace(System.out);
fail(bootImageTypeNamesFile + " contains a class named \"" + typeName + "\", but we can't find a class with that name: " + ncdf);
// NOTREACHED
return;
} catch (IllegalArgumentException ila) {
/* We should've caught any illegal type names at the data validation
* stage, when we read these in. If not, though,
* TypeReference.findOrCreate() will do its own sanity check. */
ila.printStackTrace(System.out);
fail(bootImageTypeNamesFile + " is supposed to contain type names. It contains \"" + typeName + "\", which does not parse as a legal type name: " + ila);
// NOTREACHED
return;
}
type.markAsBootImageClass();
//
// convert type name from internal form to external form
// ie: Ljava/lang/Object; --> java.lang.Object
// [Ljava/lang/Object; --> [Ljava.lang.Object;
//
// NOTE: duplicate functionality. There is a method that does the same.
//
typeName = typeName.replace('/', '.');
if (typeName.startsWith("L"))
typeName = typeName.substring(1, typeName.length() - 1);
//
// record name/type pair for later lookup by getRvmType()
//
bootImageTypes.put(typeName, type);
}
if (profile) {
stopTime = System.currentTimeMillis();
System.out.println("PROF: \tloading types " + (stopTime - startTime) + " ms");
}
int typeCount = bootImageTypes.size();
JMXSupport.CLASS_LOADING_JMX_SUPPORT.setClassLoadedCountForBootimage(typeCount);
if (verbosity.isAtLeast(SUMMARY))
say(String.valueOf(typeCount), " types");
//
if (profile)
startTime = System.currentTimeMillis();
if (verbosity.isAtLeast(SUMMARY))
say("resolving");
for (RVMType type : bootImageTypes.values()) {
if (verbosity.isAtLeast(DETAILED))
say("resolving " + type);
// The resolution is supposed to be cached already.
type.resolve();
}
//
for (RVMType type : bootImageTypes.values()) {
type.allBootImageTypesResolved();
}
if (profile) {
stopTime = System.currentTimeMillis();
System.out.println("PROF: \tresolving types " + (stopTime - startTime) + " ms");
}
// Set tocRegister early so opt compiler can access it to
// perform fixed_jtoc optimization (compile static addresses into code).
// In the boot image, the bootrecord comes first followed by a
// Address array and then the TOC. To do this, we must fully
// simulate the alignment logic in the allocation code! Rather
// than replicate the allocation code here, we perform dummy
// allocations and then reset the boot image allocator.
BootRecord bootRecord = BootRecord.the_boot_record;
RVMClass rvmBRType = getRvmType(bootRecord.getClass()).asClass();
RVMArray intArrayType = RVMArray.IntArray;
// allocate storage for boot record
bootImage.allocateDataStorage(rvmBRType.getInstanceSize(), ObjectModel.getAlignment(rvmBRType), ObjectModel.getOffsetForAlignment(rvmBRType, false));
// allocate storage for JTOC (force 16byte alignment of the JTOC on Intel)
Address jtocAddress = bootImage.allocateDataStorage(intArrayType.getInstanceSize(0), VM.BuildForIA32 ? 16 : ObjectModel.getAlignment(intArrayType), ObjectModel.getOffsetForAlignment(intArrayType, false));
bootImage.resetAllocator();
bootRecord.tocRegister = jtocAddress.plus(intArrayType.getInstanceSize(Statics.middleOfTable));
// set up some stuff we need for compiling
ArchitectureFactory.initOutOfLineMachineCode();
//
if (profile)
startTime = System.currentTimeMillis();
if (verbosity.isAtLeast(SUMMARY))
say("instantiating");
if (verbosity.isAtLeast(SUMMARY))
say("setting up compilation infrastructure and pre-compiling easy cases");
CompilationOrder order = new CompilationOrder(typeCount, numThreads);
for (RVMType type : bootImageTypes.values()) {
order.addType(type);
}
order.fixUpMissingSuperClasses();
if (verbosity.isAtLeast(SUMMARY))
say(" compiling with " + numThreads + " threads");
ThreadFactory threadFactory = new KillVMonUncaughtExceptionThreadFactory();
ExecutorService threadPool = Executors.newFixedThreadPool(numThreads, threadFactory);
int runnableCount = order.getCountOfNeededWorkers();
while (runnableCount > 0) {
try {
threadPool.execute(order.getNextRunnable());
runnableCount--;
} catch (InterruptedException e) {
throw new Error("Build interrupted", e);
}
}
threadPool.shutdown();
try {
while (!threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS)) {
say("Compilation really shouldn't take this long");
}
} catch (InterruptedException e) {
throw new Error("Build interrupted", e);
}
if (BootImageWorker.instantiationFailed) {
throw new Error("Error during instantiaion");
}
if (profile) {
stopTime = System.currentTimeMillis();
System.out.println("PROF: \tinstantiating types " + (stopTime - startTime) + " ms");
}
// Free up unnecessary Statics data structures
staticsJunk = Statics.bootImageInstantiationFinished();
// Do the portion of JNIEnvironment initialization that can be done
// at bootimage writing time.
FunctionTable functionTable = BuildJNIFunctionTable.buildTable();
JNIEnvironment.initFunctionTable(functionTable);
//
if (verbosity.isAtLeast(SUMMARY))
say("field info gathering");
if (profile)
startTime = System.currentTimeMillis();
bootImageTypeFields = new HashMap<Key, FieldInfo>(typeCount);
HashSet<String> invalidEntrys = new HashSet<String>();
// First retrieve the jdk Field table for each class of interest
for (RVMType rvmType : bootImageTypes.values()) {
FieldInfo fieldInfo;
if (!rvmType.isClassType())
// arrays and primitives have no static or instance fields
continue;
Class<?> jdkType = getJdkType(rvmType);
if (jdkType == null)
// won't need the field info
continue;
Key key = new Key(jdkType);
fieldInfo = bootImageTypeFields.get(key);
if (fieldInfo != null) {
fieldInfo.rvmType = rvmType;
} else {
if (verbosity.isAtLeast(SUMMARY))
say("making fieldinfo for " + rvmType);
fieldInfo = new FieldInfo(jdkType, rvmType);
bootImageTypeFields.put(key, fieldInfo);
// Can't add them in next loop as Iterator's don't allow updates to collection
for (Class<?> cls = jdkType.getSuperclass(); cls != null; cls = cls.getSuperclass()) {
key = new Key(cls);
fieldInfo = bootImageTypeFields.get(key);
if (fieldInfo != null) {
break;
} else {
if (verbosity.isAtLeast(SUMMARY))
say("making fieldinfo for " + jdkType);
fieldInfo = new FieldInfo(cls, null);
bootImageTypeFields.put(key, fieldInfo);
}
}
}
}
// Now build the one-to-one instance and static field maps
for (FieldInfo fieldInfo : bootImageTypeFields.values()) {
RVMType rvmType = fieldInfo.rvmType;
if (rvmType == null) {
if (verbosity.isAtLeast(SUMMARY))
say("bootImageTypeField entry has no rvmType:" + fieldInfo.jdkType);
continue;
}
Class<?> jdkType = fieldInfo.jdkType;
if (verbosity.isAtLeast(SUMMARY))
say("building static and instance fieldinfo for " + rvmType);
// First the static fields
//
RVMField[] rvmFields = rvmType.getStaticFields();
fieldInfo.jdkStaticFields = new Field[rvmFields.length];
for (int j = 0; j < rvmFields.length; j++) {
String rvmName = rvmFields[j].getName().toString();
for (Field f : fieldInfo.jdkFields) {
if (f.getName().equals(rvmName)) {
fieldInfo.jdkStaticFields[j] = f;
f.setAccessible(true);
break;
}
}
}
// Now the instance fields
//
rvmFields = rvmType.getInstanceFields();
fieldInfo.jdkInstanceFields = new Field[rvmFields.length];
for (int j = 0; j < rvmFields.length; j++) {
String rvmName = rvmFields[j].getName().toString();
// We look only in the JDK type that corresponds to the
// RVMType of the field's declaring class.
// This is the only way to correctly handle private fields.
jdkType = getJdkType(rvmFields[j].getDeclaringClass());
if (jdkType == null)
continue;
FieldInfo jdkFieldInfo = bootImageTypeFields.get(new Key(jdkType));
if (jdkFieldInfo == null)
continue;
Field[] jdkFields = jdkFieldInfo.jdkFields;
for (Field f : jdkFields) {
if (f.getName().equals(rvmName)) {
fieldInfo.jdkInstanceFields[j] = f;
f.setAccessible(true);
break;
}
}
}
}
if (profile) {
stopTime = System.currentTimeMillis();
System.out.println("PROF: \tcreating type mapping " + (stopTime - startTime) + " ms");
}
//
// Create stack, thread, and processor context in which rvm will begin
// execution.
startupThread = RVMThread.setupBootThread();
byte[] stack = startupThread.getStack();
// sanity check for bootstrap loader
int idx = stack.length - 1;
if (VM.LittleEndian) {
stack[idx--] = (byte) 0xde;
stack[idx--] = (byte) 0xad;
stack[idx--] = (byte) 0xba;
stack[idx--] = (byte) 0xbe;
} else {
stack[idx--] = (byte) 0xbe;
stack[idx--] = (byte) 0xba;
stack[idx--] = (byte) 0xad;
stack[idx--] = (byte) 0xde;
}
//
// Tell RVM where to find itself at execution time.
// This may not be the same place it was at build time, ie. if image is
// moved to another machine with different directory structure.
//
BootstrapClassLoader.setBootstrapRepositories(bootImageRepositoriesAtExecutionTime);
//
if (verbosity.isAtLeast(SUMMARY))
say("populating jtoc with static fields");
if (profile)
startTime = System.currentTimeMillis();
for (RVMType rvmType : bootImageTypes.values()) {
if (verbosity.isAtLeast(SUMMARY))
say(" jtoc for ", rvmType.toString());
if (!rvmType.isClassType())
// arrays and primitives have no static fields
continue;
Class<?> jdkType = getJdkType(rvmType);
if (jdkType == null && verbosity.isAtLeast(SUMMARY)) {
say("host has no class \"" + rvmType + "\"");
}
RVMField[] rvmFields = rvmType.getStaticFields();
for (int j = 0; j < rvmFields.length; ++j) {
RVMField rvmField = rvmFields[j];
TypeReference rvmFieldType = rvmField.getType();
Offset rvmFieldOffset = rvmField.getOffset();
String rvmFieldName = rvmField.getName().toString();
Field jdkFieldAcc = null;
if (jdkType != null && jdkType.equals(java.util.concurrent.locks.AbstractQueuedSynchronizer.class)) {
RVMClass c = (RVMClass) rvmType;
if (rvmFieldName.equals("stateOffset")) {
Statics.setSlotContents(rvmFieldOffset, c.findDeclaredField(Atom.findOrCreateAsciiAtom("state")).getOffset().toLong());
continue;
} else if (rvmFieldName.equals("headOffset")) {
Statics.setSlotContents(rvmFieldOffset, c.findDeclaredField(Atom.findOrCreateAsciiAtom("head")).getOffset().toLong());
continue;
} else if (rvmFieldName.equals("tailOffset")) {
Statics.setSlotContents(rvmFieldOffset, c.findDeclaredField(Atom.findOrCreateAsciiAtom("tail")).getOffset().toLong());
continue;
} else if (rvmFieldName.equals("waitStatusOffset")) {
try {
Statics.setSlotContents(rvmFieldOffset, ((RVMClass) getRvmType(Class.forName("java.util.concurrent.locks.AbstractQueuedSynchronizer$Node"))).findDeclaredField(Atom.findOrCreateAsciiAtom("waitStatus")).getOffset().toLong());
} catch (ClassNotFoundException e) {
throw new Error(e);
}
continue;
}
} else if (jdkType != null && jdkType.equals(java.util.concurrent.locks.LockSupport.class)) {
RVMClass c = (RVMClass) rvmType;
if (rvmFieldName.equals("parkBlockerOffset")) {
Statics.setSlotContents(rvmFieldOffset, ((RVMClass) getRvmType(java.lang.Thread.class)).findDeclaredField(Atom.findOrCreateAsciiAtom("parkBlocker")).getOffset().toLong());
continue;
}
}
if (jdkType != null)
jdkFieldAcc = getJdkFieldAccessor(jdkType, j, STATIC_FIELD);
if (jdkFieldAcc == null) {
// we failed to get a reflective field accessors
if (jdkType != null) {
// we know the type - probably a private field of a java.lang class
if (!copyKnownStaticField(jdkType, rvmFieldName, rvmFieldType, rvmFieldOffset)) {
// we didn't know the field so nullify
if (verbosity.isAtLeast(DETAILED)) {
traceContext.push(rvmFieldType.toString(), jdkType.getName(), rvmFieldName);
traceContext.traceFieldNotInHostJdk();
traceContext.pop();
}
Statics.setSlotContents(rvmFieldOffset, 0);
if (!VM.runningTool)
bootImage.countNulledReference();
invalidEntrys.add(jdkType.getName());
}
} else {
// no accessor and we don't know the type so nullify
if (verbosity.isAtLeast(DETAILED)) {
traceContext.push(rvmFieldType.toString(), rvmFieldType.toString(), rvmFieldName);
traceContext.traceFieldNotInHostJdk();
traceContext.pop();
}
Statics.setSlotContents(rvmFieldOffset, 0);
if (!VM.runningTool)
bootImage.countNulledReference();
invalidEntrys.add(rvmField.getDeclaringClass().toString());
}
continue;
}
if (!Modifier.isStatic(jdkFieldAcc.getModifiers())) {
if (verbosity.isAtLeast(DETAILED))
traceContext.push(rvmFieldType.toString(), jdkType.getName(), rvmFieldName);
if (verbosity.isAtLeast(DETAILED))
traceContext.traceFieldNotStaticInHostJdk();
if (verbosity.isAtLeast(DETAILED))
traceContext.pop();
Statics.setSlotContents(rvmFieldOffset, 0);
if (!VM.runningTool)
bootImage.countNulledReference();
invalidEntrys.add(jdkType.getName());
continue;
}
if (!equalTypes(jdkFieldAcc.getType().getName(), rvmFieldType)) {
if (verbosity.isAtLeast(DETAILED))
traceContext.push(rvmFieldType.toString(), jdkType.getName(), rvmFieldName);
if (verbosity.isAtLeast(DETAILED))
traceContext.traceFieldDifferentTypeInHostJdk();
if (verbosity.isAtLeast(DETAILED))
traceContext.pop();
Statics.setSlotContents(rvmFieldOffset, 0);
if (!VM.runningTool)
bootImage.countNulledReference();
invalidEntrys.add(jdkType.getName());
continue;
}
if (verbosity.isAtLeast(DETAILED))
say(" populating jtoc slot ", String.valueOf(Statics.offsetAsSlot(rvmFieldOffset)), " with ", rvmField.toString());
if (rvmFieldType.isPrimitiveType()) {
// field is logical or numeric type
if (rvmFieldType.isBooleanType()) {
Statics.setSlotContents(rvmFieldOffset, jdkFieldAcc.getBoolean(null) ? 1 : 0);
} else if (rvmFieldType.isByteType()) {
Statics.setSlotContents(rvmFieldOffset, jdkFieldAcc.getByte(null));
} else if (rvmFieldType.isCharType()) {
Statics.setSlotContents(rvmFieldOffset, jdkFieldAcc.getChar(null));
} else if (rvmFieldType.isShortType()) {
Statics.setSlotContents(rvmFieldOffset, jdkFieldAcc.getShort(null));
} else if (rvmFieldType.isIntType()) {
Statics.setSlotContents(rvmFieldOffset, jdkFieldAcc.getInt(null));
} else if (rvmFieldType.isLongType()) {
// note: Endian issues handled in setSlotContents.
Statics.setSlotContents(rvmFieldOffset, jdkFieldAcc.getLong(null));
} else if (rvmFieldType.isFloatType()) {
float f = jdkFieldAcc.getFloat(null);
Statics.setSlotContents(rvmFieldOffset, Float.floatToIntBits(f));
} else if (rvmFieldType.isDoubleType()) {
double d = jdkFieldAcc.getDouble(null);
// note: Endian issues handled in setSlotContents.
Statics.setSlotContents(rvmFieldOffset, Double.doubleToLongBits(d));
} else if (rvmFieldType.equals(TypeReference.Address) || rvmFieldType.equals(TypeReference.Word) || rvmFieldType.equals(TypeReference.Extent) || rvmFieldType.equals(TypeReference.Offset)) {
Object o = jdkFieldAcc.get(null);
String msg = " static field " + rvmField.toString();
boolean warn = rvmFieldType.equals(TypeReference.Address);
Statics.setSlotContents(rvmFieldOffset, getWordValue(o, msg, warn));
} else {
fail("unexpected primitive field type: " + rvmFieldType);
}
} else {
// field is reference type
final Object o = jdkFieldAcc.get(null);
if (verbosity.isAtLeast(ADDRESSES))
say(" setting with ", Services.addressAsHexString(Magic.objectAsAddress(o)));
Statics.setSlotContents(rvmFieldOffset, o);
}
}
}
if (verbosity.isAtLeast(DETAILED)) {
for (final String entry : invalidEntrys) {
say("Static fields of type are invalid: ", entry);
}
}
if (profile) {
stopTime = System.currentTimeMillis();
System.out.println("PROF: \tinitializing jtoc " + (stopTime - startTime) + " ms");
}
}
Aggregations