protected void compile() { if (shouldPrint) printStartHeader(method);   long start = 0; if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles();  VM_ReferenceMaps refMaps = new VM_ReferenceMaps((VM_BaselineCompiledMethod)compiledMethod, stackHeights);  VM_ReferenceMaps refMaps = new VM_ReferenceMaps(compiledMethod, stackHeights);   if (VM.MeasureCompilation) { long end = VM_Thread.getCurrentThread().accumulateCycles(); gcMapCycles += end - start; }     if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles(); boolean edge_counters = options.EDGE_COUNTERS; if (method.isForOsrSpecialization()) { options.EDGE_COUNTERS = false;  System.arraycopy(stackHeights, 0, stackHeights, method.getOsrPrologueLength(), method.getBytecodeLength());   new OSR_BytecodeTraverser().prologueStackHeights(method, method.getOsrPrologue(), stackHeights); } if (VM.MeasureCompilation) { long end = VM_Thread.getCurrentThread().accumulateCycles(); osrSetupCycles += end - start; }    if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles();    if (options.EDGE_COUNTERS && !method.getDeclaringClass().isBridgeFromNative() && (method.hasCondBranch() || method.hasSwitch())) { ((VM_BaselineCompiledMethod)compiledMethod).setHasCounterArray(); }   VM_MachineCode  machineCode  = genCode(); VM_CodeArray    instructions = machineCode.getInstructions(); int[]           bcMap        = machineCode.getBytecodeMap(); if (VM.MeasureCompilation) { long end = VM_Thread.getCurrentThread().accumulateCycles(); codeGenCycles += end - start; }     if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles(); if (method.isForOsrSpecialization()) { int[] newmap = new int[bcMap.length - method.getOsrPrologueLength()]; System.arraycopy(bcMap, method.getOsrPrologueLength(), newmap, 0, newmap.length); machineCode.setBytecodeMap(newmap); bcMap = newmap;  method.finalizeOsrSpecialization();  options.EDGE_COUNTERS = edge_counters; } if (VM.MeasureCompilation) { long end = VM_Thread.getCurrentThread().accumulateCycles(); osrSetupCycles += end - start; }    if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles(); if (method.isSynchronized()) {  ((VM_BaselineCompiledMethod)compiledMethod).setLockAcquisitionOffset(lockOffset);  compiledMethod.setLockAcquisitionOffset(lockOffset);  }  ((VM_BaselineCompiledMethod)compiledMethod).encodeMappingInfo(refMaps, bcMap, instructions.length());  compiledMethod.encodeMappingInfo(refMaps, bcMap, instructions.length());   compiledMethod.compileComplete(instructions); if (edgeCounterIdx > 0) { VM_EdgeCounts.allocateCounters(method, edgeCounterIdx); } if (shouldPrint) {  ((VM_BaselineCompiledMethod)compiledMethod).printExceptionTable();  compiledMethod.printExceptionTable();   printEndHeader(method); } if (VM.MeasureCompilation) { long end = VM_Thread.getCurrentThread().accumulateCycles(); encodingCycles += end - start; }
public static VM_CompiledMethod compile (VM_NormalMethod method) { VM_BaselineCompiledMethod cm = (VM_BaselineCompiledMethod)VM_CompiledMethods.createCompiledMethod(method, VM_CompiledMethod.BASELINE); new VM_Compiler(cm).compile(); return cm;
  protected void compile() {    if (shouldPrint) printStartHeader(method);    // Phase 1: GC map computation    long start = 0;    if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles();    //-#if RVM_WITH_QUICK_COMPILER    VM_ReferenceMaps refMaps = new VM_ReferenceMaps((VM_BaselineCompiledMethod)compiledMethod, stackHeights);    //-#else    VM_ReferenceMaps refMaps = new VM_ReferenceMaps(compiledMethod, stackHeights);    //-#endif    if (VM.MeasureCompilation) {      long end = VM_Thread.getCurrentThread().accumulateCycles();      gcMapCycles += end - start;    }    //-#if RVM_WITH_OSR    /* 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 consistant with reference map      */    // Phase 2: OSR setup    if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles();    boolean edge_counters = options.EDGE_COUNTERS;    if (method.isForOsrSpecialization()) {      options.EDGE_COUNTERS = false;      // we already allocated enough space for stackHeights, shift it back first      System.arraycopy(stackHeights, 0, stackHeights,                        method.getOsrPrologueLength(),                        method.getBytecodeLength());   // NB: getBytecodeLength returns back the length of original bytecodes            // compute stack height for prologue      new OSR_BytecodeTraverser().prologueStackHeights(method, method.getOsrPrologue(), stackHeights);    }     if (VM.MeasureCompilation) {      long end = VM_Thread.getCurrentThread().accumulateCycles();      osrSetupCycles += end - start;    }    //-#endif        // Phase 3: Code gen    if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles();    //-#if RVM_WITH_QUICK_COMPILER    // determine if we are going to insert edge counters for this method    if (options.EDGE_COUNTERS &&         !method.getDeclaringClass().isBridgeFromNative() &&        (method.hasCondBranch() || method.hasSwitch())) {      ((VM_BaselineCompiledMethod)compiledMethod).setHasCounterArray(); // yes, we will inject counters for this method.    }    //-#endif    VM_MachineCode  machineCode  = genCode();    VM_CodeArray    instructions = machineCode.getInstructions();    int[]           bcMap        = machineCode.getBytecodeMap();    if (VM.MeasureCompilation) {      long end = VM_Thread.getCurrentThread().accumulateCycles();      codeGenCycles += end - start;    }    //-#if RVM_WITH_OSR    /* adjust machine code map, and restore original bytecode     * for building reference map later.     */    // Phase 4: OSR part 2    if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles();    if (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.EDGE_COUNTERS = edge_counters;         }    if (VM.MeasureCompilation) {      long end = VM_Thread.getCurrentThread().accumulateCycles();      osrSetupCycles += end - start;    }    //-#endif    // Phase 5: Encode machine code maps    if (VM.MeasureCompilation) start = VM_Thread.getCurrentThread().accumulateCycles();    if (method.isSynchronized()) {      //-#if RVM_WITH_QUICK_COMPILER      ((VM_BaselineCompiledMethod)compiledMethod).setLockAcquisitionOffset(lockOffset);      //-#else      compiledMethod.setLockAcquisitionOffset(lockOffset);      //-#endif    }    //-#if RVM_WITH_QUICK_COMPILER    ((VM_BaselineCompiledMethod)compiledMethod).encodeMappingInfo(refMaps, bcMap, instructions.length());    //-#else    compiledMethod.encodeMappingInfo(refMaps, bcMap, instructions.length());    //-#endif    compiledMethod.compileComplete(instructions);    if (edgeCounterIdx > 0) {      VM_EdgeCounts.allocateCounters(method, edgeCounterIdx);    }    if (shouldPrint) {      //-#if RVM_WITH_QUICK_COMPILER      ((VM_BaselineCompiledMethod)compiledMethod).printExceptionTable();      //-#else      compiledMethod.printExceptionTable();      //-#endif      printEndHeader(method);    }    if (VM.MeasureCompilation) {      long end = VM_Thread.getCurrentThread().accumulateCycles();      encodingCycles += end - start;    }  }