From: <mic...@us...> - 2007-04-13 18:27:36
|
Revision: 47 http://svn.sourceforge.net/pearcolator/?rev=47&view=rev Author: michael_baer Date: 2007-04-13 11:27:36 -0700 (Fri, 13 Apr 2007) Log Message: ----------- Moved management of translated caches from the process space to the DynamicTranslationController. Modified Paths: -------------- src/org/binarytranslator/generic/execution/DynamicTranslationController.java src/org/binarytranslator/generic/execution/GdbController.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_Trace.java Modified: src/org/binarytranslator/generic/execution/DynamicTranslationController.java =================================================================== --- src/org/binarytranslator/generic/execution/DynamicTranslationController.java 2007-04-13 17:54:29 UTC (rev 46) +++ src/org/binarytranslator/generic/execution/DynamicTranslationController.java 2007-04-13 18:27:36 UTC (rev 47) @@ -1,7 +1,11 @@ package org.binarytranslator.generic.execution; +import java.util.Hashtable; + +import org.binarytranslator.DBT_Options; import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.generic.os.process.ProcessSpace; +import org.binarytranslator.vmInterface.DBT_Trace; import org.binarytranslator.vmInterface.DynamicCodeRunner; import org.jikesrvm.ArchitectureSpecific.VM_CodeArray; @@ -12,8 +16,13 @@ */ public class DynamicTranslationController extends ExecutionController { + /** Caches pre-translated code and uses the starting address of the code on the subject machine as a key*/ + private final Hashtable<Integer, DBT_Trace> codeHash; + public DynamicTranslationController(ProcessSpace ps) { super(ps); + + codeHash = new Hashtable<Integer, DBT_Trace>(); } @Override @@ -21,18 +30,66 @@ // The current block of compiled code. VM_CodeArray code; - try { - // interpretFrom(); // Interpreter - experimental while (ps.finished == false) { // Get the compiled code - code = ps.getCodeForPC(ps.getCurrentInstructionAddress()); + code = getCodeForPC(ps.getCurrentInstructionAddress()); + // Run the compiled code. ps.setCurrentInstructionAddress(DynamicCodeRunner.invokeCode(code, ps)); } } catch (BadInstructionException e) { System.out.println(e.toString()); } + } + + /** + * Returns an array of code starting at the given program counter. + * @param pc + * The program counter at which the code is supposed to start. + * @return + * An executable VM_CodeArray, which contains a trace starting at the given address. + */ + private VM_CodeArray getCodeForPC(int pc) { + DBT_Trace trace = codeHash.get(pc); + + if (trace == null) { + trace = translateCode(pc); + } + + return trace.getCurrentCompiledMethod().getEntryCodeArray(); } + /** + * Translates a piece of code starting at the given program counter value. + * + * @param pc + * The memory address of the first instruction that is translated + * into the code array. + * @return An code array containing target system assembly language, which has + * been translated from the subject executable. + */ + private DBT_Trace translateCode(int pc) { + + synchronized (ps) { + DBT_Trace trace = new DBT_Trace(ps, pc); + + if (DBT_Options.debugRuntime) { + report("Translating code for 0x" + Integer.toHexString(trace.pc)); + } + + // compile the given trace + trace.compile(); + + // store the compiled code in code hash + codeHash.put(trace.pc, trace); + + return trace; + } + } + + /** Outputs a debug message */ + private void report(String msg) { + System.out.println("Dynamic Translation Controller: " + msg); + } } Modified: src/org/binarytranslator/generic/execution/GdbController.java =================================================================== --- src/org/binarytranslator/generic/execution/GdbController.java 2007-04-13 17:54:29 UTC (rev 46) +++ src/org/binarytranslator/generic/execution/GdbController.java 2007-04-13 18:27:36 UTC (rev 47) @@ -181,6 +181,7 @@ /** * Main run loop */ + @Override public void run() { try { while (socket.isConnected()) { Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-13 17:54:29 UTC (rev 46) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-13 18:27:36 UTC (rev 47) @@ -10,7 +10,6 @@ import java.io.IOException; import java.io.RandomAccessFile; -import java.util.Hashtable; import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; @@ -21,22 +20,15 @@ import org.binarytranslator.generic.memory.Memory; import org.binarytranslator.generic.memory.MemoryMapException; import org.binarytranslator.generic.os.loader.Loader; -import org.binarytranslator.vmInterface.DBT_Trace; -import org.jikesrvm.ArchitectureSpecific.VM_CodeArray; -import org.jikesrvm.compilers.common.VM_CompiledMethod; import org.jikesrvm.compilers.opt.ir.OPT_GenerationContext; import org.jikesrvm.compilers.opt.ir.OPT_HIRGenerator; import org.vmmagic.pragma.Uninterruptible; - /** * A process space encapsulates a running process. This superclass contains non * operating and architecture specific details of the process. */ public abstract class ProcessSpace { - /* - * Runtime information - */ /** * A record of branches to guide translation @@ -44,29 +36,16 @@ public final BranchLogic branchInfo; /** - * A hashtable containing translated traces of code - */ - protected final Hashtable<Integer, VM_CodeArray> codeHash = new Hashtable<Integer, VM_CodeArray>(); - - /** * Has a system call been called to terminate the process */ public boolean finished = false; - /* - * Interface to memory - */ - /** * The memory for the process. As this is user mode code, it is a virtual * address space */ public Memory memory; - /* - * Utility functions - */ - /** * Debug information * @@ -80,10 +59,6 @@ } } - /* - * Methods - */ - /** * Create an optimizing compiler HIR code generator suitable for a particular * architecture @@ -121,7 +96,7 @@ } return result; } - + /** * Create a segment * @@ -202,43 +177,8 @@ } /** - * Constructor + * Record a branch instruction */ - public ProcessSpace(String[] args) throws IOException { - branchInfo = new BranchLogic(); - } - - /** - * Replace the compiled code for a trace (called by the adaptive system) - */ - public synchronized void replaceCompiledTrace(VM_CompiledMethod cm, - DBT_Trace trace) { - VM_CodeArray code = cm.getEntryCodeArray(); - codeHash.put(trace.pc, code); - } - - public synchronized VM_CodeArray getCodeForPC(int pc) { - VM_CodeArray code = (VM_CodeArray) codeHash.get(pc); - if (code == null) { - code = translateCode(new DBT_Trace(this, pc)); - } - return code; - } - - private VM_CodeArray translateCode(DBT_Trace trace) { - if (DBT_Options.debugRuntime) { - report("Translating code for 0x" + Integer.toHexString(trace.pc)); - } - trace.compile(); - VM_CompiledMethod cm = trace.getCurrentCompiledMethod(); - replaceCompiledTrace(cm, trace); - return cm.getEntryCodeArray(); - } - - /* - * - * /** Record a branch instruction - */ public void recordUncaughtBranch(int location, int destination, int code) { branchInfo.registerBranch(location, destination, code); } Modified: src/org/binarytranslator/vmInterface/DBT_Trace.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-04-13 17:54:29 UTC (rev 46) +++ src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-04-13 18:27:36 UTC (rev 47) @@ -18,6 +18,7 @@ import org.jikesrvm.classloader.VM_MemberReference; import org.jikesrvm.classloader.VM_Atom; import org.jikesrvm.classloader.VM_BytecodeStream; +import org.jikesrvm.runtime.VM_Magic; import org.jikesrvm.runtime.VM_Statics; import org.jikesrvm.runtime.VM_DynamicLink; import org.jikesrvm.compilers.opt.ir.OPT_GenerationContext; @@ -190,7 +191,6 @@ */ public final synchronized void replaceCompiledMethod( VM_CompiledMethod compiledMethod) { - ps.replaceCompiledTrace(compiledMethod, this); // Grab version that is being replaced VM_CompiledMethod oldCompiledMethod = currentCompiledMethod; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |