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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations