From: <mic...@us...> - 2007-07-04 16:39:20
|
Revision: 146 http://svn.sourceforge.net/pearcolator/?rev=146&view=rev Author: michael_baer Date: 2007-07-04 09:39:23 -0700 (Wed, 04 Jul 2007) Log Message: ----------- - Added an execution controller that performs predecoded, threaded interpretation Modified Paths: -------------- src/org/binarytranslator/DBT_Options.java src/org/binarytranslator/Main.java src/org/binarytranslator/generic/execution/ExecutionController.java Added Paths: ----------- src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java Modified: src/org/binarytranslator/DBT_Options.java =================================================================== --- src/org/binarytranslator/DBT_Options.java 2007-07-04 15:17:39 UTC (rev 145) +++ src/org/binarytranslator/DBT_Options.java 2007-07-04 16:39:23 UTC (rev 146) @@ -21,7 +21,7 @@ public class DBT_Options { /** Remove features that will only work on jikes? */ - public final static boolean buildForSunVM = false; + public final static boolean buildForSunVM = true; /** Enable the profiling of application during interpretation? */ public final static boolean profileDuringInterpretation = true; @@ -47,6 +47,7 @@ /** Instructions to translate for an optimisation level 2 trace */ public static int instrOpt2 = 1500; + /** Determines how the program will be run (i.e. interpreted, translated etc.) */ public static ExecutionController.Type executionController = ExecutionController.Type.Translator; /** Modified: src/org/binarytranslator/Main.java =================================================================== --- src/org/binarytranslator/Main.java 2007-07-04 15:17:39 UTC (rev 145) +++ src/org/binarytranslator/Main.java 2007-07-04 16:39:23 UTC (rev 146) @@ -10,6 +10,7 @@ import java.io.File; +import org.binarytranslator.generic.execution.PredecodingThreadedInterpreter; import org.binarytranslator.generic.execution.DynamicTranslationController; import org.binarytranslator.generic.execution.ExecutionController; import org.binarytranslator.generic.execution.GdbController; @@ -106,7 +107,7 @@ //on SUN's VM, only the interpreter has been tested if (DBT_Options.buildForSunVM) { - DBT_Options.executionController = ExecutionController.Type.Interpreter; + DBT_Options.executionController = ExecutionController.Type.PredecodingThreadedInterpreter; } @@ -114,6 +115,11 @@ ExecutionController controller = null; switch (DBT_Options.executionController) { + + case PredecodingThreadedInterpreter: + controller = new PredecodingThreadedInterpreter(ps); //new PredecodingThreadedInterpreter(ps); + break; + case Interpreter: controller = new InterpreterController(ps); break; Modified: src/org/binarytranslator/generic/execution/ExecutionController.java =================================================================== --- src/org/binarytranslator/generic/execution/ExecutionController.java 2007-07-04 15:17:39 UTC (rev 145) +++ src/org/binarytranslator/generic/execution/ExecutionController.java 2007-07-04 16:39:23 UTC (rev 146) @@ -8,6 +8,7 @@ public enum Type { Translator, Interpreter, + PredecodingThreadedInterpreter, GDB } Added: src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java =================================================================== --- src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java (rev 0) +++ src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java 2007-07-04 16:39:23 UTC (rev 146) @@ -0,0 +1,75 @@ +package org.binarytranslator.generic.execution; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.binarytranslator.generic.decoder.Interpreter; +import org.binarytranslator.generic.os.process.ProcessSpace; + +public final class PredecodingThreadedInterpreter extends ExecutionController { + private HashMap<Integer, List<Interpreter.Instruction>> traceCache = new HashMap<Integer, List<Interpreter.Instruction>>(); + private Interpreter interpreter; + + private List<Interpreter.Instruction> getTrace(int pc) { + List<Interpreter.Instruction> cachedTrace = traceCache.get(pc); + + if (cachedTrace != null) + return cachedTrace; + + int traceStart = pc; + ArrayList<Interpreter.Instruction> newTrace = new ArrayList<Interpreter.Instruction>(5); + + while (true) { + Interpreter.Instruction instruction = interpreter.decode(pc); + pc = instruction.getSuccessor(pc); + newTrace.add(instruction); + + //is the successor to this instruction known? + if (pc == -1) { + + //No, so stop the trace after this instruction + if (newTrace.size() > 3) { + //add this trace to the trace cache, if it contains enough instructions + traceCache.put(traceStart, newTrace); + } + + break; + } + } + + return newTrace; + } + + private void executeTrace(List<Interpreter.Instruction> trace, int pc) { + + Iterator<Interpreter.Instruction> instructions = trace.iterator(); + while (instructions.hasNext()) { + Interpreter.Instruction instr = instructions.next(); + instr.execute(); + pc = instr.getSuccessor(pc); + + if (pc != -1) + ps.setCurrentInstructionAddress(pc); + } + } + + public PredecodingThreadedInterpreter(ProcessSpace ps) { + super(ps); + } + + @Override + public void run() { + interpreter = ps.createInstructionInterpreter(); + int pc = ps.getCurrentInstructionAddress(); + + while (!ps.finished) { + + List<Interpreter.Instruction> trace = getTrace(pc); + executeTrace(trace, pc); + pc = ps.getCurrentInstructionAddress(); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |