From: <mic...@us...> - 2007-07-06 10:39:24
|
Revision: 147 http://svn.sourceforge.net/pearcolator/?rev=147&view=rev Author: michael_baer Date: 2007-07-06 03:39:15 -0700 (Fri, 06 Jul 2007) Log Message: ----------- Renamed BranchLogic to BranchProfile Modified Paths: -------------- src/org/binarytranslator/DBT_Options.java src/org/binarytranslator/Main.java src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java src/org/binarytranslator/generic/branchprofile/CallAndReturnAddress.java src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java src/org/binarytranslator/generic/execution/ExecutionController.java src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java src/org/binarytranslator/generic/os/process/ProcessSpace.java Added Paths: ----------- src/org/binarytranslator/generic/branchprofile/ src/org/binarytranslator/generic/branchprofile/BranchProfile.java src/org/binarytranslator/generic/branchprofile/ProcedureInformation.java Removed Paths: ------------- src/org/binarytranslator/generic/branch/ src/org/binarytranslator/generic/branchprofile/BranchLogic.java src/org/binarytranslator/generic/branchprofile/ProcedureInformation.java Modified: src/org/binarytranslator/DBT_Options.java =================================================================== --- src/org/binarytranslator/DBT_Options.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/DBT_Options.java 2007-07-06 10:39:15 UTC (rev 147) @@ -21,7 +21,7 @@ public class DBT_Options { /** Remove features that will only work on jikes? */ - public final static boolean buildForSunVM = true; + public final static boolean buildForSunVM = false; /** Enable the profiling of application during interpretation? */ public final static boolean profileDuringInterpretation = true; Modified: src/org/binarytranslator/Main.java =================================================================== --- src/org/binarytranslator/Main.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/Main.java 2007-07-06 10:39:15 UTC (rev 147) @@ -107,7 +107,7 @@ //on SUN's VM, only the interpreter has been tested if (DBT_Options.buildForSunVM) { - DBT_Options.executionController = ExecutionController.Type.PredecodingThreadedInterpreter; + DBT_Options.executionController = ExecutionController.Type.PredecodingInterpreter; } @@ -116,7 +116,7 @@ switch (DBT_Options.executionController) { - case PredecodingThreadedInterpreter: + case PredecodingInterpreter: controller = new PredecodingThreadedInterpreter(ps); //new PredecodingThreadedInterpreter(ps); break; Modified: src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java 2007-07-06 10:39:15 UTC (rev 147) @@ -9,7 +9,7 @@ import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; import org.binarytranslator.arch.arm.os.process.ARM_Registers; import org.binarytranslator.arch.arm.os.process.ARM_Registers.OperatingMode; -import org.binarytranslator.generic.branch.BranchLogic.BranchType; +import org.binarytranslator.generic.branchprofile.BranchProfile.BranchType; import org.binarytranslator.generic.decoder.Interpreter; import org.binarytranslator.generic.decoder.Utils; Modified: src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java 2007-07-06 10:39:15 UTC (rev 147) @@ -9,7 +9,7 @@ import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; import org.binarytranslator.arch.arm.os.process.ARM_Registers; import org.binarytranslator.arch.arm.os.process.ARM_Registers.OperatingMode; -import org.binarytranslator.generic.branch.BranchLogic.BranchType; +import org.binarytranslator.generic.branchprofile.BranchProfile.BranchType; import org.jikesrvm.classloader.VM_Atom; import org.jikesrvm.classloader.VM_MemberReference; import org.jikesrvm.classloader.VM_Method; Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-07-06 10:39:15 UTC (rev 147) @@ -11,8 +11,8 @@ import org.binarytranslator.DBT; import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; -import org.binarytranslator.generic.branch.BranchLogic; -import org.binarytranslator.generic.branch.BranchLogic.BranchType; +import org.binarytranslator.generic.branchprofile.BranchProfile; +import org.binarytranslator.generic.branchprofile.BranchProfile.BranchType; import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.vmInterface.DBT_OptimizingCompilerException; import org.jikesrvm.compilers.opt.ir.Binary; @@ -4026,7 +4026,7 @@ branchAddress = ppc2ir.getLRRegister(); } - ppc2ir.appendBranch(branchAddress, lazy, BranchLogic.BranchType.RETURN); + ppc2ir.appendBranch(branchAddress, lazy, BranchProfile.BranchType.RETURN); // stop translation on branch always if (BO == 0x14) { Modified: src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2007-07-06 10:39:15 UTC (rev 147) @@ -11,7 +11,7 @@ import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.x86.os.process.X86_ProcessSpace; import org.binarytranslator.arch.x86.os.process.X86_Registers; -import org.binarytranslator.generic.branch.BranchLogic.BranchType; +import org.binarytranslator.generic.branchprofile.BranchProfile.BranchType; import org.binarytranslator.generic.decoder.InstructionDecoder; import org.binarytranslator.generic.decoder.Laziness; import org.binarytranslator.generic.fault.BadInstructionException; Copied: src/org/binarytranslator/generic/branchprofile (from rev 133, src/org/binarytranslator/generic/branch) Deleted: src/org/binarytranslator/generic/branchprofile/BranchLogic.java =================================================================== --- src/org/binarytranslator/generic/branch/BranchLogic.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/generic/branchprofile/BranchLogic.java 2007-07-06 10:39:15 UTC (rev 147) @@ -1,318 +0,0 @@ -/* - * This file is part of binarytranslator.org. The binarytranslator.org - * project is distributed under the Common Public License (CPL). - * A copy of the license is included in the distribution, and is also - * available at http://www.opensource.org/licenses/cpl1.0.php - * - * (C) Copyright Ian Rogers, The University of Manchester 2003-2006 - */ -package org.binarytranslator.generic.branch; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.binarytranslator.DBT; -import org.binarytranslator.DBT_Options; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -/** - * Object capturing branches and jumps so that traces can avoid terminating on - * branches whose destinations aren't known - */ -public class BranchLogic { - - public enum BranchType { - INDIRECT_BRANCH, - DIRECT_BRANCH, - CALL, - RETURN - } - - /** A set of procedure information */ - private final SortedMap<Integer, ProcedureInformation> procedures; - - /** A set of switch like branchs sites and their destinations */ - private final SortedMap<Integer, Set<Integer>> branchSitesAndDestinations; - - /** Global branch information */ - private static BranchLogic global; - - /** - * Constructor has 2 functions: (1) when making a local trace we don't want to - * consider as many procedure return points as may be known for the full - * program. (2) making sure switch like branches are all recorded globally - */ - public BranchLogic() { - if (global == null) { - global = this; - branchSitesAndDestinations = new TreeMap<Integer, Set<Integer>>(); - } - else { - branchSitesAndDestinations = global.branchSitesAndDestinations; - } - procedures = new TreeMap<Integer, ProcedureInformation>(); - } - - /** - * Register a call (branch and link) instruction - * - * @param pc - * the address of the branch instruction - * @param dest - * the destination of the branch instruction - * @param ret - * the address that will be returned to - */ - public void registerCall(int pc, int dest, int ret) { - ProcedureInformation procedure = procedures.get(dest); - - if (procedure != null) { - procedure.registerCall(pc, ret); - } else { - procedure = new ProcedureInformation(pc, ret, dest); - procedures.put(dest, procedure); - } - - registerBranch(pc, dest); - } - - /** - * Register a function return. - * - * @param pc - * the address of the branch instruction - * @param lr - * the return address (value of the link register) - */ - public void registerReturn(int pc, int lr) { - - ProcedureInformation procedure = getLikelyProcedure(pc); - - if (procedure != null) { - procedure.registerReturn(pc, lr); - } - - registerBranch(pc, lr); - } - - /** - * Given an address within a procedure, returns the (most likely) procedure - * - * @param pc - * a location within the procedure - * @return corressponding procedure information - */ - private ProcedureInformation getLikelyProcedure(int pc) { - if (procedures.size() > 0) { - SortedMap<Integer, ProcedureInformation> priorProcedures = procedures.headMap(pc); - if (priorProcedures.size() > 0) { - Integer procedureEntry = priorProcedures.lastKey(); - return procedures.get(procedureEntry); - } - } - return null; - } - - /** - * Registers a branch from the address <code>origin</code> to the address <code>target</code>. - * The type of branch is determined by <code>type</code>, which is an ordinal from the - * {@link BranchType} enum. - * - * @param origin - * The address from which the branch occurs. - * @param target - * The address to which the program is branching. - * @param type - * The most likely type of the branch. This is taken from the {@link BranchType} enum. - */ - public void registerBranch(int origin, int target, BranchType type) { - - switch (type) { - case CALL: - throw new RuntimeException("Use the more specific registerCall() for these cases."); - - case RETURN: - registerReturn(origin, target); - break; - - default: - registerBranch(origin, target); - } - } - - /** - * Appends a recorded branch from <code>origin</code> to <code>target</code> to the branch profile. - * - * @param origin - * The address that the branch is taking place from. - * @param target - * The branch target address. - */ - private void registerBranch(int origin, int target) { - //Perform the general branch registration, too - Set<Integer> dests = branchSitesAndDestinations.get(origin); - - if (dests != null && dests.contains(target)) { - // This destination address is already registered - return; - } - else { - dests = new HashSet<Integer>(); - branchSitesAndDestinations.put(origin, dests); - } - - dests.add(target); - } - - /** - * Returns a list of known branch targets for the branch at address <code>pc</code>. - * - * @param pc - * The address where the branch originates from. - * @return - * A list of known target addresses for this branch. It is not critical to the functionality of the - * translated binary, if this list is not complete. - */ - public Set<Integer> getKnownBranchTargets(int pc) { - return branchSitesAndDestinations.get(pc); - } - - public void loadFromXML(String filename) throws IOException { - - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - Document doc; - try { - DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); - doc = docBuilder.parse(filename); - } catch (ParserConfigurationException e) { - throw new RuntimeException("Error creating DocumentBuilder instance to read an XML file."); - } catch (SAXException e) { - throw new IOException("File " + filename + " is not a valid XML file."); - } - - if (DBT.VerifyAssertions) DBT._assert(doc != null); - - Element root = doc.getDocumentElement(); - - if (!root.getNodeName().equals("branch-profile")) - throw new IOException("File is not a valid XML branch profile."); - - Node branches = null; - - for (int i = 0; i < root.getChildNodes().getLength(); i++) { - Node node = root.getChildNodes().item(0); - - if (node.getNodeName().equals("branches")) { - branches = node; - break; - } - } - - if (branches == null) - throw new IOException("File is not a valid XML branch profile."); - - for (int i = 0; i < branches.getChildNodes().getLength(); i++) { - Node siteNode = branches.getChildNodes().item(i); - - if (!siteNode.getNodeName().equals("origin") || siteNode.getNodeType() != Node.ELEMENT_NODE) - throw new IOException("File is not a valid XML branch profile."); - - int pc = Integer.parseInt(((Element)siteNode).getAttribute("address")); - - for (int n = 0; n < siteNode.getChildNodes().getLength(); n++) { - Node target = siteNode.getChildNodes().item(n); - - if (!target.getNodeName().equals("target") || target.getNodeType() != Node.ELEMENT_NODE) - throw new IOException("File is not a valid XML branch profile."); - - int targetAddress = Integer.parseInt(((Element)target).getAttribute("address")); - registerBranch(pc, targetAddress); - } - } - } - - /** - * Saves the branch profile of the current process space to the give file in XML format. - * - * @param filename - * The name of the file to which the branch profile is saved. - * @throws IOException - * Thrown if there is an error while creating the file. - */ - public void saveAsXML(String filename) throws IOException { - - FileOutputStream outputStream; - - try { - File f = new File(filename); - - if (!f.exists()) - f.createNewFile(); - - outputStream = new FileOutputStream(f); - } - catch (FileNotFoundException e) { - //this should not happen, as we just created the file - throw new IOException("Error creating file: " + filename); - } - - //Create an XML representation of the branch profile - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder; - try { - docBuilder = docBuilderFactory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - throw new IOException("Error creating parser to produce XML document."); - } - Document doc = docBuilder.newDocument(); - - Element root = doc.createElement("branch-profile"); - root.setAttribute("application", DBT_Options.executableFile); - doc.appendChild(root); - - Element branchesElement = doc.createElement("branches"); - root.appendChild(branchesElement); - - for (int pc : branchSitesAndDestinations.keySet()) { - Element branchSiteElement = doc.createElement("origin"); - branchesElement.appendChild(branchSiteElement); - branchSiteElement.setAttribute("address", Integer.toString(pc)); - - for (int target : getKnownBranchTargets(pc)) { - Element branchTargetElement = doc.createElement("target"); - branchSiteElement.appendChild(branchTargetElement); - branchTargetElement.setAttribute("address", Integer.toString(target)); - } - } - - //Output the resulting XML document - TransformerFactory tFactory = TransformerFactory.newInstance(); - Transformer transformer; - try { - transformer = tFactory.newTransformer(); - DOMSource source = new DOMSource(doc); - StreamResult result = new StreamResult(outputStream); - transformer.transform(source, result); - - } catch (Exception e) { - e.printStackTrace(); - } - } -} Copied: src/org/binarytranslator/generic/branchprofile/BranchProfile.java (from rev 133, src/org/binarytranslator/generic/branch/BranchLogic.java) =================================================================== --- src/org/binarytranslator/generic/branchprofile/BranchProfile.java (rev 0) +++ src/org/binarytranslator/generic/branchprofile/BranchProfile.java 2007-07-06 10:39:15 UTC (rev 147) @@ -0,0 +1,318 @@ +/* + * This file is part of binarytranslator.org. The binarytranslator.org + * project is distributed under the Common Public License (CPL). + * A copy of the license is included in the distribution, and is also + * available at http://www.opensource.org/licenses/cpl1.0.php + * + * (C) Copyright Ian Rogers, The University of Manchester 2003-2006 + */ +package org.binarytranslator.generic.branchprofile; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.binarytranslator.DBT; +import org.binarytranslator.DBT_Options; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +/** + * Object capturing branches and jumps so that traces can avoid terminating on + * branches whose destinations aren't known + */ +public class BranchProfile { + + public enum BranchType { + INDIRECT_BRANCH, + DIRECT_BRANCH, + CALL, + RETURN + } + + /** A set of procedure information */ + private final SortedMap<Integer, ProcedureInformation> procedures; + + /** A set of switch like branchs sites and their destinations */ + private final SortedMap<Integer, Set<Integer>> branchSitesAndDestinations; + + /** Global branch information */ + private static BranchProfile global; + + /** + * Constructor has 2 functions: (1) when making a local trace we don't want to + * consider as many procedure return points as may be known for the full + * program. (2) making sure switch like branches are all recorded globally + */ + public BranchProfile() { + if (global == null) { + global = this; + branchSitesAndDestinations = new TreeMap<Integer, Set<Integer>>(); + } + else { + branchSitesAndDestinations = global.branchSitesAndDestinations; + } + procedures = new TreeMap<Integer, ProcedureInformation>(); + } + + /** + * Register a call (branch and link) instruction + * + * @param pc + * the address of the branch instruction + * @param dest + * the destination of the branch instruction + * @param ret + * the address that will be returned to + */ + public void registerCall(int pc, int dest, int ret) { + ProcedureInformation procedure = procedures.get(dest); + + if (procedure != null) { + procedure.registerCall(pc, ret); + } else { + procedure = new ProcedureInformation(pc, ret, dest); + procedures.put(dest, procedure); + } + + registerBranch(pc, dest); + } + + /** + * Register a function return. + * + * @param pc + * the address of the branch instruction + * @param lr + * the return address (value of the link register) + */ + public void registerReturn(int pc, int lr) { + + ProcedureInformation procedure = getLikelyProcedure(pc); + + if (procedure != null) { + procedure.registerReturn(pc, lr); + } + + registerBranch(pc, lr); + } + + /** + * Given an address within a procedure, returns the (most likely) procedure + * + * @param pc + * a location within the procedure + * @return corressponding procedure information + */ + private ProcedureInformation getLikelyProcedure(int pc) { + if (procedures.size() > 0) { + SortedMap<Integer, ProcedureInformation> priorProcedures = procedures.headMap(pc); + if (priorProcedures.size() > 0) { + Integer procedureEntry = priorProcedures.lastKey(); + return procedures.get(procedureEntry); + } + } + return null; + } + + /** + * Registers a branch from the address <code>origin</code> to the address <code>target</code>. + * The type of branch is determined by <code>type</code>, which is an ordinal from the + * {@link BranchType} enum. + * + * @param origin + * The address from which the branch occurs. + * @param target + * The address to which the program is branching. + * @param type + * The most likely type of the branch. This is taken from the {@link BranchType} enum. + */ + public void registerBranch(int origin, int target, BranchType type) { + + switch (type) { + case CALL: + throw new RuntimeException("Use the more specific registerCall() for these cases."); + + case RETURN: + registerReturn(origin, target); + break; + + default: + registerBranch(origin, target); + } + } + + /** + * Appends a recorded branch from <code>origin</code> to <code>target</code> to the branch profile. + * + * @param origin + * The address that the branch is taking place from. + * @param target + * The branch target address. + */ + private void registerBranch(int origin, int target) { + //Perform the general branch registration, too + Set<Integer> dests = branchSitesAndDestinations.get(origin); + + if (dests != null && dests.contains(target)) { + // This destination address is already registered + return; + } + else { + dests = new HashSet<Integer>(); + branchSitesAndDestinations.put(origin, dests); + } + + dests.add(target); + } + + /** + * Returns a list of known branch targets for the branch at address <code>pc</code>. + * + * @param pc + * The address where the branch originates from. + * @return + * A list of known target addresses for this branch. It is not critical to the functionality of the + * translated binary, if this list is not complete. + */ + public Set<Integer> getKnownBranchTargets(int pc) { + return branchSitesAndDestinations.get(pc); + } + + public void loadFromXML(String filename) throws IOException { + + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + Document doc; + try { + DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + doc = docBuilder.parse(filename); + } catch (ParserConfigurationException e) { + throw new RuntimeException("Error creating DocumentBuilder instance to read an XML file."); + } catch (SAXException e) { + throw new IOException("File " + filename + " is not a valid XML file."); + } + + if (DBT.VerifyAssertions) DBT._assert(doc != null); + + Element root = doc.getDocumentElement(); + + if (!root.getNodeName().equals("branch-profile")) + throw new IOException("File is not a valid XML branch profile."); + + Node branches = null; + + for (int i = 0; i < root.getChildNodes().getLength(); i++) { + Node node = root.getChildNodes().item(0); + + if (node.getNodeName().equals("branches")) { + branches = node; + break; + } + } + + if (branches == null) + throw new IOException("File is not a valid XML branch profile."); + + for (int i = 0; i < branches.getChildNodes().getLength(); i++) { + Node siteNode = branches.getChildNodes().item(i); + + if (!siteNode.getNodeName().equals("origin") || siteNode.getNodeType() != Node.ELEMENT_NODE) + throw new IOException("File is not a valid XML branch profile."); + + int pc = Integer.parseInt(((Element)siteNode).getAttribute("address")); + + for (int n = 0; n < siteNode.getChildNodes().getLength(); n++) { + Node target = siteNode.getChildNodes().item(n); + + if (!target.getNodeName().equals("target") || target.getNodeType() != Node.ELEMENT_NODE) + throw new IOException("File is not a valid XML branch profile."); + + int targetAddress = Integer.parseInt(((Element)target).getAttribute("address")); + registerBranch(pc, targetAddress); + } + } + } + + /** + * Saves the branch profile of the current process space to the give file in XML format. + * + * @param filename + * The name of the file to which the branch profile is saved. + * @throws IOException + * Thrown if there is an error while creating the file. + */ + public void saveAsXML(String filename) throws IOException { + + FileOutputStream outputStream; + + try { + File f = new File(filename); + + if (!f.exists()) + f.createNewFile(); + + outputStream = new FileOutputStream(f); + } + catch (FileNotFoundException e) { + //this should not happen, as we just created the file + throw new IOException("Error creating file: " + filename); + } + + //Create an XML representation of the branch profile + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder; + try { + docBuilder = docBuilderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new IOException("Error creating parser to produce XML document."); + } + Document doc = docBuilder.newDocument(); + + Element root = doc.createElement("branch-profile"); + root.setAttribute("application", DBT_Options.executableFile); + doc.appendChild(root); + + Element branchesElement = doc.createElement("branches"); + root.appendChild(branchesElement); + + for (int pc : branchSitesAndDestinations.keySet()) { + Element branchSiteElement = doc.createElement("origin"); + branchesElement.appendChild(branchSiteElement); + branchSiteElement.setAttribute("address", Integer.toString(pc)); + + for (int target : getKnownBranchTargets(pc)) { + Element branchTargetElement = doc.createElement("target"); + branchSiteElement.appendChild(branchTargetElement); + branchTargetElement.setAttribute("address", Integer.toString(target)); + } + } + + //Output the resulting XML document + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer transformer; + try { + transformer = tFactory.newTransformer(); + DOMSource source = new DOMSource(doc); + StreamResult result = new StreamResult(outputStream); + transformer.transform(source, result); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} Modified: src/org/binarytranslator/generic/branchprofile/CallAndReturnAddress.java =================================================================== --- src/org/binarytranslator/generic/branch/CallAndReturnAddress.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/generic/branchprofile/CallAndReturnAddress.java 2007-07-06 10:39:15 UTC (rev 147) @@ -6,7 +6,7 @@ * * (C) Copyright Ian Rogers, The University of Manchester 2003-2006 */ -package org.binarytranslator.generic.branch; +package org.binarytranslator.generic.branchprofile; /** * Object for recording a call site and its corresponding return address Deleted: src/org/binarytranslator/generic/branchprofile/ProcedureInformation.java =================================================================== --- src/org/binarytranslator/generic/branch/ProcedureInformation.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/generic/branchprofile/ProcedureInformation.java 2007-07-06 10:39:15 UTC (rev 147) @@ -1,97 +0,0 @@ -/* - * This file is part of binarytranslator.org. The binarytranslator.org - * project is distributed under the Common Public License (CPL). - * A copy of the license is included in the distribution, and is also - * available at http://www.opensource.org/licenses/cpl1.0.php - * - * (C) Copyright Ian Rogers, The University of Manchester 2003-2006 - */ -package org.binarytranslator.generic.branch; - -import java.util.HashSet; -import java.util.Comparator; - -/** - * Objects capturing information about what looks like a method - */ -class ProcedureInformation { - /** - * Entry point to the procedure - */ - private int entry; - - /** - * Set of locations that call the procedure and the corressponding return - * address - */ - private HashSet<CallAndReturnAddress> callSitesAndReturnAddresses; - - /** - * Set of locations within the procedure that return - */ - private HashSet<Integer> returnSites; - - /** - * Comparator for procedure information - */ - @SuppressWarnings("unused") - private static final class ProcedureInformationComparator implements - Comparator { - /** - * Compare two procedure information objects - */ - public int compare(Object o1, Object o2) { - return ((ProcedureInformation) o1).entry - - ((ProcedureInformation) o2).entry; - } - } - - /** - * Constructor - * - * @param entry - * starting address of the procedure - * @param callSite - * the address calling the procedure - * @param returnAddress - * the corresponding return address - */ - ProcedureInformation(int entry, int callSite, int returnAddress) { - this.entry = entry; - callSitesAndReturnAddresses = new HashSet<CallAndReturnAddress>(); - callSitesAndReturnAddresses.add(new CallAndReturnAddress(callSite, - returnAddress)); - } - - /** - * Register a call (branch and link) instruction - * - * @param pc - * the address of the branch instruction - * @param ret - * the address that will be returned to - */ - public void registerCall(int pc, int ret) { - CallAndReturnAddress call_tuple = new CallAndReturnAddress(pc, ret); - if (!callSitesAndReturnAddresses.contains(call_tuple)) { - callSitesAndReturnAddresses.add(call_tuple); - } - } - - /** - * Register a return (branch to link register) instruction - * - * @param pc - * the address of the branch instruction - * @param ret - * the address that will be returned to - */ - public void registerReturn(int pc, int ret) { - if (returnSites == null) { - returnSites = new HashSet<Integer>(); - } - returnSites.add(new Integer(pc)); - // TODO: capture that the instruction prior to ret is a call - // site to this procedure - } -} Copied: src/org/binarytranslator/generic/branchprofile/ProcedureInformation.java (from rev 136, src/org/binarytranslator/generic/branch/ProcedureInformation.java) =================================================================== --- src/org/binarytranslator/generic/branchprofile/ProcedureInformation.java (rev 0) +++ src/org/binarytranslator/generic/branchprofile/ProcedureInformation.java 2007-07-06 10:39:15 UTC (rev 147) @@ -0,0 +1,196 @@ +/* + * This file is part of binarytranslator.org. The binarytranslator.org + * project is distributed under the Common Public License (CPL). + * A copy of the license is included in the distribution, and is also + * available at http://www.opensource.org/licenses/cpl1.0.php + * + * (C) Copyright Ian Rogers, The University of Manchester 2003-2006 + */ +package org.binarytranslator.generic.branchprofile; + +import java.util.HashSet; +import java.util.Comparator; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Objects capturing information about what looks like a method + */ +class ProcedureInformation { + /** + * Entry point to the procedure + */ + private final int entry; + + /** + * Set of locations that call the procedure and the corressponding return + * address + */ + private HashSet<CallAndReturnAddress> callSitesAndReturnAddresses; + + /** + * Set of locations within the procedure that return + */ + private HashSet<Integer> returnSites; + + /** + * Comparator for procedure information + */ + @SuppressWarnings("unused") + private static final class ProcedureInformationComparator implements + Comparator { + /** + * Compare two procedure information objects + */ + public int compare(Object o1, Object o2) { + return ((ProcedureInformation) o1).entry + - ((ProcedureInformation) o2).entry; + } + } + + private ProcedureInformation(int entry) { + this.entry = entry; + } + + /** + * Constructor + * + * @param entry + * starting address of the procedure + * @param callSite + * the address calling the procedure + * @param returnAddress + * the corresponding return address + */ + ProcedureInformation(int entry, int callSite, int returnAddress) { + this.entry = entry; + callSitesAndReturnAddresses = new HashSet<CallAndReturnAddress>(); + callSitesAndReturnAddresses.add(new CallAndReturnAddress(callSite, + returnAddress)); + } + + /** + * Register a call (branch and link) instruction + * + * @param pc + * the address of the branch instruction + * @param ret + * the address that will be returned to + */ + public void registerCall(int pc, int ret) { + CallAndReturnAddress call_tuple = new CallAndReturnAddress(pc, ret); + if (!callSitesAndReturnAddresses.contains(call_tuple)) { + callSitesAndReturnAddresses.add(call_tuple); + } + } + + /** + * Register a return (branch to link register) instruction + * + * @param pc + * the address of the branch instruction + * @param ret + * the address that will be returned to + */ + public void registerReturn(int pc, int ret) { + if (returnSites == null) { + returnSites = new HashSet<Integer>(); + } + returnSites.add(new Integer(pc)); + } + + /** + * Serializes this object to an XML document. + * + * @param doc + * The XML document that the object shall be serialized to. + * @param parentNode + * The node within <code>doc</code> that the object shall be serialized to. + */ + public void toXML(Document doc, Element parentNode) { + Element procedure = parentNode; + procedure.setAttribute("entry", Integer.toString(entry)); + + Element callSites = doc.createElement("callsites"); + for (CallAndReturnAddress caller : callSitesAndReturnAddresses) { + Element callerNode = doc.createElement("call"); + callerNode.setAttribute("from", Integer.toString(caller.getCallSite())); + callerNode.setAttribute("return", Integer.toString(caller.getReturnAddress())); + callSites.appendChild(callerNode); + } + procedure.appendChild(callSites); + + Element returnSites = doc.createElement("returnsites"); + for (Integer returnSite : this.returnSites) { + Element returnSiteNode = doc.createElement("return"); + returnSiteNode.setAttribute("at", returnSite.toString()); + returnSites.appendChild(returnSiteNode); + } + procedure.appendChild(returnSites); + } + + /** + * Loads a {@link ProcedureInformation} object from an XML element, given that the object + * was previously persisted by {@link #toXML(Document, Element)}. + * @param node + * The XML element that had been provided to {@link #toXML(Document, Element)}. + */ + public static ProcedureInformation fromXML(Element node) { + + ProcedureInformation pi = new ProcedureInformation(Integer.parseInt(node.getAttribute("entry"))); + + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node childNode = node.getChildNodes().item(i); + + //skip non-element nodes + if (childNode.getNodeType() != Node.ELEMENT_NODE) + continue; + + if (childNode.getNodeName().equals("callsites")) { + //parse call sites + for (int n = 0; n < childNode.getChildNodes().getLength(); n++) { + Node callsite = childNode.getChildNodes().item(n); + + //skip non-element nodes + if (callsite.getNodeType() != Node.ELEMENT_NODE) + continue; + + if (callsite.getNodeName().equals("call")) + throw new Error("The given XML node is not a valid ProcedureInformation entity."); + + int callFrom = Integer.parseInt(((Element)callsite).getAttribute("from")); + int callReturn = Integer.parseInt(((Element)callsite).getAttribute("return")); + + pi.callSitesAndReturnAddresses.add(new CallAndReturnAddress(callFrom, callReturn)); + } + } + else if (childNode.getNodeName().equals("returnsites")) { + //parse return sites + for (int n = 0; n < childNode.getChildNodes().getLength(); n++) { + Node callsite = childNode.getChildNodes().item(n); + + //skip non-element nodes + if (callsite.getNodeType() != Node.ELEMENT_NODE) + continue; + + if (callsite.getNodeName().equals("return")) + throw new Error("The given XML node is not a valid ProcedureInformation entity."); + + int returnAt = Integer.parseInt(((Element)callsite).getAttribute("at")); + pi.returnSites.add(returnAt); + } + } + else { + throw new Error("The given XML node is not a valid ProcedureInformation entity."); + } + } + + + + + + return pi; + } +} Modified: src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java =================================================================== --- src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java 2007-07-06 10:39:15 UTC (rev 147) @@ -16,7 +16,7 @@ import org.binarytranslator.DBT; import org.binarytranslator.DBT_Options; -import org.binarytranslator.generic.branch.BranchLogic.BranchType; +import org.binarytranslator.generic.branchprofile.BranchProfile.BranchType; import org.binarytranslator.generic.decoder.Laziness.Key; import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.generic.os.process.ProcessSpace; Modified: src/org/binarytranslator/generic/execution/ExecutionController.java =================================================================== --- src/org/binarytranslator/generic/execution/ExecutionController.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/generic/execution/ExecutionController.java 2007-07-06 10:39:15 UTC (rev 147) @@ -8,7 +8,7 @@ public enum Type { Translator, Interpreter, - PredecodingThreadedInterpreter, + PredecodingInterpreter, GDB } Modified: src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java =================================================================== --- src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/generic/execution/PredecodingThreadedInterpreter.java 2007-07-06 10:39:15 UTC (rev 147) @@ -3,15 +3,14 @@ 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 final HashMap<Integer, List<Interpreter.Instruction>> traceCache = new HashMap<Integer, List<Interpreter.Instruction>>(); + private final Interpreter interpreter; private List<Interpreter.Instruction> getTrace(int pc) { List<Interpreter.Instruction> cachedTrace = traceCache.get(pc); @@ -58,11 +57,11 @@ public PredecodingThreadedInterpreter(ProcessSpace ps) { super(ps); + interpreter = ps.createInstructionInterpreter(); } @Override public void run() { - interpreter = ps.createInstructionInterpreter(); int pc = ps.getCurrentInstructionAddress(); while (!ps.finished) { Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-07-04 16:39:23 UTC (rev 146) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-07-06 10:39:15 UTC (rev 147) @@ -14,8 +14,8 @@ import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; import org.binarytranslator.arch.x86.os.process.X86_ProcessSpace; -import org.binarytranslator.generic.branch.BranchLogic; -import org.binarytranslator.generic.branch.BranchLogic.BranchType; +import org.binarytranslator.generic.branchprofile.BranchProfile; +import org.binarytranslator.generic.branchprofile.BranchProfile.BranchType; import org.binarytranslator.generic.decoder.CodeCache; import org.binarytranslator.generic.decoder.Interpreter; import org.binarytranslator.generic.execution.GdbController.GdbTarget; @@ -33,7 +33,7 @@ public abstract class ProcessSpace { /** A record of branches to guide translation */ - public final BranchLogic branchInfo; + public final BranchProfile branchInfo; /** Has a system call been called to terminate the process? */ public boolean finished = false; @@ -123,7 +123,7 @@ * Constructor */ protected ProcessSpace() { - branchInfo = new BranchLogic(); + branchInfo = new BranchProfile(); codeCache = new CodeCache(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |