Search in sources :

Example 26 with RVMField

use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.

the class ObjectReplacer method transform.

@Override
public void transform() {
    // store the object's fields in a ArrayList
    ArrayList<RVMField> fields = getFieldsAsArrayList(klass);
    // create a scalar for each field. initialize the scalar to
    // default values before the object's def
    RegisterOperand[] scalars = new RegisterOperand[fields.size()];
    RegisterOperand def = reg.defList;
    Instruction defI = def.instruction;
    for (int i = 0; i < fields.size(); i++) {
        RVMField f = fields.get(i);
        Operand defaultValue = IRTools.getDefaultOperand(f.getType());
        scalars[i] = IRTools.moveIntoRegister(ir.regpool, defI, defaultValue);
        scalars[i].setType(f.getType());
    }
    transform2(this.reg, defI, scalars, fields, null);
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) RVMField(org.jikesrvm.classloader.RVMField) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 27 with RVMField

use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.

the class ObjectReplacer method scalarReplace.

/**
 * Replace a given use of a object with its scalar equivalent
 *
 * @param use the use to replace
 * @param scalars an array of scalar register operands to replace
 *                  the object's fields with
 * @param fields the object's fields
 * @param visited the registers that were already seen
 */
private void scalarReplace(RegisterOperand use, RegisterOperand[] scalars, ArrayList<RVMField> fields, Set<Register> visited) {
    Instruction inst = use.instruction;
    try {
        switch(inst.getOpcode()) {
            case PUTFIELD_opcode:
                {
                    FieldReference fr = PutField.getLocation(inst).getFieldRef();
                    if (VM.VerifyAssertions)
                        VM._assert(fr.isResolved());
                    RVMField f = fr.peekResolvedField();
                    int index = fields.indexOf(f);
                    TypeReference type = scalars[index].getType();
                    Operator moveOp = IRTools.getMoveOp(type);
                    Instruction i = Move.create(moveOp, scalars[index].copyRO(), PutField.getClearValue(inst));
                    inst.insertBefore(i);
                    DefUse.removeInstructionAndUpdateDU(inst);
                    DefUse.updateDUForNewInstruction(i);
                }
                break;
            case GETFIELD_opcode:
                {
                    FieldReference fr = GetField.getLocation(inst).getFieldRef();
                    if (VM.VerifyAssertions)
                        VM._assert(fr.isResolved());
                    RVMField f = fr.peekResolvedField();
                    int index = fields.indexOf(f);
                    TypeReference type = scalars[index].getType();
                    Operator moveOp = IRTools.getMoveOp(type);
                    Instruction i = Move.create(moveOp, GetField.getClearResult(inst), scalars[index].copyRO());
                    inst.insertBefore(i);
                    DefUse.removeInstructionAndUpdateDU(inst);
                    DefUse.updateDUForNewInstruction(i);
                }
                break;
            case MONITORENTER_opcode:
                inst.insertBefore(Empty.create(READ_CEILING));
                DefUse.removeInstructionAndUpdateDU(inst);
                break;
            case MONITOREXIT_opcode:
                inst.insertBefore(Empty.create(WRITE_FLOOR));
                DefUse.removeInstructionAndUpdateDU(inst);
                break;
            case CALL_opcode:
            case NULL_CHECK_opcode:
                // (SJF) TODO: Why wasn't this caught by BC2IR for
                // java.lang.Double.<init> (Ljava/lang/String;)V ?
                DefUse.removeInstructionAndUpdateDU(inst);
                break;
            case CHECKCAST_opcode:
            case CHECKCAST_NOTNULL_opcode:
            case CHECKCAST_UNRESOLVED_opcode:
                {
                    // We cannot handle removing the checkcast if the result of the
                    // checkcast test is unknown
                    TypeReference lhsType = TypeCheck.getType(inst).getTypeRef();
                    if (ClassLoaderProxy.includesType(lhsType, klass.getTypeRef()) == YES) {
                        if (visited == null) {
                            visited = new HashSet<Register>();
                        }
                        Register copy = TypeCheck.getResult(inst).getRegister();
                        if (!visited.contains(copy)) {
                            visited.add(copy);
                            transform2(copy, inst, scalars, fields, visited);
                        // NB will remove inst
                        } else {
                            DefUse.removeInstructionAndUpdateDU(inst);
                        }
                    } else {
                        Instruction i2 = Trap.create(TRAP, null, TrapCodeOperand.CheckCast());
                        DefUse.replaceInstructionAndUpdateDU(inst, i2);
                    }
                }
                break;
            case INSTANCEOF_opcode:
            case INSTANCEOF_NOTNULL_opcode:
            case INSTANCEOF_UNRESOLVED_opcode:
                {
                    // We cannot handle removing the instanceof if the result of the
                    // instanceof test is unknown
                    TypeReference lhsType = InstanceOf.getType(inst).getTypeRef();
                    Instruction i2;
                    if (ClassLoaderProxy.includesType(lhsType, klass.getTypeRef()) == YES) {
                        i2 = Move.create(INT_MOVE, InstanceOf.getClearResult(inst), IC(1));
                    } else {
                        i2 = Move.create(INT_MOVE, InstanceOf.getClearResult(inst), IC(0));
                    }
                    DefUse.replaceInstructionAndUpdateDU(inst, i2);
                }
                break;
            case GET_OBJ_TIB_opcode:
                {
                    Instruction i2 = Move.create(REF_MOVE, GuardedUnary.getClearResult(inst), new TIBConstantOperand(klass));
                    DefUse.replaceInstructionAndUpdateDU(inst, i2);
                }
                break;
            case REF_MOVE_opcode:
                {
                    if (visited == null) {
                        visited = new HashSet<Register>();
                    }
                    Register copy = Move.getResult(use.instruction).getRegister();
                    if (!visited.contains(copy)) {
                        visited.add(copy);
                        transform2(copy, inst, scalars, fields, visited);
                    // NB will remove inst
                    } else {
                        DefUse.removeInstructionAndUpdateDU(inst);
                    }
                }
                break;
            default:
                throw new OptimizingCompilerException("ObjectReplacer: unexpected use " + inst);
        }
    } catch (Exception e) {
        OptimizingCompilerException oe = new OptimizingCompilerException("Error handling use (" + use + ") of: " + inst);
        oe.initCause(e);
        throw oe;
    }
}
Also used : Operator(org.jikesrvm.compilers.opt.ir.Operator) FieldReference(org.jikesrvm.classloader.FieldReference) Register(org.jikesrvm.compilers.opt.ir.Register) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) RVMField(org.jikesrvm.classloader.RVMField) TypeReference(org.jikesrvm.classloader.TypeReference) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) HashSet(java.util.HashSet)

Example 28 with RVMField

use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.

the class SSADictionary method registerUse.

/**
 * Register that an instruction uses a heap variable for a given
 * field.
 *
 * @param s the instruction in question
 * @param fr the field heap variable the instruction uses
 */
private void registerUse(Instruction s, FieldReference fr) {
    if (VM.VerifyAssertions)
        VM._assert(s.operator() != PHI);
    RVMField f = fr.peekResolvedField();
    HeapOperand<Object> H;
    if (f == null) {
        // can't resolve field at compile time.
        // This isn't quite correct, but is somewhat close.
        // See defect 3481.
        H = new HeapOperand<Object>(findOrCreateHeapVariable(fr));
    } else {
        // not included in the set
        if (heapTypes != null) {
            if (!heapTypes.contains(f)) {
                return;
            }
        }
        H = new HeapOperand<Object>(findOrCreateHeapVariable(f));
    }
    HeapOperand<Object>[] Hprime = new HeapOperand[1];
    Hprime[0] = H;
    Hprime[0].setInstruction(s);
    uses.put(s, Hprime);
}
Also used : HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) RVMField(org.jikesrvm.classloader.RVMField)

Example 29 with RVMField

use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.

the class VMObjectStreamClass method setDoubleNative.

static void setDoubleNative(Field field, Object obj, double val) {
    RVMField f = java.lang.reflect.JikesRVMSupport.getFieldOf(field);
    f.setDoubleValueUnchecked(obj, val);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 30 with RVMField

use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.

the class VMObjectStreamClass method setCharNative.

static void setCharNative(Field field, Object obj, char val) {
    RVMField f = java.lang.reflect.JikesRVMSupport.getFieldOf(field);
    f.setCharValueUnchecked(obj, val);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Aggregations

RVMField (org.jikesrvm.classloader.RVMField)80 TypeReference (org.jikesrvm.classloader.TypeReference)21 Offset (org.vmmagic.unboxed.Offset)14 RVMClass (org.jikesrvm.classloader.RVMClass)12 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)9 Field (java.lang.reflect.Field)8 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 Atom (org.jikesrvm.classloader.Atom)7 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)6 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)6 RVMType (org.jikesrvm.classloader.RVMType)5 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)5 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)5 Address (org.vmmagic.unboxed.Address)5 FieldReference (org.jikesrvm.classloader.FieldReference)4 RVMMethod (org.jikesrvm.classloader.RVMMethod)4 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)4 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)4 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)4