Search in sources :

Example 11 with Extent

use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.

the class BootImageWriter method copyMagicArrayToBootImage.

/**
 * Copy a unboxed array type to the boot image
 * @param jdkObject object representation
 * @param rvmArrayType type of array
 * @param allocOnly allocate object don't write to fields
 * @param overwriteAddress addresss to write to if overwriting
 * @param parentObject object containing array
 * @return address of array
 * @throws IllegalAccessException
 */
private static Address copyMagicArrayToBootImage(Object jdkObject, RVMArray rvmArrayType, boolean allocOnly, Address overwriteAddress, Object parentObject) throws IllegalAccessException {
    // Return object if it is already copied and not being overwritten
    BootImageMap.Entry mapEntry = BootImageMap.findOrCreateEntry(jdkObject);
    if ((!mapEntry.imageAddress.EQ(OBJECT_NOT_ALLOCATED)) && overwriteAddress.isMax()) {
        return mapEntry.imageAddress;
    }
    if (verbosity.isAtLeast(DETAILED))
        depth++;
    RVMType rvmElementType = rvmArrayType.getElementType();
    // allocate space in image
    int arrayCount = Array.getLength(jdkObject);
    Address arrayImageAddress;
    if (overwriteAddress.isMax()) {
        if (rvmElementType.equals(RVMType.CodeType)) {
            arrayImageAddress = bootImage.allocateCode(rvmArrayType, arrayCount);
        } else {
            boolean needsIdentityHash = mapEntry.requiresIdentityHashCode();
            int identityHashValue = mapEntry.getIdentityHashCode();
            arrayImageAddress = bootImage.allocateArray(rvmArrayType, arrayCount, needsIdentityHash, identityHashValue, AlignmentEncoding.ALIGN_CODE_NONE);
        }
    } else {
        arrayImageAddress = overwriteAddress;
    }
    mapEntry.imageAddress = arrayImageAddress;
    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 arraySize = rvmArrayType.getInstanceSize(arrayCount);
            say(tab, "Copying array  ", rvmArrayType.toString(), "   length=", String.valueOf(arrayCount), (arraySize >= LARGE_ARRAY_SIZE) ? " large object!!!" : "");
        }
    }
    // copy array elements from host jdk address space into image
    if (rvmElementType.equals(RVMType.CodeType)) {
        if (VM.BuildForIA32) {
            byte[] values = (byte[]) jdkObject;
            for (int i = 0; i < arrayCount; ++i) bootImage.setByte(arrayImageAddress.plus(i), values[i]);
        } else {
            int[] values = (int[]) jdkObject;
            for (int i = 0; i < arrayCount; ++i) bootImage.setFullWord(arrayImageAddress.plus(i << LOG_BYTES_IN_INT), values[i]);
        }
    } else if (rvmElementType.equals(RVMType.AddressType)) {
        Address[] values = (Address[]) jdkObject;
        for (int i = 0; i < arrayCount; i++) {
            Address addr = values[i];
            String msg = "Address array element";
            bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, true), false, false);
        }
    } else if (rvmElementType.equals(RVMType.WordType)) {
        Word[] values = (Word[]) jdkObject;
        for (int i = 0; i < arrayCount; i++) {
            String msg = "Word array element ";
            Word addr = values[i];
            bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, false), false, false);
        }
    } else if (rvmElementType.equals(RVMType.OffsetType)) {
        Offset[] values = (Offset[]) jdkObject;
        for (int i = 0; i < arrayCount; i++) {
            String msg = "Offset array element " + i;
            Offset addr = values[i];
            bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, false), false, false);
        }
    } else if (rvmElementType.equals(RVMType.ExtentType)) {
        Extent[] values = (Extent[]) jdkObject;
        for (int i = 0; i < arrayCount; i++) {
            String msg = "Extent array element ";
            Extent addr = values[i];
            bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, false), false, false);
        }
    } else {
        fail("unexpected magic array type: " + rvmArrayType);
    }
    // copy object's TIB into image, if it's not there already
    if (!allocOnly) {
        copyTIBToBootImage(rvmArrayType, jdkObject, mapEntry.imageAddress);
    }
    if (verbosity.isAtLeast(DETAILED))
        depth--;
    return mapEntry.imageAddress;
}
Also used : Word(org.vmmagic.unboxed.Word) Address(org.vmmagic.unboxed.Address) Extent(org.vmmagic.unboxed.Extent) RVMType(org.jikesrvm.classloader.RVMType) Offset(org.vmmagic.unboxed.Offset)

Example 12 with Extent

use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.

the class AbstractSpaceDescriptorTest method testCreateDescriptorAddressAddress.

@Test
public void testCreateDescriptorAddressAddress() throws Throwable {
    Thread t = new MMTkThread() {

        public void run() {
            Extent chunkSize = Extent.fromLong(1L << VMLayoutConstants.LOG_BYTES_IN_CHUNK);
            Extent increment = chunkSize.toWord().rshl(2).toExtent();
            Extent size = chunkSize;
            Address base = Address.zero().plus(chunkSize);
            while (size.LE(VMLayoutConstants.MAX_SPACE_EXTENT)) {
                int d = SpaceDescriptor.createDescriptor(base, base.plus(size));
                for (Address addr = base; addr.LT(base.plus(size)); addr = addr.plus(increment)) {
                    if (VERBOSE)
                        System.out.printf("Testing address %s in space (%s,%s)%n", addr, base, base.plus(size));
                    Assert.assertTrue("addr " + addr + ", bounds(" + base + "," + base.plus(size) + ")", Space.isInSpace(d, addr));
                }
                Assert.assertFalse(Space.isInSpace(d, base.minus(4)));
                Assert.assertFalse(Space.isInSpace(d, base.plus(size)));
                size = size.plus(size);
            }
        }
    };
    runMMTkThread(t);
}
Also used : Address(org.vmmagic.unboxed.Address) Extent(org.vmmagic.unboxed.Extent) MMTkThread(org.mmtk.harness.scheduler.MMTkThread) MMTkThread(org.mmtk.harness.scheduler.MMTkThread) Test(org.junit.Test) BaseMMTkTest(org.mmtk.harness.tests.BaseMMTkTest)

Example 13 with Extent

use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.

the class TestNullChecks_Resolved method readVolatileExtentField.

private static Extent readVolatileExtentField(ClassWithVolatileExtentField c) {
    try {
        Extent readVolatile = c.e;
        System.out.println("Read value " + readVolatile.toLong() + " from field");
        return readVolatile;
    } catch (NullPointerException npe) {
        System.out.println("Caught NPE when reading Extent field");
        return NPE_EXTENT;
    }
}
Also used : Extent(org.vmmagic.unboxed.Extent)

Example 14 with Extent

use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.

the class TestNullChecks_Unresolved_ReadFromNonNullObject method readVolatileExtentField.

private static Extent readVolatileExtentField(ClassWithVolatileExtentField c) {
    try {
        Extent readVolatile = c.e;
        System.out.println("Read value " + readVolatile.toLong() + " from field");
        return readVolatile;
    } catch (NullPointerException npe) {
        System.out.println("Caught NPE when reading Extent field");
        return NPE_EXTENT;
    }
}
Also used : Extent(org.vmmagic.unboxed.Extent)

Example 15 with Extent

use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.

the class TestNullChecks_Unresolved_ReadFromNullObject method readVolatileExtentField.

private static Extent readVolatileExtentField(ClassWithVolatileExtentField c) {
    try {
        Extent readVolatile = c.e;
        System.out.println("Read value " + readVolatile.toLong() + " from field");
        return readVolatile;
    } catch (NullPointerException npe) {
        System.out.println("Caught NPE when reading Extent field");
        return NPE_EXTENT;
    }
}
Also used : Extent(org.vmmagic.unboxed.Extent)

Aggregations

Extent (org.vmmagic.unboxed.Extent)21 Address (org.vmmagic.unboxed.Address)11 Inline (org.vmmagic.pragma.Inline)3 Offset (org.vmmagic.unboxed.Offset)3 Test (org.junit.Test)2 BaseMMTkTest (org.mmtk.harness.tests.BaseMMTkTest)2 RawMemoryFreeList (org.mmtk.utility.RawMemoryFreeList)2 Interruptible (org.vmmagic.pragma.Interruptible)2 Word (org.vmmagic.unboxed.Word)2 Field (java.lang.reflect.Field)1 RVMField (org.jikesrvm.classloader.RVMField)1 RVMType (org.jikesrvm.classloader.RVMType)1 TypeReference (org.jikesrvm.classloader.TypeReference)1 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)1 DoubleConstantOperand (org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand)1 FloatConstantOperand (org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand)1 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)1 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)1 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)1 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)1