Search in sources :

Example 21 with RVMArray

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

the class ShortArrayReplacer method getReplacer.

/**
 * Returns an object representing this transformation for a given
 * allocation site.
 *
 * @param inst the allocation site
 * @param ir the governing IR
 * @return the object, or {@code null} if illegal
 */
public static ShortArrayReplacer getReplacer(Instruction inst, IR ir) {
    if (inst.operator() != NEWARRAY) {
        return null;
    }
    Operand size = NewArray.getSize(inst);
    if (!size.isIntConstant()) {
        return null;
    }
    int s = size.asIntConstant().value;
    if (s > ir.options.ESCAPE_MAX_ARRAY_SIZE) {
        return null;
    }
    if (s < 0) {
        return null;
    }
    Register r = NewArray.getResult(inst).getRegister();
    RVMArray a = NewArray.getType(inst).getVMType().asArray();
    // TODO :handle these cases
    if (containsUnsupportedUse(ir, r, s, a, null)) {
        return null;
    }
    return new ShortArrayReplacer(r, a, s, ir);
}
Also used : Register(org.jikesrvm.compilers.opt.ir.Register) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) RVMArray(org.jikesrvm.classloader.RVMArray)

Example 22 with RVMArray

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

the class RuntimeEntrypoints method buildMDAHelper.

/**
 * @param method Apparently unused (!)
 * @param numElements Number of elements to allocate for each dimension
 * @param dimIndex Current dimension to build
 * @param arrayType type of array that will result
 * @return a multi-dimensional array
 */
public static Object buildMDAHelper(RVMMethod method, int[] numElements, int dimIndex, RVMArray arrayType) {
    if (!arrayType.isInstantiated()) {
        arrayType.resolve();
        arrayType.instantiate();
    }
    int nelts = numElements[dimIndex];
    Object newObject = resolvedNewArray(nelts, arrayType);
    if (++dimIndex == numElements.length) {
        // all dimensions have been built
        return newObject;
    }
    Object[] newArray = (Object[]) newObject;
    RVMArray newArrayType = arrayType.getElementType().asArray();
    for (int i = 0; i < nelts; ++i) {
        newArray[i] = buildMDAHelper(method, numElements, dimIndex, newArrayType);
    }
    return newArray;
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 23 with RVMArray

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

the class RuntimeEntrypoints method unresolvedNewArray.

/**
 * Allocate something like "new Foo[]".
 * @param numElements number of array elements
 * @param id id of type reference of array to create.
 * @param site the site id of the calling allocation site
 * @return array with header installed and all fields set to zero/null
 * See also: bytecode 0xbc ("anewarray")
 */
@Entrypoint
public static Object unresolvedNewArray(int numElements, int id, int site) throws NoClassDefFoundError, OutOfMemoryError, NegativeArraySizeException {
    TypeReference tRef = TypeReference.getTypeRef(id);
    RVMType t = tRef.peekType();
    if (t == null) {
        t = tRef.resolve();
    }
    RVMArray array = t.asArray();
    if (!array.isInitialized()) {
        array.resolve();
        array.instantiate();
    }
    return resolvedNewArray(numElements, array, site);
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 24 with RVMArray

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

the class RuntimeEntrypoints method cloneArray.

/**
 * Clone an array
 *
 * @param obj the array to clone
 * @param type the type information for the array
 * @return the cloned object
 */
private static Object cloneArray(Object obj, RVMType type) throws OutOfMemoryError {
    RVMArray ary = type.asArray();
    int nelts = ObjectModel.getArrayLength(obj);
    Object newObj = resolvedNewArray(nelts, ary);
    System.arraycopy(obj, 0, newObj, 0, nelts);
    return newObj;
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 25 with RVMArray

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

the class MemoryManager method newNonMovingShortArray.

/**
 * Allocates a non moving short array.
 *
 * @param size The size of the array
 * @return the new non moving short array
 */
@NoInline
@Interruptible
public static short[] newNonMovingShortArray(int size) {
    if (!VM.runningVM) {
        return new short[size];
    }
    RVMArray arrayType = RVMArray.ShortArray;
    int headerSize = ObjectModel.computeArrayHeaderSize(arrayType);
    int align = ObjectModel.getAlignment(arrayType);
    int offset = ObjectModel.getOffsetForAlignment(arrayType, false);
    int width = arrayType.getLogElementSize();
    TIB arrayTib = arrayType.getTypeInformationBlock();
    return (short[]) allocateArray(size, width, headerSize, arrayTib, Plan.ALLOC_NON_MOVING, align, offset, Plan.DEFAULT_SITE);
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) TIB(org.jikesrvm.objectmodel.TIB) Entrypoint(org.vmmagic.pragma.Entrypoint) Interruptible(org.vmmagic.pragma.Interruptible) NoInline(org.vmmagic.pragma.NoInline)

Aggregations

RVMArray (org.jikesrvm.classloader.RVMArray)32 TIB (org.jikesrvm.objectmodel.TIB)14 Entrypoint (org.vmmagic.pragma.Entrypoint)14 RVMType (org.jikesrvm.classloader.RVMType)11 RVMClass (org.jikesrvm.classloader.RVMClass)9 NoInline (org.vmmagic.pragma.NoInline)8 TypeReference (org.jikesrvm.classloader.TypeReference)7 Interruptible (org.vmmagic.pragma.Interruptible)7 RVMMethod (org.jikesrvm.classloader.RVMMethod)6 Address (org.vmmagic.unboxed.Address)6 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)4 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)4 Test (org.junit.Test)4 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)3 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)3 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)3 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)3 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)3 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)3 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)3