Search in sources :

Example 16 with CodeArray

use of org.jikesrvm.compilers.common.CodeArray in project JikesRVM by JikesRVM.

the class BaselineCompiler method compile.

/**
 * Top level driver for baseline compilation of a method.
 */
protected void compile() {
    if (shouldPrint)
        printStartHeader(method);
    // Phase 1: GC map computation
    long start = 0;
    try {
        if (VM.MeasureCompilationPhases) {
            start = Time.nanoTime();
        }
        refMaps = new ReferenceMaps((BaselineCompiledMethod) compiledMethod, stackHeights, localTypes);
    } finally {
        if (VM.MeasureCompilationPhases) {
            long end = Time.nanoTime();
            gcMapNanos += end - start;
        }
    }
    /* reference map and stackheights were computed using original bytecodes
     * and possibly new operand words
     * recompute the stack height, but keep the operand words of the code
     * generation consistent with reference map
     * TODO: revisit this code as part of OSR redesign
     */
    // Phase 2: OSR setup\
    boolean edge_counters = options.PROFILE_EDGE_COUNTERS;
    try {
        if (VM.MeasureCompilationPhases) {
            start = Time.nanoTime();
        }
        if (VM.BuildForAdaptiveSystem && method.isForOsrSpecialization()) {
            options.PROFILE_EDGE_COUNTERS = false;
            // we already allocated enough space for stackHeights, shift it back first
            System.arraycopy(stackHeights, 0, stackHeights, method.getOsrPrologueLength(), // NB: getBytecodeLength returns back the length of original bytecodes
            method.getBytecodeLength());
            // compute stack height for prologue
            new BytecodeTraverser().prologueStackHeights(method, method.getOsrPrologue(), stackHeights);
        }
    } finally {
        if (VM.MeasureCompilationPhases) {
            long end = Time.nanoTime();
            osrSetupNanos += end - start;
        }
    }
    // Phase 3: Code generation
    int[] bcMap;
    MachineCode machineCode;
    CodeArray instructions;
    try {
        if (VM.MeasureCompilationPhases) {
            start = Time.nanoTime();
        }
        // determine if we are going to insert edge counters for this method
        if (options.PROFILE_EDGE_COUNTERS && !method.getDeclaringClass().hasBridgeFromNativeAnnotation() && (method.hasCondBranch() || method.hasSwitch())) {
            // yes, we will inject counters for this method.
            ((BaselineCompiledMethod) compiledMethod).setHasCounterArray();
        }
        // do platform specific tasks before generating code;
        initializeCompiler();
        machineCode = genCode();
        instructions = machineCode.getInstructions();
        bcMap = machineCode.getBytecodeMap();
    } finally {
        if (VM.MeasureCompilationPhases) {
            long end = Time.nanoTime();
            codeGenNanos += end - start;
        }
    }
    // Phase 4: OSR part 2
    try {
        if (VM.MeasureCompilationPhases) {
            start = Time.nanoTime();
        }
        if (VM.BuildForAdaptiveSystem && method.isForOsrSpecialization()) {
            int[] newmap = new int[bcMap.length - method.getOsrPrologueLength()];
            System.arraycopy(bcMap, method.getOsrPrologueLength(), newmap, 0, newmap.length);
            machineCode.setBytecodeMap(newmap);
            bcMap = newmap;
            // switch back to original state
            method.finalizeOsrSpecialization();
            // restore options
            options.PROFILE_EDGE_COUNTERS = edge_counters;
        }
    } finally {
        if (VM.MeasureCompilationPhases) {
            long end = Time.nanoTime();
            osrSetupNanos += end - start;
        }
    }
    // Phase 5: Encode machine code maps
    try {
        if (VM.MeasureCompilationPhases) {
            start = Time.nanoTime();
        }
        if (method.isSynchronized()) {
            ((BaselineCompiledMethod) compiledMethod).setLockAcquisitionOffset(lockOffset);
        }
        ((BaselineCompiledMethod) compiledMethod).encodeMappingInfo(refMaps, bcMap);
        compiledMethod.compileComplete(instructions);
        if (edgeCounterIdx > 0) {
            EdgeCounts.allocateCounters(method, edgeCounterIdx);
        }
        if (shouldPrint) {
            ((BaselineCompiledMethod) compiledMethod).printExceptionTable();
            printEndHeader(method);
        }
    } finally {
        if (VM.MeasureCompilationPhases) {
            long end = Time.nanoTime();
            encodingNanos += end - start;
        }
    }
}
Also used : CodeArray(org.jikesrvm.compilers.common.CodeArray) BytecodeTraverser(org.jikesrvm.osr.BytecodeTraverser)

Example 17 with CodeArray

use of org.jikesrvm.compilers.common.CodeArray in project JikesRVM by JikesRVM.

the class MemoryManager method allocateCode.

/**
 * Allocate a CodeArray into a code space.
 * Currently the interface is fairly primitive;
 * just the number of instructions in the code array and a boolean
 * to indicate hot or cold code.
 * @param numInstrs number of instructions
 * @param isHot is this a request for hot code space allocation?
 * @return The  array
 */
@NoInline
@Interruptible
public static CodeArray allocateCode(int numInstrs, boolean isHot) {
    RVMArray type = RVMType.CodeArrayType;
    int headerSize = ObjectModel.computeArrayHeaderSize(type);
    int align = ObjectModel.getAlignment(type);
    int offset = ObjectModel.getOffsetForAlignment(type, false);
    int width = type.getLogElementSize();
    TIB tib = type.getTypeInformationBlock();
    int allocator = isHot ? Plan.ALLOC_HOT_CODE : Plan.ALLOC_COLD_CODE;
    return (CodeArray) allocateArray(numInstrs, width, headerSize, tib, allocator, align, offset, Plan.DEFAULT_SITE);
}
Also used : CodeArray(org.jikesrvm.compilers.common.CodeArray) 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 18 with CodeArray

use of org.jikesrvm.compilers.common.CodeArray in project JikesRVM by JikesRVM.

the class TIB method initializeInternalLazyCompilationTrampoline.

/**
 * Initialize the lazy method invoker trampoline for this tib.
 */
@NoInline
public void initializeInternalLazyCompilationTrampoline() {
    CodeArray source = LazyCompilationTrampoline.getInstructions();
    int targetSlot = lazyMethodInvokerTrampolineIndex();
    int logIPW = LOG_BYTES_IN_ADDRESS - ArchConstants.getLogInstructionWidth();
    int logIPI = LOG_BYTES_IN_INT - ArchConstants.getLogInstructionWidth();
    if (VM.VerifyAssertions)
        VM._assert(ArchConstants.getLogInstructionWidth() <= LOG_BYTES_IN_INT);
    int mask = 0xFFFFFFFF >>> (((1 << logIPI) - 1) << LOG_BITS_IN_BYTE);
    for (int i = 0; i < lazyMethodInvokerTrampolineWords(); i++) {
        Word currentWord = Word.zero();
        int base = i << logIPW;
        for (int j = 0; j < (1 << logIPW) && (base + j) < source.length(); j++) {
            Word currentEntry = Word.fromIntZeroExtend(source.get(base + j) & mask);
            currentEntry = currentEntry.lsh(((VM.LittleEndian ? j : (1 << logIPW) - (j + 1)) << ArchConstants.getLogInstructionWidth()) << LOG_BITS_IN_BYTE);
            currentWord = currentWord.or(currentEntry);
        }
        set(targetSlot + i, currentWord);
    }
}
Also used : CodeArray(org.jikesrvm.compilers.common.CodeArray) Word(org.vmmagic.unboxed.Word) NoInline(org.vmmagic.pragma.NoInline)

Aggregations

CodeArray (org.jikesrvm.compilers.common.CodeArray)18 Address (org.vmmagic.unboxed.Address)6 Offset (org.vmmagic.unboxed.Offset)6 RVMClass (org.jikesrvm.classloader.RVMClass)4 RVMMethod (org.jikesrvm.classloader.RVMMethod)4 TIB (org.jikesrvm.objectmodel.TIB)4 Entrypoint (org.vmmagic.pragma.Entrypoint)4 NoInline (org.vmmagic.pragma.NoInline)4 RVMType (org.jikesrvm.classloader.RVMType)3 TypeReference (org.jikesrvm.classloader.TypeReference)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 TreeSet (java.util.TreeSet)2 RVMArray (org.jikesrvm.classloader.RVMArray)2 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 Interruptible (org.vmmagic.pragma.Interruptible)2 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1