Search in sources :

Example 6 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class MemoryManager method newRuntimeTable.

/**
 * Allocates a new runtime table (at runtime).
 *
 * @param size The size of the table
 * @param type the type for the table
 * @return the newly allocated table
 */
@NoInline
@Interruptible
public static Object newRuntimeTable(int size, RVMType type) {
    if (VM.VerifyAssertions)
        VM._assert(VM.runningVM);
    TIB realTib = type.getTypeInformationBlock();
    RVMArray fakeType = RVMType.WordArrayType;
    TIB fakeTib = fakeType.getTypeInformationBlock();
    int headerSize = ObjectModel.computeArrayHeaderSize(fakeType);
    int align = ObjectModel.getAlignment(fakeType);
    int offset = ObjectModel.getOffsetForAlignment(fakeType, false);
    int width = fakeType.getLogElementSize();
    /* Allocate a word array */
    Object array = allocateArray(size, width, headerSize, fakeTib, type.getMMAllocator(), align, offset, Plan.DEFAULT_SITE);
    /* Now we replace the TIB */
    ObjectModel.setTIB(array, realTib);
    return array;
}
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)

Example 7 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class MemoryManager method newTIB.

/**
 * Allocates a new type information block (TIB).
 *
 * @param numVirtualMethods the number of virtual method slots in the TIB
 * @param alignCode alignment encoding for the TIB
 * @return the new TIB
 * @see AlignmentEncoding
 */
@NoInline
@Interruptible
public static TIB newTIB(int numVirtualMethods, int alignCode) {
    int elements = TIB.computeSize(numVirtualMethods);
    if (!VM.runningVM) {
        return TIB.allocate(elements, alignCode);
    }
    if (alignCode == AlignmentEncoding.ALIGN_CODE_NONE) {
        return (TIB) newRuntimeTable(elements, RVMType.TIBType);
    }
    RVMType type = RVMType.TIBType;
    if (VM.VerifyAssertions)
        VM._assert(VM.runningVM);
    TIB realTib = type.getTypeInformationBlock();
    RVMArray fakeType = RVMType.WordArrayType;
    TIB fakeTib = fakeType.getTypeInformationBlock();
    int headerSize = ObjectModel.computeArrayHeaderSize(fakeType);
    int align = ObjectModel.getAlignment(fakeType);
    int offset = ObjectModel.getOffsetForAlignment(fakeType, false);
    int width = fakeType.getLogElementSize();
    int elemBytes = elements << width;
    if (elemBytes < 0 || (elemBytes >>> width) != elements) {
        /* asked to allocate more than Integer.MAX_VALUE bytes */
        throwLargeArrayOutOfMemoryError();
    }
    int size = elemBytes + headerSize + AlignmentEncoding.padding(alignCode);
    Selected.Mutator mutator = Selected.Mutator.get();
    Address region = allocateSpace(mutator, size, align, offset, type.getMMAllocator(), Plan.DEFAULT_SITE);
    region = AlignmentEncoding.adjustRegion(alignCode, region);
    Object result = ObjectModel.initializeArray(region, fakeTib, elements, size);
    mutator.postAlloc(ObjectReference.fromObject(result), ObjectReference.fromObject(fakeTib), size, type.getMMAllocator());
    /* Now we replace the TIB */
    ObjectModel.setTIB(result, realTib);
    return (TIB) result;
}
Also used : Address(org.vmmagic.unboxed.Address) RVMArray(org.jikesrvm.classloader.RVMArray) RVMType(org.jikesrvm.classloader.RVMType) TIB(org.jikesrvm.objectmodel.TIB) Entrypoint(org.vmmagic.pragma.Entrypoint) Interruptible(org.vmmagic.pragma.Interruptible) NoInline(org.vmmagic.pragma.NoInline)

Example 8 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class MemoryManager method newStack.

/**
 * Allocate a stack
 * @param bytes the number of bytes to allocate. Must be greater than
 *  0.
 * @return The stack
 */
@NoInline
@Unpreemptible
public static byte[] newStack(int bytes) {
    if (bytes <= 0) {
        if (VM.VerifyAssertions) {
            VM.sysWrite("Invalid stack size: ");
            VM.sysWrite(bytes);
            VM.sysWriteln("!");
            VM._assert(VM.NOT_REACHED, "Attempted to create stack with size (in bytes) of 0 or smaller!");
        } else {
            bytes = StackFrameLayout.getStackSizeNormal();
        }
    }
    if (!VM.runningVM) {
        return new byte[bytes];
    } else {
        RVMArray stackType = RVMArray.ByteArray;
        int headerSize = ObjectModel.computeArrayHeaderSize(stackType);
        int align = ObjectModel.getAlignment(stackType);
        int offset = ObjectModel.getOffsetForAlignment(stackType, false);
        int width = stackType.getLogElementSize();
        TIB stackTib = stackType.getTypeInformationBlock();
        return (byte[]) allocateArray(bytes, width, headerSize, stackTib, Plan.ALLOC_STACK, align, offset, Plan.DEFAULT_SITE);
    }
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) TIB(org.jikesrvm.objectmodel.TIB) Entrypoint(org.vmmagic.pragma.Entrypoint) Unpreemptible(org.vmmagic.pragma.Unpreemptible) NoInline(org.vmmagic.pragma.NoInline)

Example 9 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class MemoryManagerTest method allocateArrayTestPositive.

@Test
public void allocateArrayTestPositive() {
    int size = 20;
    RVMArray arrayType = RVMArray.IntArray;
    int headerSize = ObjectModel.computeArrayHeaderSize(arrayType);
    int align = ObjectModel.getAlignment(arrayType);
    int offset = ObjectModel.getOffsetForAlignment(arrayType, false);
    int width = arrayType.getLogElementSize();
    TIB arrayTib = arrayType.getTypeInformationBlock();
    int[] test = (int[]) MemoryManager.allocateArray(size, width, headerSize, arrayTib, ALLOC_NON_MOVING, align, offset, DEFAULT_SITE);
    assertEquals(test.length, 20);
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) TIB(org.jikesrvm.objectmodel.TIB) Test(org.junit.Test)

Example 10 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class MemoryManagerTest method allocateArrayTestOverflowToPositive.

@Test(expected = OutOfMemoryError.class)
public void allocateArrayTestOverflowToPositive() {
    int size = 1 << 30;
    RVMArray arrayType = RVMArray.IntArray;
    int headerSize = ObjectModel.computeArrayHeaderSize(arrayType);
    int align = ObjectModel.getAlignment(arrayType);
    int offset = ObjectModel.getOffsetForAlignment(arrayType, false);
    int width = arrayType.getLogElementSize();
    TIB arrayTib = arrayType.getTypeInformationBlock();
    int[] test = (int[]) MemoryManager.allocateArray(size, width, headerSize, arrayTib, ALLOC_NON_MOVING, align, offset, DEFAULT_SITE);
    fail("FAIL! Created array with length " + test.length);
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) TIB(org.jikesrvm.objectmodel.TIB) Test(org.junit.Test)

Aggregations

TIB (org.jikesrvm.objectmodel.TIB)36 Entrypoint (org.vmmagic.pragma.Entrypoint)16 RVMArray (org.jikesrvm.classloader.RVMArray)14 RVMType (org.jikesrvm.classloader.RVMType)13 NoInline (org.vmmagic.pragma.NoInline)9 Interruptible (org.vmmagic.pragma.Interruptible)8 Address (org.vmmagic.unboxed.Address)7 Test (org.junit.Test)5 CodeArray (org.jikesrvm.compilers.common.CodeArray)4 ITable (org.jikesrvm.objectmodel.ITable)4 RVMClass (org.jikesrvm.classloader.RVMClass)3 RVMMethod (org.jikesrvm.classloader.RVMMethod)3 Offset (org.vmmagic.unboxed.Offset)3 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 IMT (org.jikesrvm.objectmodel.IMT)2 ITableArray (org.jikesrvm.objectmodel.ITableArray)2 Inline (org.vmmagic.pragma.Inline)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1